Skip to content

Commit

Permalink
Upgrade aiocoap. Fix some Faker uses, minor lint problems. Ignore one…
Browse files Browse the repository at this point in the history
… test warning.
  • Loading branch information
asercrespo committed Jul 12, 2022
1 parent 71e255f commit 216a8ef
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 16 deletions.
2 changes: 1 addition & 1 deletion pytest.ini
Expand Up @@ -3,7 +3,7 @@ filterwarnings =
; Known deprecation warnings in newer versions of Python
ignore:"@coroutine" decorator is deprecated since Python 3\.8, use "async def" instead:DeprecationWarning
ignore:The loop argument is deprecated since Python 3\.8, and scheduled for removal in Python 3\.10:DeprecationWarning
ignore:Using or importing the ABCs from 'collections' instead of from 'collections\.abc' is deprecated since Python 3\.3, and in 3\.10 it will stop working:DeprecationWarning
ignore:Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated since Python 3.3,\s*and in 3\.[0-9]+ it will stop working:DeprecationWarning
ignore:Using sendmsg\(\) method on sockets returned from get_extra_info\('socket'\) will be prohibited in asyncio 3\.9\.:DeprecationWarning
ignore:Using recvmsg\(\) method on sockets returned from get_extra_info\('socket'\) will be prohibited in asyncio 3\.9\.:DeprecationWarning

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -40,7 +40,7 @@
test_requires.append("bump2version>=1.0,<2.0")

if is_coap_supported():
install_requires.append('aiocoap[linkheader]==0.4a1')
install_requires.append('aiocoap[linkheader]==0.4.3')

if is_mqtt_supported():
install_requires.append('hbmqtt>=0.9.4,<1.0')
Expand Down
6 changes: 3 additions & 3 deletions tests/protocols/ws/test_server.py
Expand Up @@ -286,9 +286,9 @@ def test_on_event(websocket_server):
@tornado.gen.coroutine
def test_coroutine():
observe_msg_id = Faker().pyint()
payload_01 = Faker().pydict(10, True, str, float)
payload_02 = Faker().pydict(10, True, str, float)
payload_03 = Faker().pydict(10, True, int)
payload_01 = Faker().pydict(10, True, [str, float])
payload_02 = Faker().pydict(10, True, [str, float])
payload_03 = Faker().pydict(10, True, [int])

conn = yield tornado.websocket.websocket_connect(url_thing_01)

Expand Down
7 changes: 4 additions & 3 deletions tests/utils.py
Expand Up @@ -15,7 +15,7 @@
def run_test_coroutine(coro, timeout=None):
"""Synchronously runs the given test coroutine with an optinally defined timeout."""

timeout = timeout if timeout else os.getenv(TIMEOUT_CORO_VAR, DEFAULT_TIMEOUT_SECS)
timeout = timeout if timeout else os.getenv(TIMEOUT_CORO_VAR, str(DEFAULT_TIMEOUT_SECS))

tornado.ioloop.IOLoop.current().run_sync(coro, timeout=float(timeout))

Expand All @@ -38,11 +38,12 @@ def assert_equal_dict(dict_a, dict_b, compare_as_unicode=False):
def find_free_port():
"""Returns a free TCP port by attempting to open a socket on an OS-assigned port."""

sock = None
try:
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
sock.bind(("", 0))
return sock.getsockname()[1]
finally:
# noinspection PyUnboundLocalVariable
sock.close()
if sock:
sock.close()
2 changes: 1 addition & 1 deletion tests/wot/test_exposed.py
Expand Up @@ -225,7 +225,7 @@ def test_coroutine():

observable_prop = exposed_thing.on_property_change(prop_name)

property_values = Faker().pylist(5, True, *(str,))
property_values = Faker().pylist(5, True, [str])

emitted_values = []

Expand Down
19 changes: 12 additions & 7 deletions wotpy/protocols/coap/server.py
Expand Up @@ -184,13 +184,18 @@ def _get_bind_address(self):
When the full-featured UDP6 transport is not available it
will try to guess the main IPv4 address and bind to that."""

transports = list(aiocoap.defaults.get_default_servertransports())

if not (len(transports) == 1 and transports[0] == "udp6"):
self._logr.warning("Platform does not support aiocoap udp6 transport: {}".format(transports))
return get_main_ipv4_address(), self.port
else:
return "::", self.port
# TODO: Check if this is needed in this version of aiocoap.
# Keep in mind that "get_default_servertransports" is only intented for internal use.

# transports = list(aiocoap.defaults.get_default_servertransports())

# if not (len(transports) == 1 and transports[0] == "udp6"):
# self._logr.warning("Platform does not support aiocoap udp6 transport: {}".format(transports))
# return get_main_ipv4_address(), self.port
# else:
# return "::", self.port

return "::", self.port

@tornado.gen.coroutine
def start(self):
Expand Down

0 comments on commit 216a8ef

Please sign in to comment.