Skip to content

Commit

Permalink
Make flake8 happy
Browse files Browse the repository at this point in the history
- flake8 configuration is already defined in setup.cfg
- Actually test line length (do not ignore E501)
- Increase max complexity to 15
  • Loading branch information
jdavid committed Jan 29, 2021
1 parent ae6a0d4 commit 26d782b
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/check.yml
Expand Up @@ -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
4 changes: 3 additions & 1 deletion ably/util/crypto.py
Expand Up @@ -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)
6 changes: 4 additions & 2 deletions 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
45 changes: 33 additions & 12 deletions test/ably/restcrypto_test.py
Expand Up @@ -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()
Expand All @@ -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')
Expand Down Expand Up @@ -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')
Expand Down
9 changes: 6 additions & 3 deletions test/ably/restinit_test.py
Expand Up @@ -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):
Expand Down
5 changes: 4 additions & 1 deletion test/ably/utils.py
Expand Up @@ -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'
Expand Down

0 comments on commit 26d782b

Please sign in to comment.