#!/usr/bin/env python3
# encoding: utf-8
"""control.py

Created by Thomas Mangin on 2015-01-01.
Copyright (c) 2009-2015 Exa Networks. All rights reserved.
License: 3-clause BSD. (See the COPYRIGHT file)
"""

import time
import socket
import unittest
from typing import Any


def speak(name: Any, data: Any) -> None:
    time.sleep(0.005)
    try:
        sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
        sock.connect(name)
        sock.sendall(data)
    except OSError:
        pass


class TestControl(unittest.TestCase):
    def setUp(self) -> None:
        pass

    def test_failed_creation(self) -> None:
        pass
        # control = Control()
        # try:
        # 	result = control.init()
        # 	self.assertFalse(result)
        # except IOError:
        # 	# could not write in the location
        # 	pass
        # finally:
        # 	control.cleanup()

    def validate(self, message: Any, check: Any) -> None:
        pass
        # name = tempfile.mktemp()
        # control = Control(name,False)
        # try:
        # 	result = control.init()
        # 	self.assertTrue(result)
        #
        # 	p = Process(target=speak, args=(name,message))
        # 	p.start()
        #
        # 	string = control.loop()
        # 	self.assertEqual(string, check)
        # 	p.join()
        # finally:
        # 	control.cleanup()
        # 	del control

    def test_no_newline(self) -> None:
        self.validate('x', '')

    def test_one_newline(self) -> None:
        self.validate('x\n', 'x')

    def test_two_newline(self) -> None:
        self.validate('-\nx\n', 'x')

    def test_leftover(self) -> None:
        self.validate('-\nx\n-', 'x')


if __name__ == '__main__':
    unittest.main()
