TestConnectEntryPoint.py
1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import unittest
import mock
from os.path import dirname, realpath
from sys import argv, path
path.append(dirname(dirname(realpath(__file__))) + '/lib')
from Communication.ConnectEntryPoint import ConnectEntryPoint
from Transport import Transport
class TestConnectEntryPoint(unittest.TestCase):
def setUp(self):
self._transport = mock.Mock()
self._protocol = mock.Mock()
self._newcon = mock.Mock()
self._entrypoint = ConnectEntryPoint(self._transport, self._protocol)
self._transport.bind.assert_called_once_with()
def testAccept(self):
self._transport.accept.return_value = None
self.assertFalse(self._entrypoint.accept())
self._transport.accept.side_effect = iter(
[self._newcon, self._newcon, None])
self.assertTrue(self._entrypoint.accept())
self._transport.accept.side_effect = iter(
[self._newcon, Transport.Error(1)])
self.assertTrue(self._entrypoint.accept())
def testPop(self):
self.testAccept()
self.assertEqual(self._entrypoint.pop(), self._newcon)
self.assertEqual(self._entrypoint.pop(), self._newcon)
self.assertEqual(self._entrypoint.pop(), self._newcon)
self.assertEqual(self._entrypoint.pop(), None)
def suite():
return unittest.TestLoader().loadTestsFromTestCase(TestConnectEntryPoint)
if __name__ == '__main__':
unittest.TextTestRunner(verbosity=2).run(suite())
# vim: set ft=python et ts=8 sw=4 sts=4: