Skip to content

Commit

Permalink
lower max-line-length to 117 (celery#6282)
Browse files Browse the repository at this point in the history
* flake8: lower max-line-length to 128

* flake8: lower max-line-length to 125

* flake8: lower max-line-length to 124

* flake8: lower max-line-length to 124

* flake8: lower max-line-length to 117
  • Loading branch information
graingert committed Aug 3, 2020
1 parent 11f0732 commit 1b32dd6
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 63 deletions.
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ all_files = 1
[flake8]
# classes can be lowercase, arguments and variables can be uppercase
# whenever it makes the code more readable.
max-line-length = 143
max-line-length = 117
extend-ignore =
D102, # Missing docstring in public method
D104, # Missing docstring in public package
Expand Down
21 changes: 18 additions & 3 deletions t/unit/backends/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1068,7 +1068,12 @@ def test_store_result_never_retries(self):
b._sleep = Mock()
b._get_task_meta_for = Mock()
b._get_task_meta_for.return_value = {
'status': states.RETRY, 'result': {"exc_type": "Exception", "exc_message": ["failed"], "exc_module": "builtins"}
'status': states.RETRY,
'result': {
"exc_type": "Exception",
"exc_message": ["failed"],
"exc_module": "builtins",
},
}
b._store_result = Mock()
b._store_result.side_effect = [
Expand All @@ -1092,7 +1097,12 @@ def test_store_result_with_retries(self):
b._sleep = Mock()
b._get_task_meta_for = Mock()
b._get_task_meta_for.return_value = {
'status': states.RETRY, 'result': {"exc_type": "Exception", "exc_message": ["failed"], "exc_module": "builtins"}
'status': states.RETRY,
'result': {
"exc_type": "Exception",
"exc_message": ["failed"],
"exc_module": "builtins",
},
}
b._store_result = Mock()
b._store_result.side_effect = [
Expand All @@ -1115,7 +1125,12 @@ def test_store_result_reaching_max_retries(self):
b._sleep = Mock()
b._get_task_meta_for = Mock()
b._get_task_meta_for.return_value = {
'status': states.RETRY, 'result': {"exc_type": "Exception", "exc_message": ["failed"], "exc_module": "builtins"}
'status': states.RETRY,
'result': {
"exc_type": "Exception",
"exc_message": ["failed"],
"exc_module": "builtins",
},
}
b._store_result = Mock()
b._store_result.side_effect = [
Expand Down
112 changes: 56 additions & 56 deletions t/unit/backends/test_elasticsearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,16 @@
from celery.exceptions import ImproperlyConfigured


_RESULT_RETRY = (
'{"status":"RETRY","result":'
'{"exc_type":"Exception","exc_message":["failed"],"exc_module":"builtins"}}'
)
_RESULT_FAILURE = (
'{"status":"FAILURE","result":'
'{"exc_type":"Exception","exc_message":["failed"],"exc_module":"builtins"}}'
)


@skip.unless_module('elasticsearch')
class test_ElasticsearchBackend:

Expand Down Expand Up @@ -115,9 +125,7 @@ def test_index_conflict(self, datetime_mock):

x._server.get.return_value = {
'found': True,
'_source': {
'result': """{"status":"RETRY","result":{"exc_type":"Exception","exc_message":["failed"],"exc_module":"builtins"}}"""
},
'_source': {"result": _RESULT_RETRY},
'_seq_no': 2,
'_primary_term': 1,
}
Expand Down Expand Up @@ -157,9 +165,7 @@ def test_index_conflict_without_state(self, datetime_mock):

x._server.get.return_value = {
'found': True,
'_source': {
'result': """{"status":"RETRY","result":{"exc_type":"Exception","exc_message":["failed"],"exc_module":"builtins"}}"""
},
'_source': {"result": _RESULT_RETRY},
'_seq_no': 2,
'_primary_term': 1,
}
Expand Down Expand Up @@ -204,9 +210,7 @@ def test_index_conflict_with_ready_state_on_backend_without_state(self, datetime

x._server.get.return_value = {
'found': True,
'_source': {
'result': """{"status":"FAILURE","result":{"exc_type":"Exception","exc_message":["failed"],"exc_module":"builtins"}}"""
},
'_source': {"result": _RESULT_FAILURE},
'_seq_no': 2,
'_primary_term': 1,
}
Expand Down Expand Up @@ -282,9 +286,7 @@ def test_index_conflict_with_existing_ready_state(self, datetime_mock):

x._server.get.return_value = {
'found': True,
'_source': {
'result': """{"status":"FAILURE","result":{"exc_type":"Exception","exc_message":["failed"],"exc_module":"builtins"}}"""
},
'_source': {"result": _RESULT_FAILURE},
'_seq_no': 2,
'_primary_term': 1,
}
Expand Down Expand Up @@ -315,6 +317,33 @@ def test_backend_concurrent_update(self, base_datetime_mock, es_datetime_mock):
base_datetime_mock.utcnow.return_value = expected_done_dt

self.app.conf.result_backend_always_retry, prev = True, self.app.conf.result_backend_always_retry
x_server_get_side_effect = [
{
'found': True,
'_source': {'result': _RESULT_RETRY},
'_seq_no': 2,
'_primary_term': 1,
},
{
'found': True,
'_source': {'result': _RESULT_RETRY},
'_seq_no': 2,
'_primary_term': 1,
},
{
'found': True,
'_source': {'result': _RESULT_FAILURE},
'_seq_no': 3,
'_primary_term': 1,
},
{
'found': True,
'_source': {'result': _RESULT_FAILURE},
'_seq_no': 3,
'_primary_term': 1,
},
]

try:
x = ElasticsearchBackend(app=self.app)

Expand All @@ -326,42 +355,7 @@ def test_backend_concurrent_update(self, base_datetime_mock, es_datetime_mock):
x._sleep = sleep_mock
x._server = Mock()
x._server.index.side_effect = exceptions.ConflictError(409, "concurrent update", {})

x._server.get.side_effect = [
{
'found': True,
'_source': {
'result': """{"status":"RETRY","result":{"exc_type":"Exception","exc_message":["failed"],"exc_module":"builtins"}}"""
},
'_seq_no': 2,
'_primary_term': 1,
},
{
'found': True,
'_source': {
'result': """{"status":"RETRY","result":{"exc_type":"Exception","exc_message":["failed"],"exc_module":"builtins"}}"""
},
'_seq_no': 2,
'_primary_term': 1,
},
{
'found': True,
'_source': {
'result': """{"status":"FAILURE","result":{"exc_type":"Exception","exc_message":["failed"],"exc_module":"builtins"}}"""
},
'_seq_no': 3,
'_primary_term': 1,
},
{
'found': True,
'_source': {
'result': """{"status":"FAILURE","result":{"exc_type":"Exception","exc_message":["failed"],"exc_module":"builtins"}}"""
},
'_seq_no': 3,
'_primary_term': 1,
},
]

x._server.get.side_effect = x_server_get_side_effect
x._server.update.side_effect = [
{'result': 'noop'},
{'result': 'updated'}
Expand Down Expand Up @@ -453,9 +447,7 @@ def test_backend_index_conflicting_document_removed(self, base_datetime_mock, es
x._server.get.side_effect = [
{
'found': True,
'_source': {
'result': """{"status":"RETRY","result":{"exc_type":"Exception","exc_message":["failed"],"exc_module":"builtins"}}"""
},
'_source': {"result": _RESULT_RETRY},
'_seq_no': 2,
'_primary_term': 1,
},
Expand Down Expand Up @@ -526,9 +518,7 @@ def test_backend_index_conflicting_document_removed_not_throwing(self, base_date
x._server.get.side_effect = [
{
'found': True,
'_source': {
'result': """{"status":"RETRY","result":{"exc_type":"Exception","exc_message":["failed"],"exc_module":"builtins"}}"""
},
'_source': {'result': _RESULT_RETRY},
'_seq_no': 2,
'_primary_term': 1,
},
Expand Down Expand Up @@ -768,7 +758,12 @@ def test_encode_exception_as_json(self):
raise Exception("failed")
except Exception as exc:
einfo = ExceptionInfo()
result_meta = x._get_result_meta(x.encode_result(exc, states.FAILURE), states.FAILURE, einfo.traceback, None)
result_meta = x._get_result_meta(
x.encode_result(exc, states.FAILURE),
states.FAILURE,
einfo.traceback,
None,
)
assert x.encode(result_meta) == result_meta
finally:
self.app.conf.elasticsearch_save_meta_as_text = prev
Expand Down Expand Up @@ -810,7 +805,12 @@ def test_decode_encoded_exception_as_json(self):
raise Exception("failed")
except Exception as exc:
einfo = ExceptionInfo()
result_meta = x._get_result_meta(x.encode_result(exc, states.FAILURE), states.FAILURE, einfo.traceback, None)
result_meta = x._get_result_meta(
x.encode_result(exc, states.FAILURE),
states.FAILURE,
einfo.traceback,
None,
)
assert x.decode(x.encode(result_meta)) == result_meta
finally:
self.app.conf.elasticsearch_save_meta_as_text = prev
Expand Down
8 changes: 7 additions & 1 deletion t/unit/tasks/test_chord.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,13 @@ def mul(x, y):

with patch.object(ch, 'run') as run:
ch.apply_async(task_id=sentinel.task_id)
run.assert_called_once_with(group(mul.s(1, 1), mul.s(2, 2)), mul.s(), (), task_id=sentinel.task_id, interval=10)
run.assert_called_once_with(
group(mul.s(1, 1), mul.s(2, 2)),
mul.s(),
(),
task_id=sentinel.task_id,
interval=10,
)


class test_chord(ChordCase):
Expand Down
5 changes: 3 additions & 2 deletions t/unit/utils/test_time.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,9 @@ def test_remaining():

"""
Case 3: DST check
Suppose start (which is last_run_time) is in EST while next_run is in EDT, then
check whether the `next_run` is actually the time specified in the start (i.e. there is not an hour diff due to DST).
Suppose start (which is last_run_time) is in EST while next_run is in EDT,
then check whether the `next_run` is actually the time specified in the
start (i.e. there is not an hour diff due to DST).
In 2019, DST starts on March 10
"""
start = eastern_tz.localize(datetime(month=3, day=9, year=2019, hour=10, minute=0)) # EST
Expand Down

0 comments on commit 1b32dd6

Please sign in to comment.