Changeset View
Changeset View
Standalone View
Standalone View
swh/lister/conda/tests/test_lister.py
# Copyright (C) 2022 The Software Heritage developers | # Copyright (C) 2022 The Software Heritage developers | ||||
# See the AUTHORS file at the top-level directory of this distribution | # See the AUTHORS file at the top-level directory of this distribution | ||||
# License: GNU General Public License version 3, or any later version | # License: GNU General Public License version 3, or any later version | ||||
# See top-level LICENSE file for more information | # See top-level LICENSE file for more information | ||||
from swh.lister.conda.lister import CondaLister | import pytest | ||||
def test_conda_lister_free_channel(datadir, requests_mock_datadir, swh_scheduler): | |||||
lister = CondaLister( | |||||
scheduler=swh_scheduler, channel="free", archs=["linux-64", "osx-64", "win-64"] | |||||
) | |||||
res = lister.run() | |||||
assert res.pages == 3 | |||||
assert res.origins == 11 | |||||
def test_conda_lister_conda_forge_channel( | |||||
datadir, requests_mock_datadir, swh_scheduler | |||||
): | |||||
lister = CondaLister( | |||||
scheduler=swh_scheduler, | |||||
url="https://conda.anaconda.org", | |||||
channel="conda-forge", | |||||
archs=["linux-64"], | |||||
) | |||||
res = lister.run() | |||||
assert res.pages == 1 | from swh.lister.conda.lister import CondaLister | ||||
assert res.origins == 2 | |||||
scheduler_origins = swh_scheduler.get_listed_origins(lister.lister_obj.id).results | |||||
expected_origins = [ | @pytest.fixture | ||||
def expected_origins(): | |||||
return [ | |||||
{ | { | ||||
"url": "https://anaconda.org/conda-forge/21cmfast", | "url": "https://anaconda.org/conda-forge/21cmfast", | ||||
"artifacts": [ | "artifacts": [ | ||||
{ | { | ||||
"url": "https://conda.anaconda.org/conda-forge/linux-64/21cmfast-3.0.2-py36h1af98f8_1.tar.bz2", # noqa: B950 | "url": "https://conda.anaconda.org/conda-forge/linux-64/21cmfast-3.0.2-py36h1af98f8_1.tar.bz2", # noqa: B950 | ||||
"date": "2020-11-11T16:04:49.658000+00:00", | "date": "2020-11-11T16:04:49.658000+00:00", | ||||
"version": "linux-64/3.0.2-py36h1af98f8_1", | "version": "linux-64/3.0.2-py36h1af98f8_1", | ||||
"filename": "21cmfast-3.0.2-py36h1af98f8_1.tar.bz2", | "filename": "21cmfast-3.0.2-py36h1af98f8_1.tar.bz2", | ||||
Show All 26 Lines | return [ | ||||
"md5": "c53a689a4c5948e84211bdfc23e3fe68", | "md5": "c53a689a4c5948e84211bdfc23e3fe68", | ||||
"sha256": "76146c2ebd6e3b65928bde53a2585287759d77beba785c0eeb889ee565c0035d", # noqa: B950 | "sha256": "76146c2ebd6e3b65928bde53a2585287759d77beba785c0eeb889ee565c0035d", # noqa: B950 | ||||
}, | }, | ||||
}, | }, | ||||
], | ], | ||||
}, | }, | ||||
] | ] | ||||
def test_conda_lister_free_channel(datadir, requests_mock_datadir, swh_scheduler): | |||||
lister = CondaLister( | |||||
scheduler=swh_scheduler, channel="free", archs=["linux-64", "osx-64", "win-64"] | |||||
) | |||||
res = lister.run() | |||||
assert res.pages == 3 | |||||
assert res.origins == 11 | |||||
def test_conda_lister_conda_forge_channel( | |||||
requests_mock_datadir, swh_scheduler, expected_origins | |||||
): | |||||
lister = CondaLister( | |||||
scheduler=swh_scheduler, | |||||
url="https://conda.anaconda.org", | |||||
channel="conda-forge", | |||||
archs=["linux-64"], | |||||
) | |||||
res = lister.run() | |||||
assert res.pages == 1 | |||||
assert res.origins == 2 | |||||
scheduler_origins = swh_scheduler.get_listed_origins(lister.lister_obj.id).results | |||||
assert len(scheduler_origins) == len(expected_origins) | assert len(scheduler_origins) == len(expected_origins) | ||||
assert [ | assert [ | ||||
( | ( | ||||
scheduled.visit_type, | scheduled.visit_type, | ||||
scheduled.url, | scheduled.url, | ||||
scheduled.extra_loader_arguments["artifacts"], | scheduled.extra_loader_arguments["artifacts"], | ||||
) | ) | ||||
for scheduled in sorted(scheduler_origins, key=lambda scheduled: scheduled.url) | for scheduled in sorted(scheduler_origins, key=lambda scheduled: scheduled.url) | ||||
] == [ | ] == [ | ||||
( | ( | ||||
"conda", | "conda", | ||||
expected["url"], | expected["url"], | ||||
expected["artifacts"], | expected["artifacts"], | ||||
) | ) | ||||
for expected in sorted(expected_origins, key=lambda expected: expected["url"]) | for expected in sorted(expected_origins, key=lambda expected: expected["url"]) | ||||
] | ] | ||||
def test_conda_lister_number_of_yielded_origins( | |||||
requests_mock_datadir, swh_scheduler, expected_origins | |||||
): | |||||
"""Check that a single ListedOrigin instance is sent by expected origins.""" | |||||
lister = CondaLister( | |||||
scheduler=swh_scheduler, | |||||
url="https://conda.anaconda.org", | |||||
channel="conda-forge", | |||||
archs=["linux-64"], | |||||
) | |||||
listed_origins = [] | |||||
for page in lister.get_pages(): | |||||
listed_origins += list(lister.get_origins_from_page(page)) | |||||
vlorentz: Please compare the lists contents; the length alone is not very robust, and doesn't give… | |||||
Done Inline ActionsThose are not the same type in the lists so I cannot compare them and the purpose of that test is to check the number of sent origins to the scheduler is not greater that the number of expected origins. The checks of the data sent to scheduler are done in previous tests. anlambert: Those are not the same type in the lists so I cannot compare them and the purpose of that test… | |||||
Done Inline ActionsI will modify the test to check for origin URLs instead. anlambert: I will modify the test to check for origin URLs instead. | |||||
assert sorted([listed_origin.url for listed_origin in listed_origins]) == sorted( | |||||
[origin["url"] for origin in expected_origins] | |||||
) |
Please compare the lists contents; the length alone is not very robust, and doesn't give meaningful messages on failure