forked from Lawouach/WebSocket-for-Python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_utils.py
More file actions
29 lines (23 loc) · 871 Bytes
/
Copy pathtest_utils.py
File metadata and controls
29 lines (23 loc) · 871 Bytes
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
# -*- coding: utf-8 -*-
import unittest
try:
from unittest.mock import MagicMock
except ImportError:
from mock import MagicMock
from ws4py import format_addresses
from ws4py.websocket import WebSocket
class WSUtilities(unittest.TestCase):
def test_format_address(self):
m = MagicMock()
m.getsockname.return_value = ('127.0.0.1', 52300, None, None)
m.getpeername.return_value = ('127.0.0.1', 4800, None, None)
ws = WebSocket(sock=m)
log = format_addresses(ws)
self.assertEqual(log, "[Local => 127.0.0.1:52300 | Remote => 127.0.0.1:4800]")
if __name__ == '__main__':
suite = unittest.TestSuite()
loader = unittest.TestLoader()
for testcase in [WSUtilities]:
tests = loader.loadTestsFromTestCase(testcase)
suite.addTests(tests)
unittest.TextTestRunner(verbosity=2).run(suite)