This is an automated email from the ASF dual-hosted git repository. astitcher pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/qpid-proton.git
The following commit(s) were added to refs/heads/main by this push: new 39892d990 PROTON-2322/PROTON-2813: [Python] Finish PEP8 sanitization 39892d990 is described below commit 39892d990459d02aeb67b1c3683c1d428867fb04 Author: Andrew Stitcher <astitc...@apache.org> AuthorDate: Fri Apr 12 18:40:38 2024 -0400 PROTON-2322/PROTON-2813: [Python] Finish PEP8 sanitization This is a broad but shallow change, that changes a lot of files in fairly minor ways. --- python/cproton.py | 23 ++++++-- python/examples/broker.py | 10 ++-- python/examples/db_ctrl.py | 6 +- python/examples/server.py | 3 +- python/examples/server_tx.py | 3 +- python/examples/test_examples.py | 20 +++---- python/proton/_data.py | 24 ++++---- python/proton/_delivery.py | 2 +- python/proton/_events.py | 19 +++--- python/proton/_handlers.py | 10 ++-- python/proton/_message.py | 20 +++---- python/proton/_reactor.py | 3 +- python/proton/_tracing.py | 2 - python/proton/_transport.py | 7 ++- python/proton/_utils.py | 2 +- python/proton/utils.py | 3 +- python/setup.cfg | 26 +-------- ...st_PROTON_1709_application_event_object_leak.py | 3 +- ...test_PROTON_1800_syncrequestresponse_fd_leak.py | 1 - ..._PROTON_2116_blocking_connection_object_leak.py | 4 +- python/tests/proton_tests/__init__.py | 3 + python/tests/proton_tests/__main__.py | 2 +- python/tests/proton_tests/codec.py | 48 +++++++++++----- python/tests/proton_tests/common.py | 9 ++- python/tests/proton_tests/connect.py | 5 +- python/tests/proton_tests/engine.py | 67 ++++++++++++---------- python/tests/proton_tests/handler.py | 4 +- python/tests/proton_tests/interop.py | 2 +- python/tests/proton_tests/main.py | 19 +++--- python/tests/proton_tests/message.py | 17 ++++-- python/tests/proton_tests/reactor.py | 41 ++++++------- python/tests/proton_tests/sasl.py | 46 +++++++-------- python/tests/proton_tests/soak.py | 8 +-- python/tests/proton_tests/ssl.py | 17 +++--- python/tests/proton_tests/transport.py | 4 +- python/tests/proton_tests/utils.py | 8 ++- 36 files changed, 254 insertions(+), 237 deletions(-) diff --git a/python/cproton.py b/python/cproton.py index 24281699d..61a60589e 100644 --- a/python/cproton.py +++ b/python/cproton.py @@ -17,6 +17,9 @@ # under the License. # +# Ignore unused imports in this file +# flake8: noqa: F401 + import atexit from uuid import UUID @@ -202,7 +205,7 @@ def bytes2string(b, encoding='utf8'): def py2bytes(py): - if isinstance(py, (bytes, bytearray,memoryview)): + if isinstance(py, (bytes, bytearray, memoryview)): s = ffi.from_buffer(py) return len(s), s elif isinstance(py, str): @@ -299,17 +302,21 @@ def pn_transport_set_pytracer(transport, tracer): attrs['_tracer'] = tracer lib.pn_transport_set_tracer(transport, lib.pn_pytracer) + retained_objects = set() lib.init() + @atexit.register def clear_retained_objects(): retained_objects.clear() + def retained_count(): """ Debugging aid to give the number of wrapper objects retained by the bindings""" return len(retained_objects) + @ffi.def_extern() def pn_pyref_incref(obj): retained_objects.add(obj) @@ -443,10 +450,12 @@ def pn_condition_get_description(cond): def pn_error_text(error): return utf82string(lib.pn_error_text(error)) + # pn_data bindings def pn_data_lookup(data, name): return lib.pn_data_lookup(data, string2utf8(name)) + def pn_data_put_decimal128(data, d): return lib.pn_data_put_decimal128(data, py2decimal128(d)) @@ -466,6 +475,7 @@ def pn_data_put_string(data, s): def pn_data_put_symbol(data, s): return lib.pn_data_put_symbol(data, string2bytes(s, 'ascii')) + def pn_data_get_decimal128(data): return decimal1282py(lib.pn_data_get_decimal128(data)) @@ -545,6 +555,7 @@ def pn_receiver(session, name): def pn_delivery(link, tag): return lib.pn_delivery(link, py2bytes(tag)) + def pn_link_name(link): return utf82string(lib.pn_link_name(link)) @@ -644,6 +655,7 @@ def pn_message_set_reply_to_group_id(message, value): def pn_transport_log(transport, message): lib.pn_transport_log(transport, string2utf8(message)) + def pn_transport_get_user(transport): return utf82string(lib.pn_transport_get_user(transport)) @@ -671,6 +683,7 @@ def pn_sasl_config_name(sasl, name): def pn_sasl_config_path(sasl, path): lib.pn_sasl_config_path(sasl, string2utf8(path)) + def pn_ssl_domain_set_credentials(domain, cert_file, key_file, password): return lib.pn_ssl_domain_set_credentials(domain, string2utf8(cert_file), string2utf8(key_file), string2utf8(password)) @@ -692,7 +705,7 @@ def pn_ssl_get_remote_subject_subfield(ssl, subfield_name): def pn_ssl_get_remote_subject(ssl): - return utf82string(lib.pn_ssl_get_remote_subject(ssl)) + return utf82string(lib.pn_ssl_get_remote_subject(ssl)) # int pn_ssl_domain_set_protocols(pn_ssl_domain_t *domain, const char *protocols); @@ -727,7 +740,7 @@ def pn_ssl_get_protocol_name(ssl, size): def pn_ssl_get_cert_fingerprint(ssl, fingerprint_len, hash_alg): buff = ffi.new('char[]', fingerprint_len) r = lib.pn_ssl_get_cert_fingerprint(ssl, buff, fingerprint_len, hash_alg) - if r==PN_OK: + if r == PN_OK: return utf82string(buff) return None @@ -736,10 +749,10 @@ def pn_ssl_get_cert_fingerprint(ssl, fingerprint_len, hash_alg): def pn_ssl_get_peer_hostname(ssl, size): buff = ffi.new('char[]', size) r = lib.pn_ssl_get_peer_hostname_py(ssl, buff, size) - if r==PN_OK: + if r == PN_OK: return r, utf82string(buff) return r, None + def pn_ssl_set_peer_hostname(ssl, hostname): return lib.pn_ssl_set_peer_hostname(ssl, string2utf8(hostname)) - diff --git a/python/examples/broker.py b/python/examples/broker.py index d15ad506b..753b7af3f 100755 --- a/python/examples/broker.py +++ b/python/examples/broker.py @@ -114,11 +114,11 @@ class Broker(MessagingHandler): self.remove_stale_consumers(event.connection) def remove_stale_consumers(self, connection): - l = connection.link_head(Endpoint.REMOTE_ACTIVE) - while l: - if l.is_sender: - self._unsubscribe(l) - l = l.next(Endpoint.REMOTE_ACTIVE) + link = connection.link_head(Endpoint.REMOTE_ACTIVE) + while link: + if link.is_sender: + self._unsubscribe(link) + link = link.next(Endpoint.REMOTE_ACTIVE) def on_sendable(self, event): self._queue(event.link.source.address).dispatch(event.link) diff --git a/python/examples/db_ctrl.py b/python/examples/db_ctrl.py index 8b5d4c3e7..3d2cdcf59 100755 --- a/python/examples/db_ctrl.py +++ b/python/examples/db_ctrl.py @@ -38,10 +38,10 @@ else: print(r) elif sys.argv[1] == "insert": while True: - l = sys.stdin.readline() - if not l: + line = sys.stdin.readline() + if not line: break - conn.execute("INSERT INTO records(description) VALUES (?)", (l.rstrip(),)) + conn.execute("INSERT INTO records(description) VALUES (?)", (line.rstrip(),)) conn.commit() else: print("Unrecognised command: %s" % sys.argv[1]) diff --git a/python/examples/server.py b/python/examples/server.py index 4aca80dfc..f664a9054 100755 --- a/python/examples/server.py +++ b/python/examples/server.py @@ -39,7 +39,8 @@ class Server(MessagingHandler): self.conn = event.container.connect(self.url, desired_capabilities="ANONYMOUS-RELAY") def on_connection_opened(self, event): - if event.connection.remote_offered_capabilities and 'ANONYMOUS-RELAY' in event.connection.remote_offered_capabilities: + capabilities = event.connection.remote_offered_capabilities + if capabilities and 'ANONYMOUS-RELAY' in capabilities: self.receiver = event.container.create_receiver(self.conn, self.address) self.server = self.container.create_sender(self.conn, None) else: diff --git a/python/examples/server_tx.py b/python/examples/server_tx.py index 4f70cade2..9a524f28f 100755 --- a/python/examples/server_tx.py +++ b/python/examples/server_tx.py @@ -68,7 +68,8 @@ class TxServer(MessagingHandler): self.container.declare_transaction(self.conn, handler=TxRequest(response, sender, event.delivery)) def on_connection_opened(self, event): - if event.connection.remote_offered_capabilities and 'ANONYMOUS-RELAY' in event.connection.remote_offered_capabilities: + capabilities = event.connection.remote_offered_capabilities + if capabilities and 'ANONYMOUS-RELAY' in capabilities: self.relay = self.container.create_sender(self.conn, None) diff --git a/python/examples/test_examples.py b/python/examples/test_examples.py index 1fdfd67c0..94f54899b 100644 --- a/python/examples/test_examples.py +++ b/python/examples/test_examples.py @@ -55,7 +55,7 @@ def check_call(args, **kwargs): class ExamplesTest(unittest.TestCase): def test_helloworld(self, example="helloworld.py"): with run([example]) as p: - output = [l.strip() for l in p.stdout] + output = [line.strip() for line in p.stdout] self.assertEqual(output, ['Hello World!']) def test_helloworld_direct(self): @@ -74,7 +74,7 @@ class ExamplesTest(unittest.TestCase): with Popen([recv]) as r: with run([send]): pass - actual = [l.strip() for l in r.stdout] + actual = [line.strip() for line in r.stdout] expected = ["{'sequence': %i}" % (i + 1,) for i in range(100)] self.assertEqual(actual, expected) @@ -84,12 +84,12 @@ class ExamplesTest(unittest.TestCase): time.sleep(sleep) with run(client) as c: s.terminate() - actual = [l.strip() for l in c.stdout] + actual = [line.strip() for line in c.stdout] inputs = ["Twas brillig, and the slithy toves", "Did gire and gymble in the wabe.", "All mimsy were the borogroves,", "And the mome raths outgrabe."] - expected = ["%s => %s" % (l, l.upper()) for l in inputs] + expected = ["%s => %s" % (line, line.upper()) for line in inputs] self.assertEqual(actual, expected) def test_sync_client_server(self): @@ -125,14 +125,14 @@ class ExamplesTest(unittest.TestCase): pass r.wait() # verify output of receive - actual = [l.strip() for l in r.stdout] + actual = [line.strip() for line in r.stdout] expected = ["inserted message %i" % (i + 1) for i in range(100)] self.assertEqual(actual, expected) # verify state of databases with run(['db_ctrl.py', 'list', './dst_db']) as v: expected = ["(%i, 'Message-%i')" % (i + 1, i + 1) for i in range(100)] - actual = [l.strip() for l in v.stdout] + actual = [line.strip() for line in v.stdout] self.assertEqual(actual, expected) def test_tx_send_tx_recv(self): @@ -145,7 +145,7 @@ class ExamplesTest(unittest.TestCase): with run(['simple_send.py', '-a', 'localhost:8888']): pass r.wait() - actual = [l.strip() for l in r.stdout] + actual = [line.strip() for line in r.stdout] expected = ["{'sequence': %i}" % (i + 1,) for i in range(100)] self.assertEqual(actual, expected) @@ -153,7 +153,7 @@ class ExamplesTest(unittest.TestCase): with Popen(['direct_send.py', '-a', 'localhost:8888']): time.sleep(0.5) with run(['simple_recv.py', '-a', 'localhost:8888']) as r: - actual = [l.strip() for l in r.stdout] + actual = [line.strip() for line in r.stdout] expected = ["{'sequence': %i}" % (i + 1,) for i in range(100)] self.assertEqual(actual, expected) @@ -162,11 +162,11 @@ class ExamplesTest(unittest.TestCase): pass with run(['selected_recv.py', '-m', '50']) as r: - actual = [l.strip() for l in r.stdout] + actual = [line.strip() for line in r.stdout] expected = ["green %i" % (i + 1) for i in range(100) if i % 2 == 0] self.assertEqual(actual, expected) with run(['simple_recv.py', '-m', '50']) as r: - actual = [l.strip() for l in r.stdout] + actual = [line.strip() for line in r.stdout] expected = ["red %i" % (i + 1) for i in range(100) if i % 2 == 1] self.assertEqual(actual, expected) diff --git a/python/proton/_data.py b/python/proton/_data.py index bf627b6d9..fb02e9f27 100644 --- a/python/proton/_data.py +++ b/python/proton/_data.py @@ -77,10 +77,10 @@ class ulong(long): An unsigned 64 bit integer in the range :math:`0` to :math:`2^{64} - 1` inclusive. """ - def __init__(self, l: int) -> None: - if l < 0: + def __init__(self, u64: int) -> None: + if u64 < 0: raise AssertionError("initializing ulong with negative value") - super(ulong, self).__new__(ulong, l) + super(ulong, self).__new__(ulong, u64) def __repr__(self) -> str: return "ulong(%s)" % long.__repr__(self) @@ -194,10 +194,10 @@ class uint(long): A 32 bit unsigned integer in the range :math:`0` to :math:`2^{32} - 1` inclusive. """ - def __init__(self, l: int) -> None: - if l < 0: + def __init__(self, u32: int) -> None: + if u32 < 0: raise AssertionError("initializing uint with negative value") - super(uint, self).__new__(uint, l) + super(uint, self).__new__(uint, u32) def __repr__(self) -> str: return "uint(%s)" % long.__repr__(self) @@ -517,11 +517,11 @@ class SymbolList(list): def _check_list(self, t: Iterable[Any]) -> List[Any]: """ Check all items in list are :class:`symbol`s (or are converted to symbols). """ - l = [] + item = [] if t: for v in t: - l.append(_check_is_symbol(v, self.raise_on_error)) - return l + item.append(_check_is_symbol(v, self.raise_on_error)) + return item def to_array(self): return Array(UNDESCRIBED, PN_SYMBOL, *self) @@ -1004,15 +1004,15 @@ class Data: """ self._check(pn_data_put_ulong(self._data, ul)) - def put_long(self, l: Union[long, int]) -> None: + def put_long(self, i64: Union[long, int]) -> None: """ Puts a signed long value. - :param l: an integral value in the range :math:`-(2^{63})` to :math:`2^{63} - 1` inclusive. + :param i64: an integral value in the range :math:`-(2^{63})` to :math:`2^{63} - 1` inclusive. :raise: * ``AssertionError`` if parameter is out of the range :math:`-(2^{63})` to :math:`2^{63} - 1` inclusive. * :exc:`DataException` if there is a Proton error. """ - self._check(pn_data_put_long(self._data, l)) + self._check(pn_data_put_long(self._data, i64)) def put_timestamp(self, t: Union[timestamp, int]) -> None: """ diff --git a/python/proton/_delivery.py b/python/proton/_delivery.py index f78b23596..e47d99ad7 100644 --- a/python/proton/_delivery.py +++ b/python/proton/_delivery.py @@ -31,7 +31,7 @@ from ._condition import cond2obj, obj2cond from ._data import dat2obj, obj2dat from ._wrapper import Wrapper -from typing import Dict, List, Optional, Type, Union, TYPE_CHECKING, Any +from typing import Dict, List, Optional, Type, Union, TYPE_CHECKING if TYPE_CHECKING: from ._condition import Condition diff --git a/python/proton/_events.py b/python/proton/_events.py index 76d14f021..55c5d7717 100644 --- a/python/proton/_events.py +++ b/python/proton/_events.py @@ -57,7 +57,6 @@ class Collector: return pn_collector_more(self._impl) def pop(self) -> None: - ev = self.peek() pn_collector_pop(self._impl) def release(self) -> None: @@ -484,9 +483,9 @@ class Event(EventBase): If none of these has a handler, then ``None`` is returned. """ - l = self.link - if l: - h = l.handler + link = self.link + if link: + h = link.handler if h: return h s = self.session @@ -572,9 +571,9 @@ class Event(EventBase): ``link`` property, that does an additional check on the type of the link. """ - l = self.link - if l and l.is_sender: - return l + link = self.link + if link and link.is_sender: + return link else: return None @@ -585,9 +584,9 @@ class Event(EventBase): none is associated with it. This is essentially an alias for ``link`` property, that does an additional check on the type of the link. """ - l = self.link - if l and l.is_receiver: - return l + link = self.link + if link and link.is_receiver: + return link else: return None diff --git a/python/proton/_handlers.py b/python/proton/_handlers.py index c60f8efb5..b225dda34 100644 --- a/python/proton/_handlers.py +++ b/python/proton/_handlers.py @@ -1164,10 +1164,10 @@ class IOHandler(Handler): if not r.quiesced: return - d = r.timer_deadline + r.timer_deadline readable, writable, expired = self._selector.select(r.timeout) - now = r.mark() + r.mark() for s in readable: s.readable() @@ -1192,7 +1192,7 @@ class IOHandler(Handler): try: b = s.recv(capacity) if len(b) > 0: - n = t.push(b) + t.push(b) else: # EOF handling self.on_selectable_error(event) @@ -1305,7 +1305,7 @@ class IOHandler(Handler): try: capacity = transport.capacity() selectable.reading = capacity > 0 - except: + except ProtonException: if transport.closed: selectable.terminate() selectable._transport = None @@ -1313,7 +1313,7 @@ class IOHandler(Handler): try: pending = transport.pending() selectable.writing = pending > 0 - except: + except ProtonException: if transport.closed: selectable.terminate() selectable._transport = None diff --git a/python/proton/_message.py b/python/proton/_message.py index 2b1032a0e..211a54e62 100644 --- a/python/proton/_message.py +++ b/python/proton/_message.py @@ -17,19 +17,19 @@ # under the License. # -from cproton import PN_DEFAULT_PRIORITY, PN_STRING, PN_UUID, PN_OVERFLOW, pn_error_text, pn_message, \ +from cproton import PN_DEFAULT_PRIORITY, PN_UUID, PN_OVERFLOW, pn_error_text, pn_message, \ pn_message_annotations, pn_message_body, pn_message_clear, pn_message_decode, \ pn_message_encode, pn_message_error, pn_message_free, pn_message_get_address, pn_message_get_content_encoding, \ - pn_message_get_content_type, pn_message_get_correlation_id, pn_message_get_creation_time, pn_message_get_delivery_count, \ - pn_message_get_expiry_time, pn_message_get_group_id, pn_message_get_group_sequence, pn_message_get_id, pn_message_get_priority, \ - pn_message_get_reply_to, pn_message_get_reply_to_group_id, pn_message_get_subject, pn_message_get_ttl, \ - pn_message_get_user_id, pn_message_instructions, pn_message_is_durable, \ + pn_message_get_content_type, pn_message_get_correlation_id, pn_message_get_creation_time, \ + pn_message_get_delivery_count, pn_message_get_expiry_time, pn_message_get_group_id, pn_message_get_group_sequence, \ + pn_message_get_id, pn_message_get_priority, pn_message_get_reply_to, pn_message_get_reply_to_group_id, \ + pn_message_get_subject, pn_message_get_ttl, pn_message_get_user_id, pn_message_instructions, pn_message_is_durable, \ pn_message_is_first_acquirer, pn_message_is_inferred, pn_message_properties, pn_message_set_address, \ - pn_message_set_content_encoding, pn_message_set_content_type, pn_message_set_correlation_id, pn_message_set_creation_time, \ - pn_message_set_delivery_count, pn_message_set_durable, pn_message_set_expiry_time, pn_message_set_first_acquirer, \ - pn_message_set_group_id, pn_message_set_group_sequence, pn_message_set_id, pn_message_set_inferred, pn_message_set_priority, \ - pn_message_set_reply_to, pn_message_set_reply_to_group_id, pn_message_set_subject, \ - pn_message_set_ttl, pn_message_set_user_id + pn_message_set_content_encoding, pn_message_set_content_type, pn_message_set_correlation_id, \ + pn_message_set_creation_time, pn_message_set_delivery_count, pn_message_set_durable, pn_message_set_expiry_time, \ + pn_message_set_first_acquirer, pn_message_set_group_id, pn_message_set_group_sequence, pn_message_set_id, \ + pn_message_set_inferred, pn_message_set_priority, pn_message_set_reply_to, pn_message_set_reply_to_group_id, \ + pn_message_set_subject, pn_message_set_ttl, pn_message_set_user_id from ._common import millis2secs, secs2millis from ._data import char, Data, symbol, ulong, AnnotationDict diff --git a/python/proton/_reactor.py b/python/proton/_reactor.py index b00728f75..fc13135b6 100644 --- a/python/proton/_reactor.py +++ b/python/proton/_reactor.py @@ -1460,7 +1460,8 @@ class Container(Reactor): :param source: Address of source node. :param name: Sender name. :param handler: Event handler for this sender. - :param tags: Function to generate tags for this sender of the form ``def simple_tags():`` and returns a ``bytes`` type + :param tags: Function to generate tags for this sender of the form ``def simple_tags():`` + and returns a ``bytes`` type :param options: A single option, or a list of sender options :return: New sender instance. diff --git a/python/proton/_tracing.py b/python/proton/_tracing.py index f08d31fc5..d45fd31e6 100644 --- a/python/proton/_tracing.py +++ b/python/proton/_tracing.py @@ -18,11 +18,9 @@ # import atexit -import functools import os import sys import time -import weakref try: import opentracing diff --git a/python/proton/_transport.py b/python/proton/_transport.py index 612857f6b..489654b14 100644 --- a/python/proton/_transport.py +++ b/python/proton/_transport.py @@ -19,7 +19,7 @@ from typing import Callable, Optional, Type, Union, TYPE_CHECKING, List -from cproton import PN_EOS, PN_OK, PN_SASL_AUTH, PN_SASL_NONE, PN_SASL_OK, PN_SASL_PERM, PN_SASL_SYS, PN_SASL_TEMP, \ +from cproton import PN_EOS, PN_SASL_AUTH, PN_SASL_NONE, PN_SASL_OK, PN_SASL_PERM, PN_SASL_SYS, PN_SASL_TEMP, \ PN_SSL_ANONYMOUS_PEER, PN_SSL_CERT_SUBJECT_CITY_OR_LOCALITY, PN_SSL_CERT_SUBJECT_COMMON_NAME, \ PN_SSL_CERT_SUBJECT_COUNTRY_NAME, PN_SSL_CERT_SUBJECT_ORGANIZATION_NAME, PN_SSL_CERT_SUBJECT_ORGANIZATION_UNIT, \ PN_SSL_CERT_SUBJECT_STATE_OR_PROVINCE, PN_SSL_MD5, PN_SSL_MODE_CLIENT, PN_SSL_MODE_SERVER, PN_SSL_RESUME_NEW, \ @@ -861,8 +861,9 @@ class SSL(object): # single step. So catch any attempt by the application to provide what # may be a different configuration than the original (hack) ssl = transport._ssl - if (domain and (ssl._domain is not domain) or - session_details and (ssl._session_details is not session_details)): + different_domain = domain and (ssl._domain is not domain) + different_session_details = session_details and (ssl._session_details is not session_details) + if different_domain or different_session_details: raise SSLException("Cannot re-configure existing SSL object!") else: obj = super(SSL, cls).__new__(cls) diff --git a/python/proton/_utils.py b/python/proton/_utils.py index 1d2474167..24b7e235d 100644 --- a/python/proton/_utils.py +++ b/python/proton/_utils.py @@ -65,7 +65,7 @@ class BlockingLink: self.connection.wait(lambda: self.link.state & Endpoint.REMOTE_CLOSED, timeout=timeout, msg="Opening link %s" % self.link.name) - except Timeout as e: + except Timeout: pass self._checkClosed() diff --git a/python/proton/utils.py b/python/proton/utils.py index bdc0e30ef..e97caebc9 100644 --- a/python/proton/utils.py +++ b/python/proton/utils.py @@ -17,7 +17,8 @@ # under the License. # -from ._utils import BlockingConnection, BlockingSender, BlockingReceiver, SyncRequestResponse, SendException, LinkDetached, ConnectionClosed +from ._utils import BlockingConnection, BlockingSender, BlockingReceiver, SyncRequestResponse, SendException, \ + LinkDetached, ConnectionClosed __all__ = [ 'BlockingConnection', diff --git a/python/setup.cfg b/python/setup.cfg index 00791fc6a..212a92025 100644 --- a/python/setup.cfg +++ b/python/setup.cfg @@ -13,10 +13,10 @@ classifiers = Programming Language :: Python Programming Language :: Python :: 3 Programming Language :: Python :: 3 :: Only - Programming Language :: Python :: 3.8 Programming Language :: Python :: 3.9 Programming Language :: Python :: 3.10 Programming Language :: Python :: 3.11 + Programming Language :: Python :: 3.12 [options] packages = proton @@ -28,26 +28,4 @@ install_requires = cffi>=1.0.0 opentracing = opentracing; jaeger_client [flake8] -# TODO(PROTON-2322) decrease the limit -max-line-length = 150 - -# TODO(PROTON-2322) re-enable all these warnings -ignore = - # do not use bare 'except' - E722, - # imported but unused - F401, - # ambiguous variable name 'l' - E741, - # local variable 'int_nodes' is assigned to but never used - F841, - # TODO(PROTON-2322) decide which of these two warnings we want disabled - # _transport.py:908:21: W503 line break before binary operator - # _transport.py:907:56: W504 line break after binary operator - W504, - -exclude = - # TODO(PROTON-2095) generated by SWIG - cproton.py, - # ignore the tests as they are not shipped - tests +max-line-length = 125 diff --git a/python/tests/integration/test_PROTON_1709_application_event_object_leak.py b/python/tests/integration/test_PROTON_1709_application_event_object_leak.py index 48014d59c..506449953 100644 --- a/python/tests/integration/test_PROTON_1709_application_event_object_leak.py +++ b/python/tests/integration/test_PROTON_1709_application_event_object_leak.py @@ -63,7 +63,7 @@ class Proton1709Test(unittest.TestCase): p = Program(injector) c = Container(p) t = threading.Thread(target=c.run) - object_counts = array.array('L', [0]*3) + object_counts = array.array('L', [0] * 3) t.start() p.on_start_.wait() @@ -95,4 +95,3 @@ class Proton1709Test(unittest.TestCase): "Object counts should not be increasing too fast: {0}".format(object_counts)) self.assertTrue(object_counts[2] - object_counts[0] <= 10, "No objects should be leaking at the end: {0}".format(object_counts)) - diff --git a/python/tests/integration/test_PROTON_1800_syncrequestresponse_fd_leak.py b/python/tests/integration/test_PROTON_1800_syncrequestresponse_fd_leak.py index 32471ffd3..f6db651c3 100644 --- a/python/tests/integration/test_PROTON_1800_syncrequestresponse_fd_leak.py +++ b/python/tests/integration/test_PROTON_1800_syncrequestresponse_fd_leak.py @@ -39,7 +39,6 @@ import proton.reactor from proton import Message from proton.utils import SyncRequestResponse, BlockingConnection -from proton.handlers import IncomingMessageHandler def get_fd_set(): diff --git a/python/tests/integration/test_PROTON_2116_blocking_connection_object_leak.py b/python/tests/integration/test_PROTON_2116_blocking_connection_object_leak.py index 3105ccb21..0520d92dc 100644 --- a/python/tests/integration/test_PROTON_2116_blocking_connection_object_leak.py +++ b/python/tests/integration/test_PROTON_2116_blocking_connection_object_leak.py @@ -87,14 +87,14 @@ class ReconnectingTestClient: try: recv.close() recv = None - except: + except Exception: self.count_objects("link close() failed") pass try: conn.close() conn = None self.count_objects("conn closed") - except: + except Exception: self.count_objects("conn close() failed") pass subscribed = False diff --git a/python/tests/proton_tests/__init__.py b/python/tests/proton_tests/__init__.py index 5d37bd5a7..cbbf8eded 100644 --- a/python/tests/proton_tests/__init__.py +++ b/python/tests/proton_tests/__init__.py @@ -17,6 +17,9 @@ # under the License. # +# Ignore unused imports in this file +# flake8: noqa: F401 + from . import codec from . import engine from . import message diff --git a/python/tests/proton_tests/__main__.py b/python/tests/proton_tests/__main__.py index 6c1fea5c2..fb29d3a2a 100644 --- a/python/tests/proton_tests/__main__.py +++ b/python/tests/proton_tests/__main__.py @@ -17,7 +17,7 @@ # under the License. # -from proton_tests.main import main +from .main import main if __name__ == '__main__': main() diff --git a/python/tests/proton_tests/codec.py b/python/tests/proton_tests/codec.py index d8fb8f0d5..bfc6913c2 100644 --- a/python/tests/proton_tests/codec.py +++ b/python/tests/proton_tests/codec.py @@ -20,7 +20,8 @@ import sys from uuid import uuid4 -from proton import * +from proton import AnnotationDict, Array, Data, Described, PropertyDict, SymbolList, UNDESCRIBED, \ + char, decimal32, decimal64, decimal128, symbol, timestamp, ubyte, uint, ulong, ushort from . import common @@ -180,7 +181,7 @@ class DataTest(Test): count, described, type = self.data.get_array() assert count == len(values), count if dtype is None: - assert described == False + assert described is False else: assert described assert type == aTYPE, type @@ -208,14 +209,29 @@ class DataTest(Test): def _test_int_array(self, atype): self._testArray(None, None, atype, *self.int_values(atype)) - def testByteArray(self): self._test_int_array("byte") - def testUbyteArray(self): self._test_int_array("ubyte") - def testShortArray(self): self._test_int_array("short") - def testUshortArray(self): self._test_int_array("ushort") - def testIntArray(self): self._test_int_array("int") - def testUintArray(self): self._test_int_array("uint") - def testLongArray(self): self._test_int_array("long") - def testUlongArray(self): self._test_int_array("ulong") + def testByteArray(self): + self._test_int_array("byte") + + def testUbyteArray(self): + self._test_int_array("ubyte") + + def testShortArray(self): + self._test_int_array("short") + + def testUshortArray(self): + self._test_int_array("ushort") + + def testIntArray(self): + self._test_int_array("int") + + def testUintArray(self): + self._test_int_array("uint") + + def testLongArray(self): + self._test_int_array("long") + + def testUlongArray(self): + self._test_int_array("ulong") def testUUIDArray(self): self._testArray(None, None, "uuid", uuid4(), uuid4(), uuid4()) @@ -375,25 +391,29 @@ class DataTest(Test): def _test_int(self, itype): self._test(itype, *self.int_values(itype)) - def testByte(self): self._test_int("byte") + def testByte(self): + self._test_int("byte") def testUbyte(self): self._test_int("ubyte") self.assertRaises(AssertionError, ubyte, -1) - def testShort(self): self._test_int("short") + def testShort(self): + self._test_int("short") def testUshort(self): self._test("ushort") self.assertRaises(AssertionError, ushort, -1) - def testInt(self): self._test_int("int") + def testInt(self): + self._test_int("int") def testUint(self): self._test_int("uint") self.assertRaises(AssertionError, uint, -1) - def testLong(self): self._test_int("long") + def testLong(self): + self._test_int("long") def testUlong(self): self._test_int("ulong") diff --git a/python/tests/proton_tests/common.py b/python/tests/proton_tests/common.py index 184b73b36..3aec7cc74 100644 --- a/python/tests/proton_tests/common.py +++ b/python/tests/proton_tests/common.py @@ -26,7 +26,7 @@ import subprocess from random import randint from threading import Thread from socket import socket, AF_INET, SOCK_STREAM -from subprocess import Popen, PIPE, STDOUT +from subprocess import Popen, PIPE from string import Template from proton import SASL, SSL @@ -47,7 +47,7 @@ def free_tcp_ports(count=1): sockets[-1].bind(("0.0.0.0", port)) ports.append(port) retry = 0 - except: + except OSError: retry += 1 assert retry != 100, "No free sockets available for test!" for s in sockets: @@ -88,8 +88,7 @@ def pump(transport1, transport2, buffer_size=1024): Asserts that each engine accepts some bytes every time (unless it's already closed). """ - while (pump_uni(transport1, transport2, buffer_size) or - pump_uni(transport2, transport1, buffer_size)): + while (pump_uni(transport1, transport2, buffer_size) or pump_uni(transport2, transport1, buffer_size)): pass @@ -275,7 +274,7 @@ class MessengerApp(object): self._verbose = verbose if self._verbose: print("COMMAND='%s'" % str(cmd)) - #print("ENV='%s'" % str(os.environ.copy())) + # print("ENV='%s'" % str(os.environ.copy())) try: # Handle python launch by replacing script 'filename' with # 'python abspath-to-filename' in cmdline arg list. diff --git a/python/tests/proton_tests/connect.py b/python/tests/proton_tests/connect.py index 860f8acc6..f37c51633 100644 --- a/python/tests/proton_tests/connect.py +++ b/python/tests/proton_tests/connect.py @@ -17,10 +17,9 @@ # under the License. # -import time -import sys import json -from .common import Test, SkipTest, TestServer, free_tcp_port, ensureCanTestExtendedSASL + +from .common import Test, free_tcp_port, ensureCanTestExtendedSASL from proton import SSLDomain from proton.reactor import Container from proton.handlers import MessagingHandler diff --git a/python/tests/proton_tests/engine.py b/python/tests/proton_tests/engine.py index f7a0685b4..55a39d9c1 100644 --- a/python/tests/proton_tests/engine.py +++ b/python/tests/proton_tests/engine.py @@ -20,7 +20,8 @@ import os import gc from time import time, sleep -from proton import * +from proton import Array, Condition, Collector, Connection, Data, Delivery, Disposition, Endpoint, Event, Link, \ + PropertyDict, SASL, SessionException, SymbolList, Terminus, Transport, UNDESCRIBED, symbol from proton.reactor import Container from . import common from .common import pump, Skipped @@ -265,7 +266,7 @@ class ConnectionTest(Test): try: self.c1.transport.channel_max = 666 assert False, "expected session exception" - except: + except SessionException: pass assert self.c1.transport.channel_max == upper_limit @@ -605,10 +606,10 @@ class LinkTest(Test): rcv.open() self.pump() c2 = self.rcv.session.connection - l = c2.link_head(Endpoint.LOCAL_UNINIT | Endpoint.REMOTE_ACTIVE) - while l: - l.open() - l = l.next(Endpoint.LOCAL_UNINIT | Endpoint.REMOTE_ACTIVE) + link = c2.link_head(Endpoint.LOCAL_UNINIT | Endpoint.REMOTE_ACTIVE) + while link: + link.open() + link = link.next(Endpoint.LOCAL_UNINIT | Endpoint.REMOTE_ACTIVE) self.pump() assert self.snd @@ -898,8 +899,10 @@ class TransferTest(Test): # Confirm abort discards the sender's buffered content, i.e. no data in generated transfer frame. # We want: # @transfer(20) [handle=0, delivery-id=0, delivery-tag=b"tag", message-format=0, settled=true, aborted=true] - # wanted = b"\x00\x00\x00%\x02\x00\x00\x00\x00S\x14\xd0\x00\x00\x00\x15\x00\x00\x00\nR\x00R\x00\xa0\x03tagR\x00A@@@@A" - # wanted = b"\x00\x00\x00\x26\x02\x00\x00\x00\x00S\x14\xd0\x00\x00\x00\x16\x00\x00\x00\x0bR\x00R\x00\xa0\x03tagR\x00A@@@@A@" + # wanted = b"\x00\x00\x00%\x02\x00\x00\x00\x00S\x14\xd0\x00\x00\x00\x15\x00\x00\x00\nR\x00R'\ + # b'\x00\xa0\x03tagR\x00A@@@@A" + # wanted = b"\x00\x00\x00\x26\x02\x00\x00\x00\x00S\x14\xd0\x00\x00\x00\x16\x00\x00\x00\x0bR\x00R'\ + # b'\x00\xa0\x03tagR\x00A@@@@A@" # wanted = b'\x00\x00\x00\x20\x02\x00\x00\x00\x00S\x14\xc0\x13\x0bR\x00R\x00\xa0\x03tagR\x00A@@@@A@' # wanted = b'\x00\x00\x00"\x02\x00\x00\x00\x00S\x14\xd0\x00\x00\x00\x12\x00\x00\x00\nCC\xa0\x03tagCA@@@@A' # wanted = b'\x00\x00\x00\x1d\x02\x00\x00\x00\x00S\x14\xc0\x10\x0bCC\xa0\x03tagCA@@@@A@' @@ -913,7 +916,7 @@ class TransferTest(Test): def test_multiframe_last_empty(self): self.rcv.flow(1) - sd = self.snd.delivery("tag") + self.snd.delivery("tag") msg_p1 = b"this is a test" n = self.snd.send(msg_p1) assert n == len(msg_p1) @@ -981,7 +984,7 @@ class TransferTest(Test): # fill up delivery buffer on sender for m in range(1024): - sd = self.snd.delivery("tag%s" % m) + self.snd.delivery("tag%s" % m) msg = ("message %s" % m).encode('ascii') n = self.snd.send(msg) assert n == len(msg) @@ -1003,7 +1006,7 @@ class TransferTest(Test): # add some new deliveries for m in range(1024, 1450): - sd = self.snd.delivery("tag%s" % m) + self.snd.delivery("tag%s" % m) msg = ("message %s" % m).encode('ascii') n = self.snd.send(msg) assert n == len(msg) @@ -1011,7 +1014,7 @@ class TransferTest(Test): # submit some more deliveries for m in range(1450, 1500): - sd = self.snd.delivery("tag%s" % m) + self.snd.delivery("tag%s" % m) msg = ("message %s" % m).encode('ascii') n = self.snd.send(msg) assert n == len(msg) @@ -1290,8 +1293,10 @@ class MaxFrameTransferTest(Test): assert sd.aborted # Expect a single abort transfer frame with no content. One credit is consumed. # @transfer(20) [handle=0, delivery-id=0, delivery-tag=b"tag_1", message-format=0, settled=true, aborted=true] - # wanted = b"\x00\x00\x00\x27\x02\x00\x00\x00\x00S\x14\xd0\x00\x00\x00\x17\x00\x00\x00\nR\x00R\x00\xa0\x05tag_1R\x00A@@@@A" - # wanted = b"\x00\x00\x00\x28\x02\x00\x00\x00\x00S\x14\xd0\x00\x00\x00\x18\x00\x00\x00\x0bR\x00R\x00\xa0\x05tag_1R\x00A@@@@A@" + # wanted = b"\x00\x00\x00\x27\x02\x00\x00\x00\x00S\x14\xd0\x00\x00\x00\x17\x00\x00\x00\nR\x00R'\ + # b'\x00\xa0\x05tag_1R\x00A@@@@A" + # wanted = b"\x00\x00\x00\x28\x02\x00\x00\x00\x00S\x14\xd0\x00\x00\x00\x18\x00\x00\x00\x0bR\x00R'\ + # b'\x00\xa0\x05tag_1R\x00A@@@@A@" # wanted = b'\x00\x00\x00\x22\x02\x00\x00\x00\x00S\x14\xc0\x15\x0bR\x00R\x00\xa0\x05tag_1R\x00A@@@@A@' # wanted = b'\x00\x00\x00\x24\x02\x00\x00\x00\x00S\x14\xd0\x00\x00\x00\x14\x00\x00\x00\nCC\xa0\x05tag_1CA@@@@A' # wanted = b'\x00\x00\x00\x1f\x02\x00\x00\x00\x00S\x14\xc0\x12\x0bCC\xa0\x05tag_1CA@@@@A@' @@ -1816,13 +1821,13 @@ class CreditTest(Test): self.pump() for i in range(5): - b = self.rcv.recv(512) + self.rcv.recv(512) assert self.rcv.advance() - b = self.rcv2.recv(512) + self.rcv2.recv(512) assert self.rcv2.advance() for i in range(5): - b = self.rcv2.recv(512) + self.rcv2.recv(512) assert self.rcv2.advance() @@ -2230,8 +2235,8 @@ class NoValue: assert dlv.section_number == 0 assert dlv.section_offset == 0 assert dlv.condition is None - assert dlv.failed == False - assert dlv.undeliverable == False + assert dlv.failed is False + assert dlv.undeliverable is False assert dlv.annotations is None @@ -2247,8 +2252,8 @@ class RejectValue: assert dlv.section_number == 0 assert dlv.section_offset == 0 assert dlv.condition == self.condition, (dlv.condition, self.condition) - assert dlv.failed == False - assert dlv.undeliverable == False + assert dlv.failed is False + assert dlv.undeliverable is False assert dlv.annotations is None @@ -2266,8 +2271,8 @@ class ReceivedValue: assert dlv.section_number == self.section_number, (dlv.section_number, self.section_number) assert dlv.section_offset == self.section_offset assert dlv.condition is None - assert dlv.failed == False - assert dlv.undeliverable == False + assert dlv.failed is False + assert dlv.undeliverable is False assert dlv.annotations is None @@ -2304,8 +2309,8 @@ class CustomValue: assert dlv.section_number == 0 assert dlv.section_offset == 0 assert dlv.condition is None - assert dlv.failed == False - assert dlv.undeliverable == False + assert dlv.failed is False + assert dlv.undeliverable is False assert dlv.annotations is None @@ -2749,7 +2754,7 @@ class IdleTimeoutEventTest(PeerTest): assert self.transport.pending() < 0 def testTimeoutWithZombieServerAndSASL(self): - sasl = self.transport.sasl() + self.transport.sasl() self.testTimeoutWithZombieServer(expectOpenCloseFrames=False) @@ -2765,7 +2770,7 @@ class DeliverySegFaultTest(Test): del dlv t.bind(conn) t.unbind() - dlv = snd.delivery("tag") + snd.delivery("tag") class SaslEventTest(CollectorTest): @@ -2782,9 +2787,9 @@ class SaslEventTest(CollectorTest): b'AMQP\x00\x01\x00\x00') self.expect(Event.TRANSPORT) for i in range(1024): - p = transport.pending() + transport.pending() self.drain() - p = transport.pending() + transport.pending() self.expect() def testPipelinedServerReadFirst(self): @@ -2823,7 +2828,7 @@ class SaslEventTest(CollectorTest): s.allowed_mechs("ANONYMOUS") transport.bind(conn) p = transport.pending() - bytes = transport.peek(p) + # bytes = transport.peek(p) transport.pop(p) self.expect(Event.CONNECTION_INIT, Event.CONNECTION_BOUND) transport.push( @@ -2838,7 +2843,7 @@ class SaslEventTest(CollectorTest): ) self.expect(Event.TRANSPORT) p = transport.pending() - bytes = transport.peek(p) + # bytes = transport.peek(p) transport.pop(p) assert s.outcome == SASL.OK # XXX: the bytes above appear to be correct, but we don't get any diff --git a/python/tests/proton_tests/handler.py b/python/tests/proton_tests/handler.py index 5035693e7..2eb04aa37 100644 --- a/python/tests/proton_tests/handler.py +++ b/python/tests/proton_tests/handler.py @@ -17,11 +17,9 @@ # under the License. # -import os -import gc import traceback -from proton import * +from proton import EventType, Handler from proton.reactor import Container from . import common diff --git a/python/tests/proton_tests/interop.py b/python/tests/proton_tests/interop.py index e69fb8ee5..97eb17e5a 100644 --- a/python/tests/proton_tests/interop.py +++ b/python/tests/proton_tests/interop.py @@ -19,7 +19,7 @@ import os -from proton import * +from proton import Array, Data, Described, Message, UNDESCRIBED from . import common diff --git a/python/tests/proton_tests/main.py b/python/tests/proton_tests/main.py index 1bf6823fd..15a0effa7 100644 --- a/python/tests/proton_tests/main.py +++ b/python/tests/proton_tests/main.py @@ -74,15 +74,16 @@ parser.add_option("-D", "--define", metavar="DEFINE", dest="defines", parser.add_option("-x", "--xml", metavar="XML", dest="xml", help="write test results in Junit style xml suitable for use by CI tools etc") parser.add_option("-a", "--always-colorize", action="store_true", dest="always_colorize", default=False, - help="always colorize the test results rather than relying on terminal tty detection. Useful when invoked from Jython/Maven.") + help="always colorize the test results rather than relying on terminal tty detection. " + "Useful when invoked from Jython/Maven.") parser.add_option("-n", metavar="count", dest="count", type=int, default=1, help="run the tests <count> times") parser.add_option("-b", "--bare", action="store_true", default=False, - help="Run bare, i.e. don't capture stack traces. This is useful under Jython as " + - "captured stack traces do not include the Java portion of the stack," + + help="Run bare, i.e. don't capture stack traces. This is useful under Jython as " + "captured stack traces do not include the Java portion of the stack," "whereas non captured stack traces do.") parser.add_option("-j", "--javatrace", action="store_true", default=False, - help="Show the full java stack trace. This disables heuristics to eliminate the " + + help="Show the full java stack trace. This disables heuristics to eliminate the " "jython portion of java stack traces.") @@ -389,7 +390,7 @@ class Runner: phase() except KeyboardInterrupt: raise - except: + except BaseException: self.exception_phase_name = phase_name self.exception = sys.exc_info() exception_type = self.exception[0] @@ -580,7 +581,7 @@ class PatternMatcher: class FunctionScanner(PatternMatcher): def inspect(self, obj): - return type(obj) == types.FunctionType and self.matches(obj.__name__) + return type(obj) is types.FunctionType and self.matches(obj.__name__) def descend(self, func): # the None is required for older versions of python @@ -611,7 +612,7 @@ class ClassScanner(PatternMatcher): class ModuleScanner: def inspect(self, obj): - return type(obj) == types.ModuleType + return type(obj) is types.ModuleType def descend(self, obj): for name in sorted(dir(obj)): @@ -745,6 +746,6 @@ def main(): continue if failures: - return(1) + return 1 else: - return(0) + return 0 diff --git a/python/tests/proton_tests/message.py b/python/tests/proton_tests/message.py index d57d6e34d..5876da0d7 100644 --- a/python/tests/proton_tests/message.py +++ b/python/tests/proton_tests/message.py @@ -20,7 +20,8 @@ from uuid import uuid4 from sys import version_info -from proton import * +from proton import Data, Message, MessageException, byte, char, decimal32, decimal64, decimal128, float32, int32, \ + short, symbol, timestamp, ubyte, uint, ulong, ushort from . import common @@ -304,14 +305,16 @@ class CodecTest(Test): def testDefaultCreationExpiryDecode(self): # This is a message with everything filled explicitly as null or zero in LIST32 HEADER and PROPERTIES lists - data = b'\x00\x53\x70\xd0\x00\x00\x00\x0a\x00\x00\x00\x05\x42\x40\x40\x42\x52\x00\x00\x53\x73\xd0\x00\x00\x00\x12\x00\x00\x00\x0d\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x52\x00\x40' + data = b'\x00\x53\x70\xd0\x00\x00\x00\x0a\x00\x00\x00\x05\x42\x40\x40\x42\x52\x00'\ + b'\x00\x53\x73\xd0\x00\x00\x00\x12\x00\x00\x00\x0d\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x52\x00\x40' msg2 = Message() msg2.decode(data) assert msg2.expiry_time == 0, (msg2.expiry_time) assert msg2.creation_time == 0, (msg2.creation_time) # The same message with LIST8s instead - data = b'\x00\x53\x70\xc0\x07\x05\x42\x40\x40\x42\x52\x00\x00\x53\x73\xc0\x0f\x0d\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x52\x00\x40' + data = b'\x00\x53\x70\xc0\x07\x05\x42\x40\x40\x42\x52\x00'\ + b'\x00\x53\x73\xc0\x0f\x0d\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x52\x00\x40' msg3 = Message() msg3.decode(data) assert msg2.expiry_time == 0, (msg2.expiry_time) @@ -342,13 +345,17 @@ class CodecTest(Test): def testDefaultPriorityDecode(self): # This is a message with everything filled explicitly as null or zero in LIST32 HEADER and PROPERTIES lists - data = b'\x00\x53\x70\xd0\x00\x00\x00\x0a\x00\x00\x00\x05\x42\x40\x40\x42\x52\x00\x00\x53\x73\xd0\x00\x00\x00\x22\x00\x00\x00\x0d\x40\x40\x40\x40\x40\x40\x40\x40\x83\x00\x00\x00\x00\x00\x00\x00\x00\x83\x00\x00\x00\x00\x00\x00\x00\x00\x40\x52\x00\x40' + data = b'\x00\x53\x70\xd0\x00\x00\x00\x0a\x00\x00\x00\x05\x42\x40\x40\x42\x52\x00'\ + b'\x00\x53\x73\xd0\x00\x00\x00\x22\x00\x00\x00\x0d\x40\x40\x40\x40\x40\x40\x40\x40'\ + b'\x83\x00\x00\x00\x00\x00\x00\x00\x00\x83\x00\x00\x00\x00\x00\x00\x00\x00\x40\x52\x00\x40' msg2 = Message() msg2.decode(data) assert msg2.priority == 4, (msg2.priority) # The same message with LIST8s instead - data = b'\x00\x53\x70\xc0\x07\x05\x42\x40\x40\x42\x52\x00\x00\x53\x73\xc0\x1f\x0d\x40\x40\x40\x40\x40\x40\x40\x40\x83\x00\x00\x00\x00\x00\x00\x00\x00\x83\x00\x00\x00\x00\x00\x00\x00\x00\x40\x52\x00\x40' + data = b'\x00\x53\x70\xc0\x07\x05\x42\x40\x40\x42\x52\x00'\ + b'\x00\x53\x73\xc0\x1f\x0d\x40\x40\x40\x40\x40\x40\x40\x40'\ + b'\x83\x00\x00\x00\x00\x00\x00\x00\x00\x83\x00\x00\x00\x00\x00\x00\x00\x00\x40\x52\x00\x40' msg3 = Message() msg3.decode(data) assert msg3.priority == 4, (msg3.priority) diff --git a/python/tests/proton_tests/reactor.py b/python/tests/proton_tests/reactor.py index 7f1d29c62..14f4872bf 100644 --- a/python/tests/proton_tests/reactor.py +++ b/python/tests/proton_tests/reactor.py @@ -167,8 +167,8 @@ class ExceptionTest(Test): def test_link_set(self): c = self.container.connection() s = c.session() - l = s.sender("xxx") - l.handler = BarfOnInit() + sender = s.sender("xxx") + sender.handler = BarfOnInit() try: self.container.run() assert False, "expected to barf" @@ -178,9 +178,9 @@ class ExceptionTest(Test): def test_link_add(self): c = self.container.connection() s = c.session() - l = s.sender("xxx") - l.handler = object() - l.handler.add(BarfOnInit()) + sender = s.sender("xxx") + sender.handler = object() + sender.handler.add(BarfOnInit()) try: self.container.run() assert False, "expected to barf" @@ -497,34 +497,30 @@ class ContainerTest(Test): def test_container_id_1(self): server_handler = ContainerTest._ServerHandler("localhost") container = Container(server_handler, container_id='container123') - conn = container.connect(url="localhost:%s" % (server_handler.port), - handler=ContainerTest._ClientHandler(),) + container.connect(url=f"localhost:{server_handler.port}", handler=ContainerTest._ClientHandler()) container.run() assert server_handler.peer_container_id == 'container123', server_handler.peer_container_id def test_container_id_2(self): server_handler = ContainerTest._ServerHandler("localhost") container = Container(server_handler, container_id='Not_this_id') - conn = container.connect(url="localhost:%s" % (server_handler.port), - handler=ContainerTest._ClientHandler(), - container_id='container456') + container.connect(url=f"localhost:{server_handler.port}", handler=ContainerTest._ClientHandler(), + container_id='container456') container.run() assert server_handler.peer_container_id == 'container456', server_handler.peer_container_id def test_container_id_3(self): server_handler = ContainerTest._ServerHandler("localhost") - container = Container(server_handler, container_id = None) - conn = container.connect(url="localhost:%s" % (server_handler.port), - handler=ContainerTest._ClientHandler()) + container = Container(server_handler, container_id=None) + container.connect(url=f"localhost:{server_handler.port}", handler=ContainerTest._ClientHandler()) container.run() assert server_handler.peer_container_id != '', server_handler.peer_container_id def test_container_id_4(self): server_handler = ContainerTest._ServerHandler("localhost") container = Container(server_handler) - conn = container.connect(url="localhost:%s" % (server_handler.port), - handler=ContainerTest._ClientHandler(), - container_id=None) + container.connect(url=f"localhost:{server_handler.port}", handler=ContainerTest._ClientHandler(), + container_id=None) container.run() assert server_handler.peer_container_id != '', server_handler.peer_container_id @@ -532,9 +528,8 @@ class ContainerTest(Test): ensureCanTestExtendedSASL() server_handler = ContainerTest._ServerHandler("localhost") container = Container(server_handler) - conn = container.connect(url="localhost:%s" % (server_handler.port), - handler=ContainerTest._ClientHandler(), - virtual_host="a.b.c.org") + container.connect(url=f"localhost:{server_handler.port}", handler=ContainerTest._ClientHandler(), + virtual_host="a.b.c.org") container.run() assert server_handler.peer_hostname == "a.b.c.org", server_handler.peer_hostname @@ -544,9 +539,8 @@ class ContainerTest(Test): # Python Container. server_handler = ContainerTest._ServerHandler("localhost") container = Container(server_handler) - conn = container.connect(url="localhost:%s" % (server_handler.port), - handler=ContainerTest._ClientHandler(), - virtual_host="") + container.connect(url=f"localhost:{server_handler.port}", handler=ContainerTest._ClientHandler(), + virtual_host="") container.run() assert server_handler.peer_hostname is None, server_handler.peer_hostname @@ -583,7 +577,7 @@ class ContainerTest(Test): event.connection.close() def on_transport_error(self, event): - assert self.connect_failed == False + assert self.connect_failed is False self.connect_failed = True self.server_handler.listen(event.container) @@ -703,6 +697,7 @@ class ContainerTest(Test): assert server_handler.closed assert client_handler.closed + class SelectorTest(Test): """Test the Selector""" diff --git a/python/tests/proton_tests/sasl.py b/python/tests/proton_tests/sasl.py index 9ea774f10..9125e2004 100644 --- a/python/tests/proton_tests/sasl.py +++ b/python/tests/proton_tests/sasl.py @@ -19,7 +19,7 @@ import os -from proton import * +from proton import Collector, Connection, Endpoint, Event, SASL, SSL, SSLDomain, Transport from . import common from . import engine @@ -64,7 +64,7 @@ def _testSaslMech(self, mech, clientUser='user@proton', authUser='user@proton', assert self.s2.authorization == authzid, self.s2.authorization assert self.s2.mech == mech.strip() assert self.s2.outcome == SASL.OK, self.s2.outcome - assert self.c2.state & Endpoint.LOCAL_ACTIVE and self.c2.state & Endpoint.REMOTE_ACTIVE,\ + assert self.c2.state & Endpoint.LOCAL_ACTIVE and self.c2.state & Endpoint.REMOTE_ACTIVE, \ "local_active=%s, remote_active=%s" % ( self.c1.state & Endpoint.LOCAL_ACTIVE, self.c1.state & Endpoint.REMOTE_ACTIVE) # Client @@ -72,7 +72,7 @@ def _testSaslMech(self, mech, clientUser='user@proton', authUser='user@proton', assert self.s1.user == clientUser assert self.s1.mech == mech.strip() assert self.s1.outcome == SASL.OK, self.s1.outcome - assert self.c1.state & Endpoint.LOCAL_ACTIVE and self.c1.state & Endpoint.REMOTE_ACTIVE,\ + assert self.c1.state & Endpoint.LOCAL_ACTIVE and self.c1.state & Endpoint.REMOTE_ACTIVE, \ "local_active=%s, remote_active=%s" % ( self.c1.state & Endpoint.LOCAL_ACTIVE, self.c1.state & Endpoint.REMOTE_ACTIVE) else: @@ -95,9 +95,9 @@ def consumeAllOuput(t): stops = 0 while stops < 1: out = t.peek(1024) - l = len(out) if out else 0 - t.pop(l) - if l <= 0: + size = len(out) if out else 0 + t.pop(size) + if size <= 0: stops += 1 @@ -276,10 +276,10 @@ class SaslTest(Test): self.pump() assert self.s2.outcome is None assert self.t2.condition is None - assert self.t2.authenticated == False + assert self.t2.authenticated is False assert self.s1.outcome is None assert self.t1.condition is None - assert self.t1.authenticated == False + assert self.t1.authenticated is False def testSaslSkippedFail(self): """Verify that the server (with SASL) correctly handles a client without SASL""" @@ -299,8 +299,8 @@ class SaslTest(Test): self.pump() - assert self.t2.authenticated == False - assert self.t1.authenticated == False + assert self.t2.authenticated is False + assert self.t1.authenticated is False assert self.s1.outcome != SASL.OK assert self.s2.outcome != SASL.OK @@ -378,7 +378,7 @@ class SASLMechTest(Test): def _sslConnection(domain, transport, connection): transport.bind(connection) - ssl = SSL(transport, domain, None) + SSL(transport, domain, None) return connection @@ -412,8 +412,8 @@ class SSLSASLTest(Test): self.client_domain.set_peer_authentication(SSLDomain.ANONYMOUS_PEER) - ssl1 = _sslConnection(self.client_domain, self.t1, self.c1) - ssl2 = _sslConnection(self.server_domain, self.t2, self.c2) + _sslConnection(self.client_domain, self.t1, self.c1) + _sslConnection(self.server_domain, self.t2, self.c2) _testSaslMech(self, mech, encrypted=True) @@ -433,8 +433,8 @@ class SSLSASLTest(Test): self.client_domain.set_peer_authentication(SSLDomain.ANONYMOUS_PEER) - ssl1 = _sslConnection(self.client_domain, self.t1, self.c1) - ssl2 = _sslConnection(self.server_domain, self.t2, self.c2) + _sslConnection(self.client_domain, self.t1, self.c1) + _sslConnection(self.server_domain, self.t2, self.c2) _testSaslMech(self, mech, authzid=authzid, encrypted=True) @@ -452,8 +452,8 @@ class SSLSASLTest(Test): self.client_domain.set_peer_authentication(SSLDomain.ANONYMOUS_PEER) - ssl1 = _sslConnection(self.client_domain, self.t1, self.c1) - ssl2 = _sslConnection(self.server_domain, self.t2, self.c2) + _sslConnection(self.client_domain, self.t1, self.c1) + _sslConnection(self.server_domain, self.t2, self.c2) _testSaslMech(self, mech, clientUser='usr@proton', encrypted=True, authenticated=False) @@ -476,8 +476,8 @@ class SSLSASLTest(Test): self.client_domain.set_trusted_ca_db(_sslCertpath("ca-certificate.pem")) self.client_domain.set_peer_authentication(SSLDomain.VERIFY_PEER) - ssl1 = _sslConnection(self.client_domain, self.t1, self.c1) - ssl2 = _sslConnection(self.server_domain, self.t2, self.c2) + _sslConnection(self.client_domain, self.t1, self.c1) + _sslConnection(self.server_domain, self.t2, self.c2) _testSaslMech(self, mech, clientUser=None, authUser=extUser, encrypted=True) @@ -503,8 +503,8 @@ class SSLSASLTest(Test): self.client_domain.set_trusted_ca_db(_sslCertpath("ca-certificate.pem")) self.client_domain.set_peer_authentication(SSLDomain.VERIFY_PEER) - ssl1 = _sslConnection(self.client_domain, self.t1, self.c1) - ssl2 = _sslConnection(self.server_domain, self.t2, self.c2) + _sslConnection(self.client_domain, self.t1, self.c1) + _sslConnection(self.server_domain, self.t2, self.c2) _testSaslMech(self, mech, clientUser=None, authUser=extUser, authzid=authzid, encrypted=True) @@ -520,8 +520,8 @@ class SSLSASLTest(Test): self.client_domain.set_trusted_ca_db(_sslCertpath("ca-certificate.pem")) self.client_domain.set_peer_authentication(SSLDomain.VERIFY_PEER) - ssl1 = _sslConnection(self.client_domain, self.t1, self.c1) - ssl2 = _sslConnection(self.server_domain, self.t2, self.c2) + _sslConnection(self.client_domain, self.t1, self.c1) + _sslConnection(self.server_domain, self.t2, self.c2) _testSaslMech(self, mech, clientUser=None, authUser=None, encrypted=None, authenticated=False) diff --git a/python/tests/proton_tests/soak.py b/python/tests/proton_tests/soak.py index 25e5f21a9..506cd8752 100644 --- a/python/tests/proton_tests/soak.py +++ b/python/tests/proton_tests/soak.py @@ -92,8 +92,8 @@ class AppTests(Test): for S in self.senders: S.wait() - #print("SENDER OUTPUT:") - #print( S.stdout() ) + # print("SENDER OUTPUT:") + # print( S.stdout() ) assert S.status() == 0, ("Command '%s' failed status=%d: '%s' '%s'" % (str(S.cmdline()), S.status(), @@ -102,8 +102,8 @@ class AppTests(Test): for R in self.receivers: R.wait() - #print("RECEIVER OUTPUT") - #print( R.stdout() ) + # print("RECEIVER OUTPUT") + # print( R.stdout() ) assert R.status() == 0, ("Command '%s' failed status=%d: '%s' '%s'" % (str(R.cmdline()), R.status(), diff --git a/python/tests/proton_tests/ssl.py b/python/tests/proton_tests/ssl.py index c8f497d22..edb5f2cf6 100644 --- a/python/tests/proton_tests/ssl.py +++ b/python/tests/proton_tests/ssl.py @@ -19,7 +19,7 @@ import os -from proton import * +from proton import Connection, Endpoint, SSL, SSLDomain, SSLException, SSLSessionDetails, Transport from . import common from .common import Skipped, pump @@ -264,7 +264,8 @@ class SslTest(common.Test): self.assertEqual("1762688fb3c1c7908690efa158e89924a8e739b6", server.ssl.get_cert_fingerprint_sha1()) self.assertEqual("f5890052d5ad3f38f68eae9027b30fc4c3f09758d59d8f19e3f192e29e41708d", server.ssl.get_cert_fingerprint_sha256()) - self.assertEqual("5d2b1bff39df99d101040348be015970e3da1d0ad610902dc78bba24555aae16395fd1342e26b89b422c304c32b48913000b485933720773d033aaffc561b3e9", + self.assertEqual("5d2b1bff39df99d101040348be015970e3da1d0ad610902dc78bba24555aae16395fd1342e26b89b422c304c32" + "b48913000b485933720773d033aaffc561b3e9", server.ssl.get_cert_fingerprint_sha512()) self.assertEqual("246ea13c8a549e8c0b0cc6490d81b34b", server.ssl.get_cert_fingerprint_md5()) @@ -272,7 +273,8 @@ class SslTest(common.Test): self.assertEqual("d28c0ae17c370c269bd680ea3bcc523ea5da544e", client.ssl.get_cert_fingerprint_sha1()) self.assertEqual("c460a601f77b77ec59480955574a227c309805dd36dbf866f42d2dce3fd4757c", client.ssl.get_cert_fingerprint_sha256()) - self.assertEqual("37c28f451105b1979e2ea62d4a38c86e158ad345894b5016662bdd1913f48764bd71deb4b4de4ce22559828634357dcaea1832dd58327dfe5b0bc368ecbeee4c", + self.assertEqual("37c28f451105b1979e2ea62d4a38c86e158ad345894b5016662bdd1913f48764bd71deb4b4de4ce22559828634" + "357dcaea1832dd58327dfe5b0bc368ecbeee4c", client.ssl.get_cert_fingerprint_sha512()) self.assertEqual("16b075688b82c40ce5b03c984f20286b", client.ssl.get_cert_fingerprint_md5()) @@ -585,11 +587,7 @@ class SslTest(common.Test): server.connection.open() self._pump(client, server) assert server.ssl.protocol_name() is not None - if(API_LANGUAGE == "C"): - assert client.ssl.resume_status() == SSL.RESUME_REUSED - else: - # Java gives no way to check whether a previous session has been resumed - pass + assert client.ssl.resume_status() == SSL.RESUME_REUSED client.connection.close() server.connection.close() @@ -609,8 +607,7 @@ class SslTest(common.Test): server.connection.open() self._pump(client, server) assert server.ssl.protocol_name() is not None - if(API_LANGUAGE == "C"): - assert client.ssl.resume_status() == SSL.RESUME_NEW + assert client.ssl.resume_status() == SSL.RESUME_NEW client.connection.close() server.connection.close() diff --git a/python/tests/proton_tests/transport.py b/python/tests/proton_tests/transport.py index 077d8a4b5..35e6522aa 100644 --- a/python/tests/proton_tests/transport.py +++ b/python/tests/proton_tests/transport.py @@ -19,7 +19,7 @@ import sys -from proton import * +from proton import Connection, Endpoint, Transport, TransportException from . import common @@ -232,7 +232,7 @@ class ServerTransportTest(Test): def testEOS(self): self.transport.push(b"") # should be a noop self.transport.close_tail() - p = self.transport.pending() + self.transport.pending() self.drain() assert self.transport.closed diff --git a/python/tests/proton_tests/utils.py b/python/tests/proton_tests/utils.py index ba3439fc5..4b1e0298b 100644 --- a/python/tests/proton_tests/utils.py +++ b/python/tests/proton_tests/utils.py @@ -149,8 +149,9 @@ class SyncRequestResponseTest(Test): # This will cause an exception because we are specifying allowed_mechs as # EXTERNAL. The SASL handshake will fail because the server is not setup # to handle EXTERNAL - connection = BlockingConnection(server.url, timeout=self.timeout, properties=CONNECTION_PROPERTIES, - offered_capabilities=OFFERED_CAPABILITIES, desired_capabilities=DESIRED_CAPABILITIES, allowed_mechs=EXTERNAL) + BlockingConnection(server.url, timeout=self.timeout, properties=CONNECTION_PROPERTIES, + offered_capabilities=OFFERED_CAPABILITIES, desired_capabilities=DESIRED_CAPABILITIES, + allowed_mechs=EXTERNAL) self.fail("Expected ConnectionException") except ConnectionException as e: self.assertTrue('amqp:unauthorized-access' in str(e), "expected unauthorized-access") @@ -163,7 +164,8 @@ class SyncRequestResponseTest(Test): server.wait() # An ANONYMOUS allowed_mechs will work, anonymous connections are allowed by ConnPropertiesServer connection = BlockingConnection(server.url, timeout=self.timeout, properties=CONNECTION_PROPERTIES, - offered_capabilities=OFFERED_CAPABILITIES, desired_capabilities=DESIRED_CAPABILITIES, allowed_mechs=ANONYMOUS) + offered_capabilities=OFFERED_CAPABILITIES, + desired_capabilities=DESIRED_CAPABILITIES, allowed_mechs=ANONYMOUS) client = SyncRequestResponse(connection) client.connection.close() server.join(timeout=self.timeout) --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@qpid.apache.org For additional commands, e-mail: commits-h...@qpid.apache.org