Skip to content

Commit 7de6d63

Browse files
Removed dependency on unittest.TestCase base class
1 parent e8f9bba commit 7de6d63

12 files changed

+27
-42
lines changed

tests/async/test_aiohttp.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
import unittest
21
from unittest import mock
32

43
from engineio.async_drivers import aiohttp as async_aiohttp
54

65

7-
class AiohttpTests(unittest.TestCase):
6+
class TestAiohttp:
87
def test_create_route(self):
98
app = mock.MagicMock()
109
mock_server = mock.MagicMock()

tests/async/test_asgi.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import asyncio
22
import os
3-
import unittest
43
from unittest import mock
54

65
from engineio.async_drivers import asgi as async_asgi
@@ -22,7 +21,7 @@ def _run(coro):
2221
return asyncio.get_event_loop().run_until_complete(coro)
2322

2423

25-
class AsgiTests(unittest.TestCase):
24+
class TestAsgi:
2625
def test_create_app(self):
2726
app = async_asgi.ASGIApp(
2827
'eio',

tests/async/test_client.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import asyncio
22
import ssl
3-
import sys
4-
import unittest
53
from unittest import mock
64

75
try:
@@ -33,8 +31,7 @@ def _run(coro):
3331
return asyncio.get_event_loop().run_until_complete(coro)
3432

3533

36-
@unittest.skipIf(sys.version_info < (3, 5), 'only for Python 3.5+')
37-
class TestAsyncClient(unittest.TestCase):
34+
class TestAsyncClient:
3835
def test_is_asyncio_based(self):
3936
c = async_client.AsyncClient()
4037
assert c.is_asyncio_based()

tests/async/test_server.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import gzip
33
import io
44
import logging
5-
import unittest
65
from unittest import mock
76
import zlib
87

@@ -32,7 +31,7 @@ def _run(coro):
3231
return asyncio.get_event_loop().run_until_complete(coro)
3332

3433

35-
class TestAsyncServer(unittest.TestCase):
34+
class TestAsyncServer:
3635
@staticmethod
3736
def get_async_mock(environ={'REQUEST_METHOD': 'GET', 'QUERY_STRING': ''}):
3837
if environ.get('QUERY_STRING'):
@@ -67,17 +66,17 @@ def _get_mock_socket(self):
6766
return mock_socket
6867

6968
@classmethod
70-
def setUpClass(cls):
69+
def setup_class(cls):
7170
async_server.AsyncServer._default_monitor_clients = False
7271

7372
@classmethod
74-
def tearDownClass(cls):
73+
def teardown_class(cls):
7574
async_server.AsyncServer._default_monitor_clients = True
7675

77-
def setUp(self):
76+
def setup_method(self):
7877
logging.getLogger('engineio').setLevel(logging.NOTSET)
7978

80-
def tearDown(self):
79+
def teardown_method(self):
8180
# restore JSON encoder, in case a test changed it
8281
packet.Packet.json = json
8382

@@ -1030,11 +1029,12 @@ def test_background_tasks(self):
10301029
async def foo(arg):
10311030
r.append(arg)
10321031

1033-
s = async_server.AsyncServer()
1034-
s.start_background_task(foo, 'bar')
1035-
pending = asyncio.all_tasks(loop=asyncio.get_event_loop()) \
1036-
if hasattr(asyncio, 'all_tasks') else asyncio.Task.all_tasks()
1037-
asyncio.get_event_loop().run_until_complete(asyncio.wait(pending))
1032+
async def main():
1033+
s = async_server.AsyncServer()
1034+
task = s.start_background_task(foo, 'bar')
1035+
await task
1036+
1037+
_run(main())
10381038
assert r == ['bar']
10391039

10401040
def test_sleep(self):

tests/async/test_socket.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import asyncio
22
import time
3-
import unittest
43
from unittest import mock
54

65
import pytest
@@ -27,7 +26,7 @@ def _run(coro):
2726
return asyncio.get_event_loop().run_until_complete(coro)
2827

2928

30-
class TestSocket(unittest.TestCase):
29+
class TestSocket:
3130
def _get_read_mock_coro(self, payload):
3231
mock_input = mock.MagicMock()
3332
mock_input.read = AsyncMock()

tests/async/test_tornado.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import asyncio
2-
import unittest
32
from unittest import mock
43

54
try:
@@ -15,7 +14,7 @@ def _run(coro):
1514
return asyncio.get_event_loop().run_until_complete(coro)
1615

1716

18-
class TornadoTests(unittest.TestCase):
17+
class TestTornado:
1918
def test_get_tornado_handler(self):
2019
mock_server = mock.MagicMock()
2120
handler = async_tornado.get_tornado_handler(mock_server)

tests/common/test_client.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import logging
22
import ssl
33
import time
4-
import unittest
54
from unittest import mock
65

76
import pytest
@@ -15,7 +14,7 @@
1514
from engineio import payload
1615

1716

18-
class TestClient(unittest.TestCase):
17+
class TestClient:
1918
def test_is_asyncio_based(self):
2019
c = client.Client()
2120
assert not c.is_asyncio_based()

tests/common/test_middleware.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import os
2-
import unittest
32
from unittest import mock
43

54
import engineio
65

76

8-
class TestWSGIApp(unittest.TestCase):
7+
class TestWSGIApp:
98
def test_wsgi_routing(self):
109
mock_wsgi_app = mock.MagicMock()
1110
mock_eio_app = 'foo'

tests/common/test_packet.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
import unittest
2-
31
import pytest
42

53
from engineio import packet
64

75

8-
class TestPacket(unittest.TestCase):
6+
class TestPacket:
97
def test_encode_default_packet(self):
108
pkt = packet.Packet()
119
assert pkt.packet_type == packet.NOOP

tests/common/test_payload.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
import unittest
2-
31
import pytest
42

53
from engineio import packet
64
from engineio import payload
75

86

9-
class TestPayload(unittest.TestCase):
7+
class TestPayload:
108
def test_encode_empty_payload(self):
119
p = payload.Payload()
1210
assert p.packets == []

tests/common/test_server.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import logging
55
import sys
66
import time
7-
import unittest
87
from unittest import mock
98
import zlib
109

@@ -25,7 +24,7 @@ def _mock_import(module, *args, **kwargs):
2524
return module
2625

2726

28-
class TestServer(unittest.TestCase):
27+
class TestServer:
2928
_mock_async = mock.MagicMock()
3029
_mock_async._async = {
3130
'thread': 't',
@@ -43,17 +42,17 @@ def _get_mock_socket(self):
4342
return mock_socket
4443

4544
@classmethod
46-
def setUpClass(cls):
45+
def setup_class(cls):
4746
server.Server._default_monitor_clients = False
4847

4948
@classmethod
50-
def tearDownClass(cls):
49+
def teardown_class(cls):
5150
server.Server._default_monitor_clients = True
5251

53-
def setUp(self):
52+
def setup_method(self):
5453
logging.getLogger('engineio').setLevel(logging.NOTSET)
5554

56-
def tearDown(self):
55+
def teardown_method(self):
5756
# restore JSON encoder, in case a test changed it
5857
packet.Packet.json = json
5958

tests/common/test_socket.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import io
22
import time
3-
import unittest
43
from unittest import mock
54

65
import pytest
@@ -11,8 +10,8 @@
1110
from engineio import socket
1211

1312

14-
class TestSocket(unittest.TestCase):
15-
def setUp(self):
13+
class TestSocket:
14+
def setup_method(self):
1615
self.bg_tasks = []
1716

1817
def _get_mock_server(self):

0 commit comments

Comments
 (0)