Skip to content

Commit

Permalink
Merge e550386 into 12b6f29
Browse files Browse the repository at this point in the history
  • Loading branch information
miburk committed Mar 17, 2023
2 parents 12b6f29 + e550386 commit 3952d47
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 15 deletions.
4 changes: 3 additions & 1 deletion aio_pika/connection.py
Expand Up @@ -360,7 +360,9 @@ async def main():
client_properties=client_properties,
**kwargs,
),
loop=loop, ssl_context=ssl_context,
loop=loop,
ssl_context=ssl_context,
**kwargs,
)

await connection.connect(timeout=timeout)
Expand Down
2 changes: 1 addition & 1 deletion aio_pika/robust_connection.py
Expand Up @@ -320,7 +320,7 @@ async def main():
client_properties=client_properties,
**kwargs,
),
loop=loop, ssl_context=ssl_context,
loop=loop, ssl_context=ssl_context, **kwargs
)

await connection.connect(timeout=timeout)
Expand Down
37 changes: 24 additions & 13 deletions tests/test_kwargs.py
Expand Up @@ -2,7 +2,7 @@

from aio_pika import connect
from aio_pika.connection import Connection
from aio_pika.robust_connection import RobustConnection
from aio_pika.robust_connection import RobustConnection, connect_robust


class MockConnection(Connection):
Expand All @@ -12,8 +12,6 @@ async def connect(self, timeout=None, **kwargs):

class MockConnectionRobust(RobustConnection):
async def connect(self, timeout=None, **kwargs):
self.kwargs["reconnect_interval"] = self.reconnect_interval
self.kwargs["fail_fast"] = self.fail_fast
return self


Expand All @@ -31,7 +29,6 @@ async def connect(self, timeout=None, **kwargs):
"yes": True,
"no": False,
"": False,
None: False,
},
parse_timeout: {
"0": 0,
Expand All @@ -48,27 +45,41 @@ async def connect(self, timeout=None, **kwargs):
class TestCase:
CONNECTION_CLASS = MockConnection

async def get_instance(self, url):
return await connect(url, connection_class=self.CONNECTION_CLASS)
async def get_instance(self, url, **kwargs):
return await connect(
url, connection_class=self.CONNECTION_CLASS, **kwargs
)

async def test_kwargs(self):
instance = await self.get_instance("amqp://localhost/")

for key, parser, default in self.CONNECTION_CLASS.KWARGS_TYPES:
assert key in instance.kwargs
assert instance.kwargs[key] is parser(default)
assert hasattr(instance, key)
assert getattr(instance, key) is parser(default)

async def test_kwargs_values(self):
for key, parser, default in self.CONNECTION_CLASS.KWARGS_TYPES:
positives = VALUE_GENERATORS[parser] # type: ignore
positives = VALUE_GENERATORS[parser] # type: ignore
for example, expected in positives.items(): # type: ignore
instance = await self.get_instance(
"amqp://localhost/?{}={}".format(key, example),
f"amqp://localhost/?{key}={example}"
)
assert hasattr(instance, key)
assert getattr(instance, key) == expected

assert key in instance.kwargs
assert instance.kwargs[key] == expected
instance = await self.get_instance(
"amqp://localhost", **{key: example}
)
assert hasattr(instance, key)
assert getattr(instance, key) == expected


class TestCaseRobust(TestCase):
CONNECTION_CLASS = MockConnectionRobust # type: ignore
CONNECTION_CLASS = MockConnectionRobust # type: ignore

async def get_instance(self, url, **kwargs):
return await connect_robust(
url,
connection_class=self.CONNECTION_CLASS,
**kwargs, # type: ignore
)

0 comments on commit 3952d47

Please sign in to comment.