Changeset View
Standalone View
swh/loader/package/opam/tests/test_opam.py
- This file was added.
# Copyright (C) 2019-2021 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 shutil import rmtree | ||||||||||||
from swh.loader.package.opam.loader import OpamLoader, OpamPackageInfo | ||||||||||||
from swh.loader.tests import assert_last_visit_matches, check_snapshot | ||||||||||||
from swh.model.hashutil import hash_to_bytes | ||||||||||||
from swh.model.model import Person, Snapshot, SnapshotBranch, TargetType | ||||||||||||
def test_opam_loader_one_version(tmpdir, requests_mock_datadir, datadir, swh_storage): | ||||||||||||
opam_url = f"file://{datadir}/fake_opam_repo" | ||||||||||||
opam_root = tmpdir | ||||||||||||
# the directory should NOT exist, we just need an unique name, so we delete it | ||||||||||||
ardumont: why, if i might ask?
Can't we make it accept an already existing directory?
(I'm not sure how… | ||||||||||||
aleoAuthorUnsubmitted Done Inline ActionsBecause otherwise it looks like the opam root is already initialised, which is not the case. If the directory exists, I suppose that it is already initialised and thus that I don't have to initialize it. I do this because initializing an opam root is a little bit slow. aleo: Because otherwise it looks like the opam root is already initialised, which is not the case. If… | ||||||||||||
ardumontUnsubmitted Not Done Inline Actionsthanks. So, at the moment, for real condition using the same opamroot, one lister could run and initialize that state then other workers could reuse said state, right? (I'm trying to make sense on how to actually make the opam lister and loader run in their current implementation) ardumont: thanks.
So, at the moment, for real condition using the same opamroot, one lister could run… | ||||||||||||
aleoAuthorUnsubmitted Done Inline ActionsYes, it's fine to have the lister and the loader to run on the same node or on different nodes. aleo: Yes, it's fine to have the lister and the loader to run on the same node or on different nodes. | ||||||||||||
rmtree(tmpdir) | ||||||||||||
opam_instance = "loadertest" | ||||||||||||
Not Done Inline ActionsUse this instead: https://docs.pytest.org/en/6.2.x/tmpdir.html Unlike tempfile.mkdtemp, it cleans up the directory after the test finished (even if it failed) (And it's a (path to a) directory, not a file) vlorentz: Use this instead: https://docs.pytest.org/en/6.2.x/tmpdir.html
Unlike `tempfile.mkdtemp`, it… | ||||||||||||
Done Inline ActionsDone. aleo: Done. | ||||||||||||
opam_package = "agrid" | ||||||||||||
url = f"opam+{opam_url}/packages/{opam_package}" | ||||||||||||
loader = OpamLoader( | ||||||||||||
swh_storage, url, opam_root, opam_instance, opam_url, opam_package | ||||||||||||
) | ||||||||||||
# Run the loader, with a swh-storage instance, on the given URL. | ||||||||||||
# HTTP calls will be mocked by the requests_mock_datadir fixture | ||||||||||||
actual_load_status = loader.load() | ||||||||||||
# Check the loader loaded exactly the snapshot we expected | ||||||||||||
# (when writing your tests for the first time, you cannot know the | ||||||||||||
# snapshot id without running your loader; so let it error and write | ||||||||||||
# down the result here) | ||||||||||||
expected_snapshot_id = hash_to_bytes("4e4bf977312460329d7f769b0be89937c9827efc") | ||||||||||||
assert actual_load_status == { | ||||||||||||
"status": "eventful", | ||||||||||||
"snapshot_id": expected_snapshot_id.hex(), | ||||||||||||
} | ||||||||||||
target = b"S\x8c\x8aq\xdcy\xa4/0\xa0\xb2j\xeb\xc1\x16\xad\xce\x06\xeaV" | ||||||||||||
# Check the content of the snapshot. (ditto) | ||||||||||||
expected_snapshot = Snapshot( | ||||||||||||
id=expected_snapshot_id, | ||||||||||||
branches={ | ||||||||||||
b"HEAD": SnapshotBranch(target=b"agrid.0.1", target_type=TargetType.ALIAS,), | ||||||||||||
b"agrid.0.1": SnapshotBranch( | ||||||||||||
target=target, target_type=TargetType.REVISION, | ||||||||||||
), | ||||||||||||
}, | ||||||||||||
) | ||||||||||||
check_snapshot(expected_snapshot, swh_storage) | ||||||||||||
# Check the visit was properly created with the right type | ||||||||||||
assert_last_visit_matches( | ||||||||||||
swh_storage, url, status="full", type="opam", snapshot=expected_snapshot_id | ||||||||||||
) | ||||||||||||
# Then you could check the directory structure: | ||||||||||||
directory_id = swh_storage.revision_get([target])[0].directory | ||||||||||||
entries = list(swh_storage.directory_ls(directory_id, recursive=True)) | ||||||||||||
assert entries == [ | ||||||||||||
{ | ||||||||||||
"dir_id": b"\x00A.\xe5\xbc`\x1d\xebF.U\xad\xdd\x10\x04qQ\x16x^", | ||||||||||||
"type": "dir", | ||||||||||||
"target": b"\xcaT\xcb\x8e\x15\xd6\xc4\xbdT9\x03\x8d6\xd7\x18\x80w,w\xad", | ||||||||||||
"name": b"agrid-0.1", | ||||||||||||
"perms": 0o40000, | ||||||||||||
"status": None, | ||||||||||||
"sha1": None, | ||||||||||||
Done Inline Actionscan you write expected perms in octal? it's easier to read. You can get the literal like this: print(oct(16384)) 0o40000 vlorentz: can you write expected perms in octal? it's easier to read.
You can get the literal like this… | ||||||||||||
Done Inline ActionsDone. aleo: Done. | ||||||||||||
"sha1_git": None, | ||||||||||||
"sha256": None, | ||||||||||||
"length": None, | ||||||||||||
}, | ||||||||||||
{ | ||||||||||||
"dir_id": b"\xcaT\xcb\x8e\x15\xd6\xc4\xbdT9\x03\x8d6\xd7\x18\x80w,w\xad", | ||||||||||||
"type": "dir", | ||||||||||||
"target": b"\x05_^g\\\x7f\xb2p\xba\xb4\xc3z\x10\x90u\xe7Zj\xcd\xa4", | ||||||||||||
"name": b"agrid-0.1/.github", | ||||||||||||
"perms": 0o40000, | ||||||||||||
"status": None, | ||||||||||||
"sha1": None, | ||||||||||||
"sha1_git": None, | ||||||||||||
"sha256": None, | ||||||||||||
"length": None, | ||||||||||||
}, | ||||||||||||
{ | ||||||||||||
"dir_id": b"\xcaT\xcb\x8e\x15\xd6\xc4\xbdT9\x03\x8d6\xd7\x18\x80w,w\xad", | ||||||||||||
"type": "file", | ||||||||||||
"target": b"p\x8aR\x00x\x14tH5\xae\xb3\xa3\xcf\x84b\xf9\xf9\x05\x1a\x06", | ||||||||||||
"name": b"agrid-0.1/.gitignore", | ||||||||||||
"perms": 0o100644, | ||||||||||||
"status": "visible", | ||||||||||||
"sha1": b"\x9e<M&\x90\xbe\x85\x8d'sI\xc7B\xf9\x02\xf6\xc4\xeb\xff\xe7", | ||||||||||||
"sha1_git": b"p\x8aR\x00x\x14tH5\xae\xb3\xa3\xcf\x84b\xf9\xf9\x05\x1a\x06", | ||||||||||||
"sha256": b"\x19\xa7\x86t\x18^UQ\xc3\xe848a\xd2\xa4\x98=\x9d-\xf7\x05ff" | ||||||||||||
b"\x01\xcev\xd0bO\xfd\tm", | ||||||||||||
"length": 36, | ||||||||||||
}, | ||||||||||||
{ | ||||||||||||
"dir_id": b"\xcaT\xcb\x8e\x15\xd6\xc4\xbdT9\x03\x8d6\xd7\x18\x80w,w\xad", | ||||||||||||
"type": "file", | ||||||||||||
"target": b"If\xc3\x96\x86e\xd5\\\x1bUB\xbe\xee\xd8\xc1z\x92\xc6@m", | ||||||||||||
"name": b"agrid-0.1/.ocamlformat", | ||||||||||||
"perms": 0o100644, | ||||||||||||
"status": "visible", | ||||||||||||
"sha1": b"\x1cI0\xe0\no\xb8\x95X\x1d\xc2\x13T~\xbbN\x87\x97\x88R", | ||||||||||||
"sha1_git": b"If\xc3\x96\x86e\xd5\\\x1bUB\xbe\xee\xd8\xc1z\x92\xc6@m", | ||||||||||||
"sha256": b";\xfe\xac -\xa9\xdb\xcb\x99\x17\xdb\x04\xc8}\xe66\x16e" | ||||||||||||
b"\xc5\xa5\xd3\x07\xe4\xe0EDqj\xe9\xde.\xce", | ||||||||||||
"length": 1452, | ||||||||||||
}, | ||||||||||||
{ | ||||||||||||
"dir_id": b"\xcaT\xcb\x8e\x15\xd6\xc4\xbdT9\x03\x8d6\xd7\x18\x80w,w\xad", | ||||||||||||
"type": "file", | ||||||||||||
"target": b"S\x90R\xa9\xaa%8\x8fWc\x93\xd2T\x08\x98\xbb;\n\xe2`", | ||||||||||||
"name": b"agrid-0.1/CHANGES.md", | ||||||||||||
"perms": 0o100644, | ||||||||||||
"status": "visible", | ||||||||||||
"sha1": b"+0\xbb\x95\x85\x14\t\xd4\xa6\x92\xb0hH\x07\xfc\x04\xf3\x0f\xd6D", | ||||||||||||
"sha1_git": b"S\x90R\xa9\xaa%8\x8fWc\x93\xd2T\x08\x98\xbb;\n\xe2`", | ||||||||||||
"sha256": b"\xaa\x01#\xa0\x88IE`\x06\xe8\xb7~ef\xbb\x0b~\x15\xceQ3\xd0\r" | ||||||||||||
b"\x9b\xf0\xc2\x88?\x12a\xd2%", | ||||||||||||
"length": 38, | ||||||||||||
}, | ||||||||||||
{ | ||||||||||||
"dir_id": b"\xcaT\xcb\x8e\x15\xd6\xc4\xbdT9\x03\x8d6\xd7\x18\x80w,w\xad", | ||||||||||||
"type": "file", | ||||||||||||
"target": b"n\xa0@g/y\x95\xfbm\x85\x05\x19\xdf\x1b\x1aT\x08\xb2C\xa0", | ||||||||||||
"name": b"agrid-0.1/LICENSE.md", | ||||||||||||
"perms": 0o100644, | ||||||||||||
"status": "visible", | ||||||||||||
"sha1": b"\x10\xaa\xf5\x97\xf1w\x83\x83F\xa0\xe7\xb0\x8a1\x07\x98" | ||||||||||||
b"\xa0\xf3\x10:", | ||||||||||||
"sha1_git": b"n\xa0@g/y\x95\xfbm\x85\x05\x19\xdf\x1b\x1aT\x08\xb2C\xa0", | ||||||||||||
"sha256": b"\xf6\xcc\x7f\x13\xe0\xa1l+\x0f\xb5V:\x06iJ\xf0\x9e\xfd\xeb" | ||||||||||||
b"\xd6\x9f\x0e9\xa5\xa6\xe5\xdf.\x91n\xe0X", | ||||||||||||
"length": 771, | ||||||||||||
}, | ||||||||||||
{ | ||||||||||||
"dir_id": b"\xcaT\xcb\x8e\x15\xd6\xc4\xbdT9\x03\x8d6\xd7\x18\x80w,w\xad", | ||||||||||||
"type": "file", | ||||||||||||
"target": b"\x92\xac>\x90\x12\xec\x89w\xa8\x9d\xf6\x96h\x0e4\xa9\xfa(H\x1a", | ||||||||||||
"name": b"agrid-0.1/README.md", | ||||||||||||
"perms": 0o100644, | ||||||||||||
"status": "visible", | ||||||||||||
"sha1": b"\xfb\xa0\x83\xd8\n\xf8\x93\x9c#\xe5\xabEN\xc5\x90\xca\x88ZM\xaf", | ||||||||||||
"sha1_git": b"\x92\xac>\x90\x12\xec\x89w\xa8\x9d\xf6\x96h\x0e4" | ||||||||||||
b"\xa9\xfa(H\x1a", | ||||||||||||
"sha256": b"P\xd6<\xf2\xaa\x17\xe6\xd9e\x9a\xc6:*\x11\xf0\xc7\xd5z" | ||||||||||||
b"\xc8+\xf3\xdaW\xc2\nRe\x8f+m\t\x18", | ||||||||||||
"length": 1578, | ||||||||||||
}, | ||||||||||||
{ | ||||||||||||
"dir_id": b"\xcaT\xcb\x8e\x15\xd6\xc4\xbdT9\x03\x8d6\xd7\x18\x80w,w\xad", | ||||||||||||
"type": "file", | ||||||||||||
"target": b"A\x95ii\x13\xb7\xec\xff\xaf#(\x10\x18\xc8\xe0\xd2*\xc4L\xc8", | ||||||||||||
"name": b"agrid-0.1/agrid.opam", | ||||||||||||
"perms": 0o100644, | ||||||||||||
"status": "visible", | ||||||||||||
"sha1": b"S$\xf6<\xf5S\xb1\xc13\xa6\xe2\xac\x90\xe1\x98WS\x89\xa9\x86", | ||||||||||||
"sha1_git": b"A\x95ii\x13\xb7\xec\xff\xaf#(\x10\x18\xc8\xe0\xd2*\xc4L\xc8", | ||||||||||||
"sha256": b"\xf7\xb3q\xd3\xc93\xbb'\x96\x82\x9e\t\xdf\xa3\xfft)\x8c[" | ||||||||||||
b"\xa3\xe37\x12\xd9\xb3\x9e\xb3\xb0\xe5\xa5\xa2\x1d", | ||||||||||||
"length": 886, | ||||||||||||
}, | ||||||||||||
{ | ||||||||||||
"dir_id": b"\xcaT\xcb\x8e\x15\xd6\xc4\xbdT9\x03\x8d6\xd7\x18\x80w,w\xad", | ||||||||||||
"type": "dir", | ||||||||||||
"target": b"8\x94`\xbbsz\xc9\xe0\x10\x9c\xed\x87\xdc\x0e\xc8\x86" | ||||||||||||
b"\xdd\x14\xadr", | ||||||||||||
"name": b"agrid-0.1/doc", | ||||||||||||
"perms": 0o40000, | ||||||||||||
"status": None, | ||||||||||||
"sha1": None, | ||||||||||||
"sha1_git": None, | ||||||||||||
"sha256": None, | ||||||||||||
"length": None, | ||||||||||||
}, | ||||||||||||
{ | ||||||||||||
"dir_id": b"\xcaT\xcb\x8e\x15\xd6\xc4\xbdT9\x03\x8d6\xd7\x18\x80w,w\xad", | ||||||||||||
"type": "file", | ||||||||||||
"target": b"\x88 \xd0/~<\\\xb7\x90n\xef\x1c+\x01d\x8dksy\xd0", | ||||||||||||
"name": b"agrid-0.1/dune-project", | ||||||||||||
"perms": 0o100644, | ||||||||||||
"status": "visible", | ||||||||||||
"sha1": b"\x16-d\xd8\xa3\x10f!8\x9d\xdcjI\x00u\xe0\xf4+!C", | ||||||||||||
"sha1_git": b"\x88 \xd0/~<\\\xb7\x90n\xef\x1c+\x01d\x8dksy\xd0", | ||||||||||||
"sha256": b"@3\x94\x19ay\x12\xf8(L^\xb2XOBu$?\x02J4\x1b$\x9f\xdbk" | ||||||||||||
b"\x12\xbe\x989\xc0\xfa", | ||||||||||||
"length": 595, | ||||||||||||
}, | ||||||||||||
{ | ||||||||||||
"dir_id": b"\xcaT\xcb\x8e\x15\xd6\xc4\xbdT9\x03\x8d6\xd7\x18\x80w,w\xad", | ||||||||||||
"type": "dir", | ||||||||||||
"target": b"\xf6Uf_g\xabd-Y\xb0\n\xcba?0\xf9\nP\xe0x", | ||||||||||||
"name": b"agrid-0.1/example", | ||||||||||||
"perms": 0o40000, | ||||||||||||
"status": None, | ||||||||||||
"sha1": None, | ||||||||||||
"sha1_git": None, | ||||||||||||
"sha256": None, | ||||||||||||
"length": None, | ||||||||||||
}, | ||||||||||||
{ | ||||||||||||
"dir_id": b"\xcaT\xcb\x8e\x15\xd6\xc4\xbdT9\x03\x8d6\xd7\x18\x80w,w\xad", | ||||||||||||
"type": "dir", | ||||||||||||
"target": b"F\xaf\xff\x91\x97\x82\x94\x1b?\xad\xd2m\xa1|\xdf\xa9y;@\xed", | ||||||||||||
"name": b"agrid-0.1/src", | ||||||||||||
"perms": 0o40000, | ||||||||||||
"status": None, | ||||||||||||
"sha1": None, | ||||||||||||
"sha1_git": None, | ||||||||||||
"sha256": None, | ||||||||||||
"length": None, | ||||||||||||
}, | ||||||||||||
{ | ||||||||||||
"dir_id": b"\xcaT\xcb\x8e\x15\xd6\xc4\xbdT9\x03\x8d6\xd7\x18\x80w,w\xad", | ||||||||||||
"type": "dir", | ||||||||||||
"target": b"\xdd\xcf&\xda\xee\x1d\xc6\x08\\r[h\x99@\xc3\x1a\x061\x95\x86", | ||||||||||||
"name": b"agrid-0.1/test", | ||||||||||||
"perms": 0o40000, | ||||||||||||
"status": None, | ||||||||||||
"sha1": None, | ||||||||||||
"sha1_git": None, | ||||||||||||
"sha256": None, | ||||||||||||
"length": None, | ||||||||||||
}, | ||||||||||||
{ | ||||||||||||
"dir_id": b"\x05_^g\\\x7f\xb2p\xba\xb4\xc3z\x10\x90u\xe7Zj\xcd\xa4", | ||||||||||||
"type": "dir", | ||||||||||||
"target": b"\xbaN\x90\xc4\xe3\x18~\x1e\xe8y_n\x01r}zuf0\xa1", | ||||||||||||
"name": b"agrid-0.1/.github/workflows", | ||||||||||||
"perms": 0o40000, | ||||||||||||
"status": None, | ||||||||||||
"sha1": None, | ||||||||||||
"sha1_git": None, | ||||||||||||
"sha256": None, | ||||||||||||
"length": None, | ||||||||||||
}, | ||||||||||||
{ | ||||||||||||
"dir_id": b"8\x94`\xbbsz\xc9\xe0\x10\x9c\xed\x87\xdc\x0e" | ||||||||||||
b"\xc8\x86\xdd\x14\xadr", | ||||||||||||
"type": "file", | ||||||||||||
"target": b"\xe8\xfb\x96\x12\xe4\xe9\x92\xe3\x80 \xdf\x81" | ||||||||||||
b"^\x13\xabg\x90\xb2,\xd0", | ||||||||||||
"name": b"agrid-0.1/doc/favicon.png", | ||||||||||||
"perms": 0o100644, | ||||||||||||
"status": "visible", | ||||||||||||
"sha1": b"\xfc\x020+X\xf4\t\xe5\xa5\x1d\xfe&\xb3{@\xc2\x07`6\xf0", | ||||||||||||
"sha1_git": b"\xe8\xfb\x96\x12\xe4\xe9\x92\xe3\x80 \xdf\x81" | ||||||||||||
b"^\x13\xabg\x90\xb2,\xd0", | ||||||||||||
"sha256": b"\xbb\x18\xa5,_\xf4\xd2\xf2\x9c:\xa4\xea\xdbr7:\xad\xb0h" | ||||||||||||
b"\x9ay1=\xe6\x99\xec\x82\x97@\xe2'\x08", | ||||||||||||
"length": 37725, | ||||||||||||
}, | ||||||||||||
{ | ||||||||||||
"dir_id": b"8\x94`\xbbsz\xc9\xe0\x10\x9c\xed\x87" | ||||||||||||
b"\xdc\x0e\xc8\x86\xdd\x14\xadr", | ||||||||||||
"type": "file", | ||||||||||||
"target": b"G&\xdc\x1f\xb0\x1d\x89z\x0c\xbd\x1c\x9b\n>n@6\x85\xb0t", | ||||||||||||
"name": b"agrid-0.1/doc/index.html", | ||||||||||||
"perms": 0o100644, | ||||||||||||
"status": "visible", | ||||||||||||
"sha1": b"\xb6dw\x80Z>\x95&x\xf4\x01\xf3z\x17\xeaWg &\xfa", | ||||||||||||
"sha1_git": b"G&\xdc\x1f\xb0\x1d\x89z\x0c\xbd\x1c\x9b\n>n@6\x85\xb0t", | ||||||||||||
"sha256": b"\xe6\xb1a\xc04\x11L\xd39xT\xd3\x98j\x0eM" | ||||||||||||
b"\x11\x1a\x8d\x00\xd5cj\x86\xeb\xd3\xc7\x95k\xb6\xabi", | ||||||||||||
"length": 920, | ||||||||||||
}, | ||||||||||||
{ | ||||||||||||
"dir_id": b"8\x94`\xbbsz\xc9\xe0\x10\x9c\xed\x87" | ||||||||||||
b"\xdc\x0e\xc8\x86\xdd\x14\xadr", | ||||||||||||
"type": "file", | ||||||||||||
"target": b"\xcf\xe3!7\xa1\x13;\\\xc9+=\x90\xcc\xe4\xdfl\xe8gO\xba", | ||||||||||||
"name": b"agrid-0.1/doc/style.css", | ||||||||||||
"perms": 0o100644, | ||||||||||||
"status": "visible", | ||||||||||||
"sha1": b"EF\xba$\xb9\x9d\x1b\xfb\xcc2m\xba\xb66\x13/\x05\x1b\x17\xde", | ||||||||||||
"sha1_git": b"\xcf\xe3!7\xa1\x13;\\\xc9+=\x90\xcc\xe4\xdfl\xe8gO\xba", | ||||||||||||
"sha256": b"\xc0,e\x12\xad\xcb'\xc2W\xb1\x81}S\xc3Q\xf9\xe9]N_d=[" | ||||||||||||
b"\x13\xf1\x16\xa0\x8f\x800U\xeb", | ||||||||||||
"length": 236, | ||||||||||||
}, | ||||||||||||
{ | ||||||||||||
"dir_id": b"\xf6Uf_g\xabd-Y\xb0\n\xcba?0\xf9\nP\xe0x", | ||||||||||||
"type": "file", | ||||||||||||
"target": b"?\x9c\xc8\x14*6\xc5\xe8\xa5'\x1a\xe0}\x88O\x88\x17\xdb(K", | ||||||||||||
"name": b"agrid-0.1/example/dune", | ||||||||||||
"perms": 0o100644, | ||||||||||||
"status": "visible", | ||||||||||||
"sha1": b"\xba]\xf8\xfdP\x80\xbd\xc8[\x1c!\xc62d.\xfa\xf1\x1c\x86\xff", | ||||||||||||
"sha1_git": b"?\x9c\xc8\x14*6\xc5\xe8\xa5'\x1a\xe0}\x88O\x88\x17\xdb(K", | ||||||||||||
"sha256": b"\xad\x17\xd6\x1e?\x0e\xe48\xb2J\x99\xb5\x17\x12\xb4\xd6n" | ||||||||||||
b"\x82\x94f\xcd\xcc\xe2C\x0e\xaa\x9dss\xf3\xcf\x9a", | ||||||||||||
"length": 56, | ||||||||||||
}, | ||||||||||||
{ | ||||||||||||
"dir_id": b"\xf6Uf_g\xabd-Y\xb0\n\xcba?0\xf9\nP\xe0x", | ||||||||||||
"type": "file", | ||||||||||||
"target": b"\x92A\x1f;\xb6\xd8\x10\x96\x06\xc1_\x82\xca" | ||||||||||||
b"\xc3\xd0\x7f\xbe=\xb3\x91", | ||||||||||||
"name": b"agrid-0.1/example/main.ml", | ||||||||||||
"perms": 0o100644, | ||||||||||||
"status": "visible", | ||||||||||||
"sha1": b"\xbc\x0eV\xccb\r\xad\xf2\x83\xd6\x08G\x82'\x16`\xc3;\xe1j", | ||||||||||||
"sha1_git": b"\x92A\x1f;\xb6\xd8\x10\x96\x06\xc1_\x82\xca" | ||||||||||||
b"\xc3\xd0\x7f\xbe=\xb3\x91", | ||||||||||||
"sha256": b"jg\x82\x93-n\x939\nO\xf8\xc1w\x84\xe3\x86:l\x01Z%" | ||||||||||||
b"\xfa?k\xd0\x1c\x1a\x93F\xd8\x9c\xe0", | ||||||||||||
"length": 720, | ||||||||||||
}, | ||||||||||||
{ | ||||||||||||
"dir_id": b"F\xaf\xff\x91\x97\x82\x94\x1b?\xad\xd2m\xa1|\xdf\xa9y;@\xed", | ||||||||||||
"type": "file", | ||||||||||||
"target": b"\x045\x91\xfc\xe6\xc5\xfdD\xc2+\x1e\x13\x06!b\xa2\xb7U\xb6\x02", | ||||||||||||
"name": b"agrid-0.1/src/agrid.ml", | ||||||||||||
"perms": 0o100644, | ||||||||||||
"status": "visible", | ||||||||||||
"sha1": b"\xa7\x11\xaa\xef\xf5\xc4;\xca\xbdo\xe7\xa5\x8f" | ||||||||||||
b"\xf8\xfd\xc6\xe4XN\xd7", | ||||||||||||
"sha1_git": b"\x045\x91\xfc\xe6\xc5\xfdD\xc2+\x1e\x13\x06!b" | ||||||||||||
b"\xa2\xb7U\xb6\x02", | ||||||||||||
"sha256": b"LY\xbf\xe3\x95`)\x167%\xc0L\xfb\xa3>y\xb7\xde\xdd\x85" | ||||||||||||
b"\x90\xc4R$\xfdg\xe4\xdf\x9c\x03.\x0b", | ||||||||||||
"length": 6342, | ||||||||||||
}, | ||||||||||||
{ | ||||||||||||
"dir_id": b"F\xaf\xff\x91\x97\x82\x94\x1b?\xad\xd2m\xa1|\xdf\xa9y;@\xed", | ||||||||||||
"type": "file", | ||||||||||||
"target": b"*\xb5\xa3\x9a)p94\xae\xfd\x7f\xa9\x90y\n\xb3\xcf\xc2W\xa5", | ||||||||||||
"name": b"agrid-0.1/src/dune", | ||||||||||||
"perms": 0o100644, | ||||||||||||
"status": "visible", | ||||||||||||
"sha1": b"\xcb\xa4\x9b\x86\nY)\x9c\x01\x0b\xa2\xb75RJ\xf0\xba\x18\r\xaa", | ||||||||||||
"sha1_git": b"*\xb5\xa3\x9a)p94\xae\xfd\x7f\xa9\x90y\n\xb3\xcf\xc2W\xa5", | ||||||||||||
"sha256": b"D\xb5u\x11I\xd2\xeb\x83\x16\xc8r\xaa\xf5\xf8" | ||||||||||||
b"\x0b\xda'L\x17\xcbK\x9b`\xa7\xe8\x03{\xaf8\x93\xdb\xb3", | ||||||||||||
"length": 114, | ||||||||||||
}, | ||||||||||||
{ | ||||||||||||
"dir_id": b"\xdd\xcf&\xda\xee\x1d\xc6\x08\\r[h\x99@\xc3\x1a\x061\x95\x86", | ||||||||||||
"type": "file", | ||||||||||||
"target": b'\xfd0ZX\xde\xb5\xffL\xf7\x9b\xf2\xf1}\xc1\x1b,"\xdcZ4', | ||||||||||||
"name": b"agrid-0.1/test/dune", | ||||||||||||
"perms": 0o100644, | ||||||||||||
"status": "visible", | ||||||||||||
"sha1": b"\xca\x17\x8f!\xcbQ|\xb2\x8dI\xd0m\x14\xc2\x00y\xbd\xddW\xc7", | ||||||||||||
"sha1_git": b'\xfd0ZX\xde\xb5\xffL\xf7\x9b\xf2\xf1}\xc1\x1b,"\xdcZ4', | ||||||||||||
"sha256": b"3\x13q)J\xbd[~\xf0\xf6\x02\x0e\xb2+\xf0\x96u" | ||||||||||||
b"\xb6y\xfb\xa5\xe3\xb4X\xb9\x9f L\x1d3\xdc?", | ||||||||||||
"length": 39, | ||||||||||||
}, | ||||||||||||
{ | ||||||||||||
"dir_id": b"\xdd\xcf&\xda\xee\x1d\xc6\x08\\r[h\x99@\xc3\x1a\x061\x95\x86", | ||||||||||||
"type": "file", | ||||||||||||
"target": b"\xa2\xb5v\rw\xc1\xe8\xea^v\x9a1\xe0\x03_\x0c6\xd4O\xb1", | ||||||||||||
"name": b"agrid-0.1/test/test.ml", | ||||||||||||
"perms": 0o100644, | ||||||||||||
"status": "visible", | ||||||||||||
"sha1": b"\xf4\\\xb4e\xec:\xd9\x1d\xb4\xb74\x88\x9d\xbes\xfcf\xa0\x8dJ", | ||||||||||||
"sha1_git": b"\xa2\xb5v\rw\xc1\xe8\xea^v\x9a1\xe0\x03_\x0c6\xd4O\xb1", | ||||||||||||
"sha256": b"n<\rl\xa8\xcbG\xdcc\xee\x135\x03\x96\xd5l\xbe#\x00" | ||||||||||||
b"\x11\x8d\xdb\xd7\x84\xdcW\xb9\xcc\xf2\xc3p\xdf", | ||||||||||||
"length": 3957, | ||||||||||||
}, | ||||||||||||
{ | ||||||||||||
"dir_id": b"\xbaN\x90\xc4\xe3\x18~\x1e\xe8y_n\x01r}zuf0\xa1", | ||||||||||||
"type": "file", | ||||||||||||
"target": b"9Fu\xac\xc4A10\xbb\xd5\n3?\x95|\xe6\xc5\xe8F\xf5", | ||||||||||||
"name": b"agrid-0.1/.github/workflows/build.yml", | ||||||||||||
"perms": 0o100644, | ||||||||||||
"status": "visible", | ||||||||||||
"sha1": b"\xb3D\xbb\xf9\x04\xbc\xb3\x82\xb0.H" | ||||||||||||
b"[b\xb8\xd6\xc5\xc1\xe2\x05\x89", | ||||||||||||
"sha1_git": b"9Fu\xac\xc4A10\xbb\xd5\n3?\x95|\xe6\xc5\xe8F\xf5", | ||||||||||||
"sha256": b"y9+~\x172\x00%~\xb6\xc0\xa8\\\x0cxM\x99\x8c\xcd\xca$" | ||||||||||||
b"\xfb\r\xf9\x031\x82.\xe6\xa9\x84\x93", | ||||||||||||
"length": 922, | ||||||||||||
}, | ||||||||||||
{ | ||||||||||||
"dir_id": b"\xbaN\x90\xc4\xe3\x18~\x1e\xe8y_n\x01r}zuf0\xa1", | ||||||||||||
"type": "file", | ||||||||||||
"target": b'\x13\xc8\xeb\x08\xc7\xf8"\xe8\xd6\xfc\xfa\xc2' | ||||||||||||
b"\x8a\x16\xb7\xfc\x82\xbfO4", | ||||||||||||
"name": b"agrid-0.1/.github/workflows/deploy.yml", | ||||||||||||
"perms": 0o100644, | ||||||||||||
"status": "visible", | ||||||||||||
"sha1": b"\xceY\xaeg\x9d\xb2\xc3\x95\x8e\xb9\xd4}\x0f\x05z]i\x8e\xa8m", | ||||||||||||
"sha1_git": b'\x13\xc8\xeb\x08\xc7\xf8"\xe8\xd6\xfc' | ||||||||||||
b"\xfa\xc2\x8a\x16\xb7\xfc\x82\xbfO4", | ||||||||||||
"sha256": b"\xd8\x94\xc9K\xe42\xb1#R\x08\x8f\xb8\xbd\x1f" | ||||||||||||
b"\xe2X\xce\xd84\x12\x90.\x02\xb8~\xc9\xa1\xcf$\xf2\x0f\xcd", | ||||||||||||
"length": 1501, | ||||||||||||
}, | ||||||||||||
] | ||||||||||||
ardumontUnsubmitted Not Done Inline ActionsI understand that to see the loader does indeed ingest, it's good to check that we have Can you please simplify according to [1]? ardumont: I understand that to see the loader does indeed ingest, it's good to check that we have
what's… | ||||||||||||
def test_opam_loader_many_version(tmpdir, requests_mock_datadir, datadir, swh_storage): | ||||||||||||
ardumontUnsubmitted Not Done Inline Actions
ardumont: | ||||||||||||
opam_url = f"file://{datadir}/fake_opam_repo" | ||||||||||||
opam_root = tmpdir | ||||||||||||
# the directory should NOT exist, we just need an unique name, so we delete it | ||||||||||||
rmtree(tmpdir) | ||||||||||||
opam_instance = "loadertest" | ||||||||||||
opam_package = "directories" | ||||||||||||
url = f"opam+{opam_url}/packages/{opam_package}" | ||||||||||||
loader = OpamLoader( | ||||||||||||
swh_storage, url, opam_root, opam_instance, opam_url, opam_package | ||||||||||||
) | ||||||||||||
# Run the loader, with a swh-storage instance, on the given URL. | ||||||||||||
# HTTP calls will be mocked by the requests_mock_datadir fixture | ||||||||||||
actual_load_status = loader.load() | ||||||||||||
# Check the loader loaded exactly the snapshot we expected | ||||||||||||
# (when writing your tests for the first time, you cannot know the | ||||||||||||
# snapshot id without running your loader; so let it error and write | ||||||||||||
# down the result here) | ||||||||||||
ardumontUnsubmitted Not Done Inline Actionsyou can drop those explanatory comments when your iteration of this loader is done btw ;) ardumont: you can drop those explanatory comments when your iteration of this loader is done btw ;) | ||||||||||||
aleoAuthorUnsubmitted Done Inline Actionsdone aleo: done | ||||||||||||
expected_snapshot_id = hash_to_bytes("1b49be175dcf17c0f568bcd7aac3d4faadc41249") | ||||||||||||
assert actual_load_status == { | ||||||||||||
"status": "eventful", | ||||||||||||
"snapshot_id": expected_snapshot_id.hex(), | ||||||||||||
} | ||||||||||||
# Check the content of the snapshot. (ditto) | ||||||||||||
expected_snapshot = Snapshot( | ||||||||||||
id=expected_snapshot_id, | ||||||||||||
branches={ | ||||||||||||
b"HEAD": SnapshotBranch( | ||||||||||||
target=b"directories.0.3", target_type=TargetType.ALIAS, | ||||||||||||
), | ||||||||||||
b"directories.0.1": SnapshotBranch( | ||||||||||||
target=b"N\x92jA\xb2\x892\xeb\xcc\x9c\xa9\xb3\xea\xa7kz\xb08\xa6V", | ||||||||||||
target_type=TargetType.REVISION, | ||||||||||||
), | ||||||||||||
b"directories.0.2": SnapshotBranch( | ||||||||||||
target=b"yj\xc9\x1a\x8f\xe0\xaa\xff[\x88\xffz" | ||||||||||||
b"\x91C\xcc\x96\xb7\xd4\xf65", | ||||||||||||
target_type=TargetType.REVISION, | ||||||||||||
), | ||||||||||||
b"directories.0.3": SnapshotBranch( | ||||||||||||
target=b"hA \xc4\xb5\x18A8\xb8C\x12\xa3\xa5T\xb7/v\x85X\xcb", | ||||||||||||
target_type=TargetType.REVISION, | ||||||||||||
), | ||||||||||||
}, | ||||||||||||
) | ||||||||||||
check_snapshot(expected_snapshot, swh_storage) | ||||||||||||
# Check the visit was properly created with the right type | ||||||||||||
assert_last_visit_matches( | ||||||||||||
swh_storage, url, status="full", type="opam", snapshot=expected_snapshot_id | ||||||||||||
) | ||||||||||||
def test_opam_revision(tmpdir, requests_mock_datadir, swh_storage, datadir): | ||||||||||||
opam_url = f"file://{datadir}/fake_opam_repo" | ||||||||||||
Not Done Inline ActionsI don't think this test tests what we consider metadata; instead it's checking data used to build the revision, without checking the revision itself. Could you rename it, and check the actual revision info? vlorentz: I don't think this test tests what we consider metadata; instead it's checking data used to… | ||||||||||||
opam_root = tmpdir | ||||||||||||
# the directory should NOT exist, we just need an unique name, so we delete it | ||||||||||||
rmtree(tmpdir) | ||||||||||||
opam_instance = "loadertest" | ||||||||||||
opam_package = "ocb" | ||||||||||||
url = f"opam+{opam_url}/packages/{opam_package}" | ||||||||||||
loader = OpamLoader( | ||||||||||||
swh_storage, url, opam_root, opam_instance, opam_url, opam_package | ||||||||||||
) | ||||||||||||
# Run the loader, with a swh-storage instance, on the given URL. | ||||||||||||
# HTTP calls will be mocked by the requests_mock_datadir fixture | ||||||||||||
actual_load_status = loader.load() | ||||||||||||
expected_snapshot_id = hash_to_bytes("398df115b9feb2f463efd21941d69b7d59cd9025") | ||||||||||||
assert actual_load_status == { | ||||||||||||
"status": "eventful", | ||||||||||||
"snapshot_id": expected_snapshot_id.hex(), | ||||||||||||
} | ||||||||||||
info_iter = loader.get_package_info("0.1") | ||||||||||||
branch_name, package_info = next(info_iter) | ||||||||||||
expected_branch_name = "ocb.0.1" | ||||||||||||
print(package_info) | ||||||||||||
ardumontUnsubmitted Done Inline Actionsyou can drop the print statement. ardumont: you can drop the print statement. | ||||||||||||
aleoAuthorUnsubmitted Done Inline Actionsdone aleo: done | ||||||||||||
expected_package_info = OpamPackageInfo( | ||||||||||||
url="https://github.com/OCamlPro/ocb/archive/0.1.tar.gz", | ||||||||||||
filename=None, | ||||||||||||
directory_extrinsic_metadata=[], | ||||||||||||
author=Person( | ||||||||||||
fullname=b"OCamlPro <contact@ocamlpro.com>", name=None, email=None | ||||||||||||
), | ||||||||||||
committer=Person( | ||||||||||||
fullname=b"OCamlPro <contact@ocamlpro.com>", name=None, email=None | ||||||||||||
), | ||||||||||||
version="0.1", | ||||||||||||
) | ||||||||||||
assert branch_name == expected_branch_name | ||||||||||||
assert package_info == expected_package_info | ||||||||||||
revision_id = b"o\xad\x7f=\x07\xbb\xaah\xdbI(\xb0'\x10z\xfc\xff\x06x\x1b" | ||||||||||||
revision = swh_storage.revision_get([revision_id])[0] | ||||||||||||
assert revision is not None | ||||||||||||
assert revision.author == expected_package_info.author | ||||||||||||
assert revision.committer == expected_package_info.committer |
why, if i might ask?
Can't we make it accept an already existing directory?
(I'm not sure how that would actually behave in real life in that current implementation.)