Page MenuHomeSoftware Heritage

api.classes: Open swh.core.api.classes.stream_results
ClosedPublic

Authored by ardumont on Fri, Jul 31, 12:58 PM.

Details

Summary

This avoids duplication which is growing (right now storage and search proposes
the same pattern in different functions).

Related to T645

Test Plan

tox

Diff Detail

Repository
rDCORE Foundations and core functionalities
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

ardumont created this revision.Fri, Jul 31, 12:58 PM

Build is green

Patch application report for D3664 (id=12898)

Rebasing onto d639fa9f97...

Current branch diff-target is up to date.
Changes applied before test
commit cd5fab9366b4f5913e44f58e7ec451b985c2fb07
Author: Antoine R. Dumont (@ardumont) <ardumont@softwareheritage.org>
Date:   Fri Jul 31 12:58:30 2020 +0200

    api.classes: Open swh.core.api.classes.stream_results
    
    This avoids duplication which is growing (right now storage and search proposes
    the same pattern in different functions).
    
    Related to T645

See https://jenkins.softwareheritage.org/job/DCORE/job/tests-on-diff/33/ for more details.

vlorentz accepted this revision.Fri, Jul 31, 1:05 PM
vlorentz added a subscriber: vlorentz.

Great, thanks.

Could you also add a test for when page_result.results is empty?

swh/core/api/tests/test_classes.py
28

split here into two tests

This revision is now accepted and ready to land.Fri, Jul 31, 1:05 PM
vlorentz added inline comments.Fri, Jul 31, 1:06 PM
swh/core/api/classes.py
30

add let's add some typing:

def stream_results(f: Callable[[...], PageResult[TResult, TToken], *args, **kwargs) -> Iterable[TResult]`
ardumont added inline comments.Fri, Jul 31, 1:25 PM
swh/core/api/classes.py
30

yeah, was going to do it after lunch break
thanks.

ardumont updated this revision to Diff 12904.Fri, Jul 31, 1:25 PM

Adapt according to review:

  • Add type to new function
  • Split tests
  • Add new test for empty result
vlorentz added inline comments.Fri, Jul 31, 1:26 PM
swh/core/api/classes.py
37

nitpick: should be ArgumentError, actually.

vlorentz accepted this revision.Fri, Jul 31, 1:27 PM
vlorentz added inline comments.
swh/core/api/classes.py
37

uh, actually no, nvm

Build is green

Patch application report for D3664 (id=12904)

Rebasing onto d639fa9f97...

Current branch diff-target is up to date.
Changes applied before test
commit 6d49f04a6b84d365799d00f85fc4ab2aa15b6537
Author: Antoine R. Dumont (@ardumont) <ardumont@softwareheritage.org>
Date:   Fri Jul 31 12:58:30 2020 +0200

    api.classes: Open swh.core.api.classes.stream_results
    
    This avoids duplication which is growing (right now storage and search proposes
    the same pattern in different functions).
    
    Related to T645

See https://jenkins.softwareheritage.org/job/DCORE/job/tests-on-diff/34/ for more details.