Changeset View
Changeset View
Standalone View
Standalone View
swh/lister/gnu/tests/test_tree.py
- This file was added.
# 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 | |||||
import json | |||||
import re | |||||
import pytest | |||||
from swh.lister.gnu.tree import ( | |||||
GNUTree, find_artifacts, check_filename_is_archive | |||||
) | |||||
from swh.lister.gnu.tests import get_response_cb | |||||
def test_tree_json(requests_mock): | |||||
requests_mock.get(re.compile('https://ftp.gnu.org'), body=get_response_cb) | |||||
tree_json = GNUTree('https://ftp.gnu.org/tree.json.gz') | |||||
assert tree_json.projects['https://ftp.gnu.org/gnu/8sync/'] == { | |||||
'name': '8sync', | |||||
'time_modified': '1489817408', | |||||
'url': 'https://ftp.gnu.org/gnu/8sync/' | |||||
} | |||||
assert tree_json.projects['https://ftp.gnu.org/gnu/3dldf/'] == { | |||||
'name': '3dldf', | |||||
'time_modified': '1386961236', | |||||
'url': 'https://ftp.gnu.org/gnu/3dldf/' | |||||
} | |||||
assert tree_json.projects['https://ftp.gnu.org/gnu/a2ps/'] == { | |||||
'name': 'a2ps', | |||||
'time_modified': '1198900505', | |||||
'url': 'https://ftp.gnu.org/gnu/a2ps/' | |||||
} | |||||
assert tree_json.projects['https://ftp.gnu.org/old-gnu/xshogi/'] == { | |||||
'name': 'xshogi', | |||||
'time_modified': '1059822922', | |||||
'url': 'https://ftp.gnu.org/old-gnu/xshogi/' | |||||
} | |||||
assert tree_json.artifacts['https://ftp.gnu.org/old-gnu/zlibc/'] == [ | |||||
{ | |||||
'archive': 'https://ftp.gnu.org/old-gnu/zlibc/zlibc-0.9b.tar.gz', # noqa | |||||
'length': 90106, | |||||
'time': 857980800 | |||||
}, | |||||
{ | |||||
'archive': 'https://ftp.gnu.org/old-gnu/zlibc/zlibc-0.9e.tar.gz', # noqa | |||||
'length': 89625, | |||||
'time': 860396400 | |||||
} | |||||
] | |||||
def test_tree_json_failures(requests_mock): | |||||
requests_mock.get(re.compile('https://unknown'), body=get_response_cb) | |||||
url = 'https://unknown/tree.json.gz' | |||||
tree_json = GNUTree(url) | |||||
with pytest.raises(ValueError, match='Error during query to %s' % url): | |||||
tree_json.artifacts['https://ftp.gnu.org/gnu/3dldf/'] | |||||
with pytest.raises(ValueError, match='Error during query to %s' % url): | |||||
tree_json.projects['https://ftp.gnu.org/old-gnu/xshogi/'] | |||||
def test_find_artifacts_small_sample(): | |||||
expected_tarballs = [ | |||||
{ | |||||
'archive': '/root/artanis/artanis-0.2.1.tar.bz2', | |||||
'time': 1495205979, | |||||
'length': 424081, | |||||
}, | |||||
{ | |||||
'archive': '/root/xboard/winboard/winboard-4_0_0-src.zip', # noqa | |||||
'time': 898422900, | |||||
'length': 1514448 | |||||
}, | |||||
{ | |||||
'archive': '/root/xboard/xboard-3.6.2.tar.gz', # noqa | |||||
'time': 869814000, | |||||
'length': 450164, | |||||
}, | |||||
{ | |||||
'archive': '/root/xboard/xboard-4.0.0.tar.gz', # noqa | |||||
'time': 898422900, | |||||
'length': 514951, | |||||
}, | |||||
] | |||||
file_structure = json.load(open('swh/lister/gnu/tests/tree.min.json')) | |||||
actual_tarballs = find_artifacts(file_structure, '/root/') | |||||
assert actual_tarballs == expected_tarballs | |||||
vlorentz: Shouldn't these files be in `DATADIR`? | |||||
Done Inline ActionsYes, i'm currently trying to finalize and propose a fixture for that in swh-core. ardumont: Yes, i'm currently trying to finalize and propose a fixture for that in swh-core.
I'd like to… | |||||
Done Inline ActionsD2082 defines a "datadir" fixture for that. ardumont: D2082 defines a "datadir" fixture for that. | |||||
def test_find_artifacts(): | |||||
file_structure = json.load(open('swh/lister/gnu/tests/tree.json')) | |||||
actual_tarballs = find_artifacts(file_structure, '/root/') | |||||
assert len(actual_tarballs) == 42 + 3 # tar + zip | |||||
def test_check_filename_is_archive(): | |||||
for ext in ['abc.xy.zip', 'cvb.zip', 'abc.tar.bz2', 'something.tar']: | |||||
assert check_filename_is_archive(ext) is True | |||||
Not Done Inline ActionsFor consistency, either use is True for the true tests (preferred), or not file_extension_check('abc') in the false one. Also add a test for an extension that is not an archive. vlorentz: For consistency, either use `is True` for the true tests (preferred), or `not… | |||||
Not Done Inline Actionsconsistency is still not done vlorentz: consistency is still not done | |||||
for ext in ['abc.tar.gz.sig', 'abc', 'something.zip2', 'foo.tar.']: | |||||
assert not check_filename_is_archive(ext) |
Shouldn't these files be in DATADIR?