kopia lustrzana https://github.com/Yakifo/amqtt
remove deprecated loop parameter from tests
rodzic
035cd6267b
commit
9628a1ce3e
|
@ -39,16 +39,14 @@ class ProtocolHandlerTest(unittest.TestCase):
|
|||
def setUp(self):
|
||||
self.loop = asyncio.new_event_loop()
|
||||
asyncio.set_event_loop(self.loop)
|
||||
self.plugin_manager = PluginManager(
|
||||
"amqtt.test.plugins", context=None, loop=self.loop
|
||||
)
|
||||
self.plugin_manager = PluginManager("amqtt.test.plugins", context=None)
|
||||
|
||||
def tearDown(self):
|
||||
self.loop.close()
|
||||
|
||||
def test_init_handler(self):
|
||||
Session()
|
||||
handler = ProtocolHandler(self.plugin_manager, loop=self.loop)
|
||||
handler = ProtocolHandler(self.plugin_manager)
|
||||
self.assertIsNone(handler.session)
|
||||
self.assertIs(handler._loop, self.loop)
|
||||
self.check_empty_waiters(handler)
|
||||
|
@ -70,7 +68,7 @@ class ProtocolHandlerTest(unittest.TestCase):
|
|||
except Exception as ae:
|
||||
future.set_exception(ae)
|
||||
|
||||
future = asyncio.Future(loop=self.loop)
|
||||
future = asyncio.Future()
|
||||
coro = asyncio.start_server(server_mock, "127.0.0.1", 8888)
|
||||
server = self.loop.run_until_complete(coro)
|
||||
self.loop.run_until_complete(test_coro())
|
||||
|
@ -92,11 +90,9 @@ class ProtocolHandlerTest(unittest.TestCase):
|
|||
async def test_coro():
|
||||
try:
|
||||
s = Session()
|
||||
reader, writer = await asyncio.open_connection(
|
||||
"127.0.0.1", 8888, loop=self.loop
|
||||
)
|
||||
reader, writer = await asyncio.open_connection("127.0.0.1", 8888)
|
||||
reader_adapted, writer_adapted = adapt(reader, writer)
|
||||
handler = ProtocolHandler(self.plugin_manager, loop=self.loop)
|
||||
handler = ProtocolHandler(self.plugin_manager)
|
||||
handler.attach(s, reader_adapted, writer_adapted)
|
||||
await self.start_handler(handler, s)
|
||||
message = await handler.mqtt_publish(
|
||||
|
@ -113,8 +109,8 @@ class ProtocolHandlerTest(unittest.TestCase):
|
|||
except Exception as ae:
|
||||
future.set_exception(ae)
|
||||
|
||||
future = asyncio.Future(loop=self.loop)
|
||||
coro = asyncio.start_server(server_mock, "127.0.0.1", 8888, loop=self.loop)
|
||||
future = asyncio.Future()
|
||||
coro = asyncio.start_server(server_mock, "127.0.0.1", 8888)
|
||||
server = self.loop.run_until_complete(coro)
|
||||
self.loop.run_until_complete(test_coro())
|
||||
server.close()
|
||||
|
@ -138,11 +134,9 @@ class ProtocolHandlerTest(unittest.TestCase):
|
|||
|
||||
async def test_coro():
|
||||
try:
|
||||
reader, writer = await asyncio.open_connection(
|
||||
"127.0.0.1", 8888, loop=self.loop
|
||||
)
|
||||
reader, writer = await asyncio.open_connection("127.0.0.1", 8888)
|
||||
reader_adapted, writer_adapted = adapt(reader, writer)
|
||||
self.handler = ProtocolHandler(self.plugin_manager, loop=self.loop)
|
||||
self.handler = ProtocolHandler(self.plugin_manager)
|
||||
self.handler.attach(self.session, reader_adapted, writer_adapted)
|
||||
await self.start_handler(self.handler, self.session)
|
||||
message = await self.handler.mqtt_publish(
|
||||
|
@ -162,9 +156,9 @@ class ProtocolHandlerTest(unittest.TestCase):
|
|||
|
||||
self.handler = None
|
||||
self.session = Session()
|
||||
future = asyncio.Future(loop=self.loop)
|
||||
future = asyncio.Future()
|
||||
|
||||
coro = asyncio.start_server(server_mock, "127.0.0.1", 8888, loop=self.loop)
|
||||
coro = asyncio.start_server(server_mock, "127.0.0.1", 8888)
|
||||
server = self.loop.run_until_complete(coro)
|
||||
self.loop.run_until_complete(test_coro())
|
||||
server.close()
|
||||
|
@ -193,11 +187,9 @@ class ProtocolHandlerTest(unittest.TestCase):
|
|||
|
||||
async def test_coro():
|
||||
try:
|
||||
reader, writer = await asyncio.open_connection(
|
||||
"127.0.0.1", 8888, loop=self.loop
|
||||
)
|
||||
reader, writer = await asyncio.open_connection("127.0.0.1", 8888)
|
||||
reader_adapted, writer_adapted = adapt(reader, writer)
|
||||
self.handler = ProtocolHandler(self.plugin_manager, loop=self.loop)
|
||||
self.handler = ProtocolHandler(self.plugin_manager)
|
||||
self.handler.attach(self.session, reader_adapted, writer_adapted)
|
||||
await self.start_handler(self.handler, self.session)
|
||||
message = await self.handler.mqtt_publish(
|
||||
|
@ -217,9 +209,9 @@ class ProtocolHandlerTest(unittest.TestCase):
|
|||
|
||||
self.handler = None
|
||||
self.session = Session()
|
||||
future = asyncio.Future(loop=self.loop)
|
||||
future = asyncio.Future()
|
||||
|
||||
coro = asyncio.start_server(server_mock, "127.0.0.1", 8888, loop=self.loop)
|
||||
coro = asyncio.start_server(server_mock, "127.0.0.1", 8888)
|
||||
server = self.loop.run_until_complete(coro)
|
||||
self.loop.run_until_complete(test_coro())
|
||||
server.close()
|
||||
|
@ -236,11 +228,9 @@ class ProtocolHandlerTest(unittest.TestCase):
|
|||
|
||||
async def test_coro():
|
||||
try:
|
||||
reader, writer = await asyncio.open_connection(
|
||||
"127.0.0.1", 8888, loop=self.loop
|
||||
)
|
||||
reader, writer = await asyncio.open_connection("127.0.0.1", 8888)
|
||||
reader_adapted, writer_adapted = adapt(reader, writer)
|
||||
self.handler = ProtocolHandler(self.plugin_manager, loop=self.loop)
|
||||
self.handler = ProtocolHandler(self.plugin_manager)
|
||||
self.handler.attach(self.session, reader_adapted, writer_adapted)
|
||||
await self.start_handler(self.handler, self.session)
|
||||
message = await self.handler.mqtt_deliver_next_message()
|
||||
|
@ -257,8 +247,8 @@ class ProtocolHandlerTest(unittest.TestCase):
|
|||
|
||||
self.handler = None
|
||||
self.session = Session()
|
||||
future = asyncio.Future(loop=self.loop)
|
||||
coro = asyncio.start_server(server_mock, "127.0.0.1", 8888, loop=self.loop)
|
||||
future = asyncio.Future()
|
||||
coro = asyncio.start_server(server_mock, "127.0.0.1", 8888)
|
||||
server = self.loop.run_until_complete(coro)
|
||||
self.loop.run_until_complete(test_coro())
|
||||
server.close()
|
||||
|
@ -282,11 +272,9 @@ class ProtocolHandlerTest(unittest.TestCase):
|
|||
|
||||
async def test_coro():
|
||||
try:
|
||||
reader, writer = await asyncio.open_connection(
|
||||
"127.0.0.1", 8888, loop=self.loop
|
||||
)
|
||||
reader, writer = await asyncio.open_connection("127.0.0.1", 8888)
|
||||
reader_adapted, writer_adapted = adapt(reader, writer)
|
||||
self.handler = ProtocolHandler(self.plugin_manager, loop=self.loop)
|
||||
self.handler = ProtocolHandler(self.plugin_manager)
|
||||
self.handler.attach(self.session, reader_adapted, writer_adapted)
|
||||
await self.start_handler(self.handler, self.session)
|
||||
message = await self.handler.mqtt_deliver_next_message()
|
||||
|
@ -303,9 +291,9 @@ class ProtocolHandlerTest(unittest.TestCase):
|
|||
|
||||
self.handler = None
|
||||
self.session = Session()
|
||||
future = asyncio.Future(loop=self.loop)
|
||||
self.event = asyncio.Event(loop=self.loop)
|
||||
coro = asyncio.start_server(server_mock, "127.0.0.1", 8888, loop=self.loop)
|
||||
future = asyncio.Future()
|
||||
self.event = asyncio.Event()
|
||||
coro = asyncio.start_server(server_mock, "127.0.0.1", 8888)
|
||||
server = self.loop.run_until_complete(coro)
|
||||
self.loop.run_until_complete(test_coro())
|
||||
server.close()
|
||||
|
@ -334,11 +322,9 @@ class ProtocolHandlerTest(unittest.TestCase):
|
|||
|
||||
async def test_coro():
|
||||
try:
|
||||
reader, writer = await asyncio.open_connection(
|
||||
"127.0.0.1", 8888, loop=self.loop
|
||||
)
|
||||
reader, writer = await asyncio.open_connection("127.0.0.1", 8888)
|
||||
reader_adapted, writer_adapted = adapt(reader, writer)
|
||||
self.handler = ProtocolHandler(self.plugin_manager, loop=self.loop)
|
||||
self.handler = ProtocolHandler(self.plugin_manager)
|
||||
self.handler.attach(self.session, reader_adapted, writer_adapted)
|
||||
await self.start_handler(self.handler, self.session)
|
||||
message = await self.handler.mqtt_deliver_next_message()
|
||||
|
@ -355,8 +341,8 @@ class ProtocolHandlerTest(unittest.TestCase):
|
|||
|
||||
self.handler = None
|
||||
self.session = Session()
|
||||
future = asyncio.Future(loop=self.loop)
|
||||
coro = asyncio.start_server(server_mock, "127.0.0.1", 8888, loop=self.loop)
|
||||
future = asyncio.Future()
|
||||
coro = asyncio.start_server(server_mock, "127.0.0.1", 8888)
|
||||
server = self.loop.run_until_complete(coro)
|
||||
self.loop.run_until_complete(test_coro())
|
||||
server.close()
|
||||
|
@ -402,11 +388,9 @@ class ProtocolHandlerTest(unittest.TestCase):
|
|||
|
||||
async def test_coro():
|
||||
try:
|
||||
reader, writer = await asyncio.open_connection(
|
||||
"127.0.0.1", 8888, loop=self.loop
|
||||
)
|
||||
reader, writer = await asyncio.open_connection("127.0.0.1", 8888)
|
||||
reader_adapted, writer_adapted = adapt(reader, writer)
|
||||
self.handler = ProtocolHandler(self.plugin_manager, loop=self.loop)
|
||||
self.handler = ProtocolHandler(self.plugin_manager)
|
||||
self.handler.attach(self.session, reader_adapted, writer_adapted)
|
||||
await self.handler.start()
|
||||
await self.stop_handler(self.handler, self.session)
|
||||
|
@ -422,9 +406,9 @@ class ProtocolHandlerTest(unittest.TestCase):
|
|||
"/topic", b"test_data", rand_packet_id(), False, QOS_1, False
|
||||
)
|
||||
self.session.inflight_out[1] = message
|
||||
future = asyncio.Future(loop=self.loop)
|
||||
future = asyncio.Future()
|
||||
|
||||
coro = asyncio.start_server(server_mock, "127.0.0.1", 8888, loop=self.loop)
|
||||
coro = asyncio.start_server(server_mock, "127.0.0.1", 8888)
|
||||
server = self.loop.run_until_complete(coro)
|
||||
self.loop.run_until_complete(test_coro())
|
||||
server.close()
|
||||
|
@ -453,11 +437,9 @@ class ProtocolHandlerTest(unittest.TestCase):
|
|||
|
||||
async def test_coro():
|
||||
try:
|
||||
reader, writer = await asyncio.open_connection(
|
||||
"127.0.0.1", 8888, loop=self.loop
|
||||
)
|
||||
reader, writer = await asyncio.open_connection("127.0.0.1", 8888)
|
||||
reader_adapted, writer_adapted = adapt(reader, writer)
|
||||
self.handler = ProtocolHandler(self.plugin_manager, loop=self.loop)
|
||||
self.handler = ProtocolHandler(self.plugin_manager)
|
||||
self.handler.attach(self.session, reader_adapted, writer_adapted)
|
||||
await self.handler.start()
|
||||
await self.stop_handler(self.handler, self.session)
|
||||
|
@ -473,9 +455,9 @@ class ProtocolHandlerTest(unittest.TestCase):
|
|||
"/topic", b"test_data", rand_packet_id(), False, QOS_2, False
|
||||
)
|
||||
self.session.inflight_out[1] = message
|
||||
future = asyncio.Future(loop=self.loop)
|
||||
future = asyncio.Future()
|
||||
|
||||
coro = asyncio.start_server(server_mock, "127.0.0.1", 8888, loop=self.loop)
|
||||
coro = asyncio.start_server(server_mock, "127.0.0.1", 8888)
|
||||
server = self.loop.run_until_complete(coro)
|
||||
self.loop.run_until_complete(test_coro())
|
||||
server.close()
|
||||
|
|
|
@ -46,10 +46,10 @@ class TestPluginManager(unittest.TestCase):
|
|||
def test_fire_event(self):
|
||||
async def fire_event():
|
||||
await manager.fire_event("test")
|
||||
await asyncio.sleep(1, loop=self.loop)
|
||||
await asyncio.sleep(1)
|
||||
await manager.close()
|
||||
|
||||
manager = PluginManager("amqtt.test.plugins", context=None, loop=self.loop)
|
||||
manager = PluginManager("amqtt.test.plugins", context=None)
|
||||
self.loop.run_until_complete(fire_event())
|
||||
plugin = manager.get_plugin("event_plugin")
|
||||
assert plugin.object.test_flag
|
||||
|
@ -59,7 +59,7 @@ class TestPluginManager(unittest.TestCase):
|
|||
await manager.fire_event("test", wait=True)
|
||||
await manager.close()
|
||||
|
||||
manager = PluginManager("amqtt.test.plugins", context=None, loop=self.loop)
|
||||
manager = PluginManager("amqtt.test.plugins", context=None)
|
||||
self.loop.run_until_complete(fire_event())
|
||||
plugin = manager.get_plugin("event_plugin")
|
||||
assert plugin.object.test_flag
|
||||
|
@ -68,7 +68,7 @@ class TestPluginManager(unittest.TestCase):
|
|||
async def call_coro():
|
||||
await manager.map_plugin_coro("test_coro")
|
||||
|
||||
manager = PluginManager("amqtt.test.plugins", context=None, loop=self.loop)
|
||||
manager = PluginManager("amqtt.test.plugins", context=None)
|
||||
self.loop.run_until_complete(call_coro())
|
||||
plugin = manager.get_plugin("event_plugin")
|
||||
assert plugin.object.test_coro
|
||||
|
@ -77,7 +77,7 @@ class TestPluginManager(unittest.TestCase):
|
|||
async def call_coro():
|
||||
return await manager.map_plugin_coro("ret_coro")
|
||||
|
||||
manager = PluginManager("amqtt.test.plugins", context=None, loop=self.loop)
|
||||
manager = PluginManager("amqtt.test.plugins", context=None)
|
||||
ret = self.loop.run_until_complete(call_coro())
|
||||
plugin = manager.get_plugin("event_plugin")
|
||||
self.assertEqual(ret[plugin], "TEST")
|
||||
|
@ -91,6 +91,6 @@ class TestPluginManager(unittest.TestCase):
|
|||
async def call_coro():
|
||||
return await manager.map_plugin_coro("ret_coro", filter_plugins=[])
|
||||
|
||||
manager = PluginManager("amqtt.test.plugins", context=None, loop=self.loop)
|
||||
manager = PluginManager("amqtt.test.plugins", context=None)
|
||||
ret = self.loop.run_until_complete(call_coro())
|
||||
assert len(ret) == 0
|
||||
|
|
|
@ -94,10 +94,8 @@ async def test_client_connect(broker, mock_plugin_manager):
|
|||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_client_connect_will_flag(broker, event_loop):
|
||||
conn_reader, conn_writer = await asyncio.open_connection(
|
||||
"127.0.0.1", 1883, loop=event_loop
|
||||
)
|
||||
async def test_client_connect_will_flag(broker):
|
||||
conn_reader, conn_writer = await asyncio.open_connection("127.0.0.1", 1883)
|
||||
reader = StreamReaderAdapter(conn_reader)
|
||||
writer = StreamWriterAdapter(conn_writer)
|
||||
|
||||
|
@ -360,10 +358,8 @@ async def test_client_publish_acl_permitted_sub_forbidden(acl_broker):
|
|||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_client_publish_dup(broker, event_loop):
|
||||
conn_reader, conn_writer = await asyncio.open_connection(
|
||||
"127.0.0.1", 1883, loop=event_loop
|
||||
)
|
||||
async def test_client_publish_dup(broker):
|
||||
conn_reader, conn_writer = await asyncio.open_connection("127.0.0.1", 1883)
|
||||
reader = StreamReaderAdapter(conn_reader)
|
||||
writer = StreamWriterAdapter(conn_writer)
|
||||
|
||||
|
@ -380,7 +376,7 @@ async def test_client_publish_dup(broker, event_loop):
|
|||
|
||||
publish_1 = PublishPacket.build("/test", b"data", 1, False, QOS_2, False)
|
||||
await publish_1.to_stream(writer)
|
||||
asyncio.ensure_future(PubrecPacket.from_stream(reader), loop=event_loop)
|
||||
asyncio.ensure_future(PubrecPacket.from_stream(reader))
|
||||
|
||||
await asyncio.sleep(2)
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue