diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index 70d8f519..18966419 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -33,7 +33,7 @@ jobs: # stop the build if there are Python syntax errors or undefined names flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide - flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics + flake8 . --count --exit-zero --max-complexity=15 --statistics - name: Test with pytest run: | pytest diff --git a/ably/util/crypto.py b/ably/util/crypto.py index 1f428a89..df2d0072 100644 --- a/ably/util/crypto.py +++ b/ably/util/crypto.py @@ -171,4 +171,6 @@ def validate_cipher_params(cipher_params): key_length = cipher_params.key_length if key_length == 128 or key_length == 256: return - raise ValueError('Unsupported key length ' + str(key_length) + ' for aes-cbc encryption. Encryption key must be 128 or 256 bits (16 or 32 ASCII characters)') + raise ValueError( + 'Unsupported key length %s for aes-cbc encryption. Encryption key must be 128 or 256 bits' + ' (16 or 32 ASCII characters)' % key_length) diff --git a/setup.cfg b/setup.cfg index b2a36bfa..d95ce934 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,7 +1,9 @@ [coverage:run] branch=True + [flake8] -max-line-length = 120 -ignore = E114,E121,E123,E126,E127,E128,E241,E226,E231,E251,E302,E305,E306,E402,E501,F401,F821,F841,I100,I101,I201,N802,W291,W293,W391,W503,W504 +max-line-length = 115 +ignore = E114,E121,E123,E126,E127,E128,E241,E226,E231,E251,E302,E305,E306,E402,F401,F821,F841,I100,I101,I201,N802,W291,W293,W391,W503,W504 + [tool:pytest] #log_level = DEBUG diff --git a/test/ably/restcrypto_test.py b/test/ably/restcrypto_test.py index 2aff5803..63657674 100644 --- a/test/ably/restcrypto_test.py +++ b/test/ably/restcrypto_test.py @@ -74,10 +74,17 @@ def test_crypto_publish(self): message_contents = dict((m.name, m.data) for m in messages) log.debug("message_contents: %s" % str(message_contents)) - assert "This is a string message payload" == message_contents["publish3"], "Expect publish3 to be expected String)" - assert b"This is a byte[] message payload" == message_contents["publish4"], "Expect publish4 to be expected byte[]. Actual: %s" % str(message_contents['publish4']) - assert {"test": "This is a JSONObject message payload"} == message_contents["publish5"], "Expect publish5 to be expected JSONObject" - assert ["This is a JSONArray message payload"] == message_contents["publish6"], "Expect publish6 to be expected JSONObject" + assert "This is a string message payload" == message_contents["publish3"],\ + "Expect publish3 to be expected String)" + + assert b"This is a byte[] message payload" == message_contents["publish4"],\ + "Expect publish4 to be expected byte[]. Actual: %s" % str(message_contents['publish4']) + + assert {"test": "This is a JSONObject message payload"} == message_contents["publish5"],\ + "Expect publish5 to be expected JSONObject" + + assert ["This is a JSONArray message payload"] == message_contents["publish6"],\ + "Expect publish6 to be expected JSONObject" def test_crypto_publish_256(self): rndfile = Random.new() @@ -100,10 +107,17 @@ def test_crypto_publish_256(self): message_contents = dict((m.name, m.data) for m in messages) log.debug("message_contents: %s" % str(message_contents)) - assert "This is a string message payload" == message_contents["publish3"], "Expect publish3 to be expected String)" - assert b"This is a byte[] message payload" == message_contents["publish4"], "Expect publish4 to be expected byte[]. Actual: %s" % str(message_contents['publish4']) - assert {"test": "This is a JSONObject message payload"} == message_contents["publish5"], "Expect publish5 to be expected JSONObject" - assert ["This is a JSONArray message payload"] == message_contents["publish6"], "Expect publish6 to be expected JSONObject" + assert "This is a string message payload" == message_contents["publish3"],\ + "Expect publish3 to be expected String)" + + assert b"This is a byte[] message payload" == message_contents["publish4"],\ + "Expect publish4 to be expected byte[]. Actual: %s" % str(message_contents['publish4']) + + assert {"test": "This is a JSONObject message payload"} == message_contents["publish5"],\ + "Expect publish5 to be expected JSONObject" + + assert ["This is a JSONArray message payload"] == message_contents["publish6"],\ + "Expect publish6 to be expected JSONObject" def test_crypto_publish_key_mismatch(self): channel_name = self.get_channel_name('persisted:crypto_publish_key_mismatch') @@ -146,10 +160,17 @@ def test_crypto_send_unencrypted(self): message_contents = dict((m.name, m.data) for m in messages) log.debug("message_contents: %s" % str(message_contents)) - assert "This is a string message payload" == message_contents["publish3"], "Expect publish3 to be expected String)" - assert b"This is a byte[] message payload" == message_contents["publish4"], "Expect publish4 to be expected byte[]. Actual: %s" % str(message_contents['publish4']) - assert {"test": "This is a JSONObject message payload"} == message_contents["publish5"], "Expect publish5 to be expected JSONObject" - assert ["This is a JSONArray message payload"] == message_contents["publish6"], "Expect publish6 to be expected JSONObject" + assert "This is a string message payload" == message_contents["publish3"],\ + "Expect publish3 to be expected String" + + assert b"This is a byte[] message payload" == message_contents["publish4"],\ + "Expect publish4 to be expected byte[]. Actual: %s" % str(message_contents['publish4']) + + assert {"test": "This is a JSONObject message payload"} == message_contents["publish5"],\ + "Expect publish5 to be expected JSONObject" + + assert ["This is a JSONArray message payload"] == message_contents["publish6"],\ + "Expect publish6 to be expected JSONObject" def test_crypto_encrypted_unhandled(self): channel_name = self.get_channel_name('persisted:crypto_send_encrypted_unhandled') diff --git a/test/ably/restinit_test.py b/test/ably/restinit_test.py index 6d61dc43..eccc09c0 100644 --- a/test/ably/restinit_test.py +++ b/test/ably/restinit_test.py @@ -123,17 +123,20 @@ def test_specified_realtime_host(self): @dont_vary_protocol def test_specified_port(self): ably = AblyRest(token='foo', port=9998, tls_port=9999) - assert 9999 == Defaults.get_port(ably.options), "Unexpected port mismatch. Expected: 9999. Actual: %d" % ably.options.tls_port + assert 9999 == Defaults.get_port(ably.options),\ + "Unexpected port mismatch. Expected: 9999. Actual: %d" % ably.options.tls_port @dont_vary_protocol def test_specified_non_tls_port(self): ably = AblyRest(token='foo', port=9998, tls=False) - assert 9998 == Defaults.get_port(ably.options), "Unexpected port mismatch. Expected: 9999. Actual: %d" % ably.options.tls_port + assert 9998 == Defaults.get_port(ably.options),\ + "Unexpected port mismatch. Expected: 9999. Actual: %d" % ably.options.tls_port @dont_vary_protocol def test_specified_tls_port(self): ably = AblyRest(token='foo', tls_port=9999, tls=True) - assert 9999 == Defaults.get_port(ably.options), "Unexpected port mismatch. Expected: 9999. Actual: %d" % ably.options.tls_port + assert 9999 == Defaults.get_port(ably.options),\ + "Unexpected port mismatch. Expected: 9999. Actual: %d" % ably.options.tls_port @dont_vary_protocol def test_tls_defaults_to_true(self): diff --git a/test/ably/utils.py b/test/ably/utils.py index f72b8e46..4677b0a5 100644 --- a/test/ably/utils.py +++ b/test/ably/utils.py @@ -62,7 +62,10 @@ def test_decorated(self, *args, **kwargs): patcher = patch() fn(self, *args, **kwargs) unpatch(patcher) - assert len(responses) >= 1, "If your test doesn't make any requests, use the @dont_vary_protocol decorator" + + assert len(responses) >= 1,\ + "If your test doesn't make any requests, use the @dont_vary_protocol decorator" + for response in responses: if protocol == 'json': assert response.headers['content-type'] == 'application/json'