-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
39 lines (30 loc) · 1.15 KB
/
test.py
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
import server
import mock
## testcase for connecting with server
server_socket = mock.create_autospec(server.ser_sock)
def test_unix_fs(mocker):
server_socket("127.0.0.1", "12345")
server_socket.assert_called_once_with("127.0.0.1", "12345")
# import unittest
# import socket
# from time import sleep
# import mock
# import TcpService
# def accept_gen():
# for i in range(1):
# mock_socket = mock.MagicMock(name='socket.socket', spec=socket.socket)
# sleep(1)
# yield (mock_socket, ['127.0.0.1', 12345])
# while True:
# sleep(1) # so I have a chance to kill the process before the OS becomes unresponsive
# yield socket.error()
# class test_TcpService(unittest.TestCase):
# @mock.patch('socket.socket', autospec=True)
# def test_listen_tcp(self, mock_socket):
# mocked_socket = mock_socket.return_value
# mocked_socket.accept.side_effect = accept_gen()
# sts = TcpService()
# with self.assertRaises(socket.error):
# sts.listen_tcp()
# mock_socket.assert_called_once() # trivial POC check, final test would be more thorough...
# sts.close_tcp()