Details
Diff Detail
- Repository
- rDSTO Storage manager
- Branch
- iter_origins
- Lint
No Linters Available - Unit
No Unit Test Coverage - Build Status
Buildable 4450 Build 5890: tox-on-jenkins Jenkins Build 5889: arc lint + arc unit
Event Timeline
Build is green
See https://jenkins.softwareheritage.org/job/DSTO/job/tox/204/ for more details.
Build is green
See https://jenkins.softwareheritage.org/job/DSTO/job/tox/207/ for more details.
@anlambert recently added a list origins method to the Web API. I'm pinging him here to make sure there is no overlap and/or that there is code to be reused/refactored related to this proposed change.
Build is green
See https://jenkins.softwareheritage.org/job/DSTO/job/tox/208/ for more details.
The logic looks fine, I'm just having a hard time with some sylistic issues that give me a hard time reading the code.
As a point of reference, black on the test file gives:
# Copyright (C) 2019 The Software Heritage developers # See the AUTHORS file at the top-level directory of this distribution # License: GNU General Public License version 3, or any later version # See top-level LICENSE file for more information from unittest.mock import patch from swh.storage.in_memory import Storage from swh.storage.algos.origin import iter_origins def test_iter_origins(): storage = Storage() origins = storage.origin_add( [ {"type": "foo", "url": "bar"}, {"type": "baz", "url": "qux"}, {"type": "quux", "url": "quuz"}, ] ) assert list(iter_origins(storage)) == origins assert list(iter_origins(storage, batch_size=1)) == origins assert list(iter_origins(storage, batch_size=2)) == origins for i in range(1, 5): assert list(iter_origins(storage, origin_from=i + 1)) == origins[i:], i assert ( list(iter_origins(storage, origin_from=i + 1, batch_size=1)) == origins[i:] ), i assert ( list(iter_origins(storage, origin_from=i + 1, batch_size=2)) == origins[i:] ), i for j in range(i, 5): assert ( list(iter_origins(storage, origin_from=i + 1, origin_to=j + 1)) == origins[i:j] ), (i, j) assert ( list( iter_origins( storage, origin_from=i + 1, origin_to=j + 1, batch_size=1 ) ) == origins[i:j] ), (i, j) assert ( list( iter_origins( storage, origin_from=i + 1, origin_to=j + 1, batch_size=2 ) ) == origins[i:j] ), (i, j) @patch("swh.storage.in_memory.Storage.origin_get_range") def test_iter_origins_batch_size(mock_origin_get_range): storage = Storage() mock_origin_get_range.return_value = [] list(iter_origins(storage)) mock_origin_get_range.assert_called_with(origin_from=1, origin_count=10000) list(iter_origins(storage, batch_size=42)) mock_origin_get_range.assert_called_with(origin_from=1, origin_count=42)
Which feels slightly more verbose but is easier to read for me.
swh/storage/algos/origin.py | ||
---|---|---|
23 | Please add spaces around the - operator (I'm surprised flake8 didn't complain) | |
30 | Same here. | |
swh/storage/tests/algos/test_origin.py | ||
19–24 | do we really need these line breaks? | |
26–44 | Phew, the pytest style of assert foo == bar, "message" really, really messes with my brain. The line wrapping is not helping at all. There's two things here:
Do we really need such non-explicit comments in the assert statements? |
swh/storage/tests/algos/test_origin.py | ||
---|---|---|
26–44 |
I don't like them either.
If the test fail, one needs to print that at some point to understand the failure. |
Build is green
See https://jenkins.softwareheritage.org/job/DSTO/job/tox/210/ for more details.
Apart the tests that should be rewritten using unittest.TestCase, looks good to me.
swh/storage/tests/algos/test_origin.py | ||
---|---|---|
26–44 | I am not a big fan either of the pytest assert style. |
swh/storage/tests/algos/test_origin.py | ||
---|---|---|
26–44 | pytest fixtures are not usable for tests based on unittest.TestCase, so we have to use pytest-style functions for these. For consistency, we're writing all new tests with this style. |
swh/storage/tests/algos/test_origin.py | ||
---|---|---|
26–44 | Not really convinced here as no unusable pytest fixtures are used in swh-storage tests. Anyway, that's just a code style issue so that's not really important. |
Build has FAILED
Link to build: https://jenkins.softwareheritage.org/job/DSTO/job/tox/211/
See console output for more information: https://jenkins.softwareheritage.org/job/DSTO/job/tox/211/console