Skip to content

Commit b0a8b1f

Browse files
unit test reorganization
1 parent 9f21867 commit b0a8b1f

17 files changed

+40
-82
lines changed

setup.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"""
77
import re
88
from setuptools import setup
9+
import six
910

1011
with open('socketio/__init__.py', 'r') as f:
1112
version = re.search(r'^__version__\s*=\s*[\'"]([^\'"]*)[\'"]',
@@ -42,7 +43,7 @@
4243
tests_require=[
4344
'mock',
4445
],
45-
test_suite='tests',
46+
test_suite='tests' if six.PY3 else 'tests.common',
4647
classifiers=[
4748
'Environment :: Web Environment',
4849
'Intended Audience :: Developers',

tests/asyncio/__init__.py

Whitespace-only changes.

tests/test_asyncio_client.py renamed to tests/asyncio/test_asyncio_client.py

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import asyncio
12
import sys
23
import unittest
34

@@ -7,26 +8,18 @@
78
else:
89
import mock
910

11+
from socketio import asyncio_client
12+
from socketio import asyncio_namespace
1013
from engineio import exceptions as engineio_exceptions
1114
from socketio import exceptions
1215
from socketio import packet
13-
if six.PY3:
14-
import asyncio
15-
from asyncio import coroutine
16-
from socketio import asyncio_client
17-
from socketio import asyncio_namespace
18-
else:
19-
# mock coroutine so that Python 2 doesn't complain
20-
def coroutine(f):
21-
return f
2216

2317

2418
def AsyncMock(*args, **kwargs):
2519
"""Return a mock asynchronous function."""
2620
m = mock.MagicMock(*args, **kwargs)
2721

28-
@coroutine
29-
def mock_coro(*args, **kwargs):
22+
async def mock_coro(*args, **kwargs):
3023
return m(*args, **kwargs)
3124

3225
mock_coro.mock = m
@@ -119,8 +112,7 @@ def test_wait_reconnect_failed(self):
119112
c.sleep = AsyncMock()
120113
states = ['disconnected']
121114

122-
@coroutine
123-
def fake_wait():
115+
async def fake_wait():
124116
c.eio.state = states.pop(0)
125117

126118
c._reconnect_task = fake_wait()
@@ -134,8 +126,7 @@ def test_wait_reconnect_successful(self):
134126
c.sleep = AsyncMock()
135127
states = ['connected', 'disconnected']
136128

137-
@coroutine
138-
def fake_wait():
129+
async def fake_wait():
139130
c.eio.state = states.pop(0)
140131
c._reconnect_task = fake_wait()
141132

tests/test_asyncio_manager.py renamed to tests/asyncio/test_asyncio_manager.py

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import asyncio
12
import sys
23
import unittest
34

@@ -7,22 +8,14 @@
78
else:
89
import mock
910

10-
if sys.version_info >= (3, 5):
11-
import asyncio
12-
from asyncio import coroutine
13-
from socketio import asyncio_manager
14-
else:
15-
# mock coroutine so that Python 2 doesn't complain
16-
def coroutine(f):
17-
return f
11+
from socketio import asyncio_manager
1812

1913

2014
def AsyncMock(*args, **kwargs):
2115
"""Return a mock asynchronous function."""
2216
m = mock.MagicMock(*args, **kwargs)
2317

24-
@coroutine
25-
def mock_coro(*args, **kwargs):
18+
async def mock_coro(*args, **kwargs):
2619
return m(*args, **kwargs)
2720

2821
mock_coro.mock = m

tests/test_asyncio_namespace.py renamed to tests/asyncio/test_asyncio_namespace.py

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import asyncio
12
import sys
23
import unittest
34

@@ -7,22 +8,14 @@
78
else:
89
import mock
910

10-
if sys.version_info >= (3, 5):
11-
import asyncio
12-
from asyncio import coroutine
13-
from socketio import asyncio_namespace
14-
else:
15-
# mock coroutine so that Python 2 doesn't complain
16-
def coroutine(f):
17-
return f
11+
from socketio import asyncio_namespace
1812

1913

2014
def AsyncMock(*args, **kwargs):
2115
"""Return a mock asynchronous function."""
2216
m = mock.MagicMock(*args, **kwargs)
2317

24-
@coroutine
25-
def mock_coro(*args, **kwargs):
18+
async def mock_coro(*args, **kwargs):
2619
return m(*args, **kwargs)
2720

2821
mock_coro.mock = m
@@ -40,8 +33,7 @@ def test_connect_event(self):
4033
result = {}
4134

4235
class MyNamespace(asyncio_namespace.AsyncNamespace):
43-
@coroutine
44-
def on_connect(self, sid, environ):
36+
async def on_connect(self, sid, environ):
4537
result['result'] = (sid, environ)
4638

4739
ns = MyNamespace('/foo')
@@ -53,8 +45,7 @@ def test_disconnect_event(self):
5345
result = {}
5446

5547
class MyNamespace(asyncio_namespace.AsyncNamespace):
56-
@coroutine
57-
def on_disconnect(self, sid):
48+
async def on_disconnect(self, sid):
5849
result['result'] = sid
5950

6051
ns = MyNamespace('/foo')
@@ -78,8 +69,7 @@ def test_async_event(self):
7869
result = {}
7970

8071
class MyNamespace(asyncio_namespace.AsyncNamespace):
81-
@coroutine
82-
def on_custom_message(self, sid, data):
72+
async def on_custom_message(self, sid, data):
8373
result['result'] = (sid, data)
8474

8575
ns = MyNamespace('/foo')
@@ -91,8 +81,7 @@ def test_event_not_found(self):
9181
result = {}
9282

9383
class MyNamespace(asyncio_namespace.AsyncNamespace):
94-
@coroutine
95-
def on_custom_message(self, sid, data):
84+
async def on_custom_message(self, sid, data):
9685
result['result'] = (sid, data)
9786

9887
ns = MyNamespace('/foo')
@@ -217,8 +206,7 @@ def test_async_event_client(self):
217206
result = {}
218207

219208
class MyNamespace(asyncio_namespace.AsyncClientNamespace):
220-
@coroutine
221-
def on_custom_message(self, sid, data):
209+
async def on_custom_message(self, sid, data):
222210
result['result'] = (sid, data)
223211

224212
ns = MyNamespace('/foo')
@@ -230,8 +218,7 @@ def test_event_not_found_client(self):
230218
result = {}
231219

232220
class MyNamespace(asyncio_namespace.AsyncClientNamespace):
233-
@coroutine
234-
def on_custom_message(self, sid, data):
221+
async def on_custom_message(self, sid, data):
235222
result['result'] = (sid, data)
236223

237224
ns = MyNamespace('/foo')

tests/test_asyncio_pubsub_manager.py renamed to tests/asyncio/test_asyncio_pubsub_manager.py

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import asyncio
12
import functools
23
import sys
34
import unittest
@@ -8,23 +9,15 @@
89
else:
910
import mock
1011

11-
if sys.version_info >= (3, 5):
12-
import asyncio
13-
from asyncio import coroutine
14-
from socketio import asyncio_manager
15-
from socketio import asyncio_pubsub_manager
16-
else:
17-
# mock coroutine so that Python 2 doesn't complain
18-
def coroutine(f):
19-
return f
12+
from socketio import asyncio_manager
13+
from socketio import asyncio_pubsub_manager
2014

2115

2216
def AsyncMock(*args, **kwargs):
2317
"""Return a mock asynchronous function."""
2418
m = mock.MagicMock(*args, **kwargs)
2519

26-
@coroutine
27-
def mock_coro(*args, **kwargs):
20+
async def mock_coro(*args, **kwargs):
2821
return m(*args, **kwargs)
2922

3023
mock_coro.mock = m

tests/test_asyncio_redis_manager.py renamed to tests/asyncio/test_asyncio_redis_manager.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import sys
22
import unittest
33

4-
if sys.version_info >= (3, 5):
5-
from socketio import asyncio_redis_manager
4+
from socketio import asyncio_redis_manager
65

76

87
@unittest.skipIf(sys.version_info < (3, 5), 'only for Python 3.5+')

tests/test_asyncio_server.py renamed to tests/asyncio/test_asyncio_server.py

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import asyncio
12
import json
23
import logging
34
import sys
@@ -9,25 +10,17 @@
910
else:
1011
import mock
1112

13+
from socketio import asyncio_server
14+
from socketio import asyncio_namespace
1215
from socketio import packet
1316
from socketio import namespace
14-
if sys.version_info >= (3, 5):
15-
import asyncio
16-
from asyncio import coroutine
17-
from socketio import asyncio_server
18-
from socketio import asyncio_namespace
19-
else:
20-
# mock coroutine so that Python 2 doesn't complain
21-
def coroutine(f):
22-
return f
2317

2418

2519
def AsyncMock(*args, **kwargs):
2620
"""Return a mock asynchronous function."""
2721
m = mock.MagicMock(*args, **kwargs)
2822

29-
@coroutine
30-
def mock_coro(*args, **kwargs):
23+
async def mock_coro(*args, **kwargs):
3124
return m(*args, **kwargs)
3225

3326
mock_coro.mock = m
@@ -476,12 +469,15 @@ async def _test():
476469
self.assertEqual(session, {'foo': 'bar'})
477470
session['foo'] = 'baz'
478471
session['bar'] = 'foo'
479-
self.assertEqual(await s.get_session('123'), {'foo': 'baz', 'bar': 'foo'})
480-
self.assertEqual(fake_session, {'/': {'foo': 'baz', 'bar': 'foo'}})
472+
self.assertEqual(await s.get_session('123'),
473+
{'foo': 'baz', 'bar': 'foo'})
474+
self.assertEqual(fake_session,
475+
{'/': {'foo': 'baz', 'bar': 'foo'}})
481476
async with s.session('123', namespace='/ns') as session:
482477
self.assertEqual(session, {})
483478
session['a'] = 'b'
484-
self.assertEqual(await s.get_session('123', namespace='/ns'), {'a': 'b'})
479+
self.assertEqual(await s.get_session('123', namespace='/ns'),
480+
{'a': 'b'})
485481
self.assertEqual(fake_session, {'/': {'foo': 'baz', 'bar': 'foo'},
486482
'/ns': {'a': 'b'}})
487483
_run(_test())
@@ -528,19 +524,16 @@ class MyNamespace(asyncio_namespace.AsyncNamespace):
528524
def on_connect(self, sid, environ):
529525
result['result'] = (sid, environ)
530526

531-
@coroutine
532-
def on_disconnect(self, sid):
527+
async def on_disconnect(self, sid):
533528
result['result'] = ('disconnect', sid)
534529

535-
@coroutine
536-
def on_foo(self, sid, data):
530+
async def on_foo(self, sid, data):
537531
result['result'] = (sid, data)
538532

539533
def on_bar(self, sid):
540534
result['result'] = 'bar'
541535

542-
@coroutine
543-
def on_baz(self, sid, data1, data2):
536+
async def on_baz(self, sid, data1, data2):
544537
result['result'] = (data1, data2)
545538

546539
s = asyncio_server.AsyncServer()

tests/common/__init__.py

Whitespace-only changes.
File renamed without changes.

0 commit comments

Comments
 (0)