Page MenuHomeSoftware Heritage

tests: Fix loader git instantiation
ClosedPublic

Authored by ardumont on Oct 2 2020, 6:05 PM.

Diff Detail

Repository
rDVAU Software Heritage Vault
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

Build is green

Patch application report for D4134 (id=14576)

Rebasing onto b0c50dd168...

Current branch diff-target is up to date.
Changes applied before test
commit 7af35ae919caa67c62c4e48571f18fa06e504631
Author: Antoine R. Dumont (@ardumont) <ardumont@softwareheritage.org>
Date:   Fri Oct 2 18:05:44 2020 +0200

    tests: Fix loader git instantiation
    
    Fixes build [1]
    
    [1] https://jenkins.softwareheritage.org/job/DVAU/job/tests/807/console

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

anlambert added a subscriber: anlambert.

Looks good ! I think we could simplify the git loader creation by making git_loader a pytest fixture. This could be added in a second commit or I can open a diff with my local experiments (see diff extract below)

diff --git a/swh/vault/tests/test_cookers.py b/swh/vault/tests/test_cookers.py
index 42b9243..a86027f 100644
--- a/swh/vault/tests/test_cookers.py
+++ b/swh/vault/tests/test_cookers.py
@@ -129,20 +129,25 @@ def swh_loader_config(swh_loader_config):
     return swh_loader_config
 
 
+@pytest.fixture
 def git_loader(
-    storage,
-    repo_path,
-    visit_date=datetime.datetime.now(datetime.timezone.utc),
-    config=None,
+    swh_storage, swh_loader_config,
 ):
     """Instantiate a Git Loader using the storage instance as storage.
 
     """
-    loader = GitLoaderFromDisk(
-        "fake_origin", directory=repo_path, visit_date=visit_date, config=config
-    )
-    loader.storage = storage
-    return loader
+
+    def _create_loader(directory):
+        loader = GitLoaderFromDisk(
+            "fake_origin",
+            directory=directory,
+            visit_date=datetime.datetime.now(datetime.timezone.utc),
+            config=swh_loader_config,
+        )
+        loader.storage = swh_storage
+        return loader
+
+    return _create_loader
 
 
 @contextlib.contextmanager
@@ -196,7 +201,7 @@ TEST_EXECUTABLE = b"\x42\x40\x00\x00\x05"
 
 
 class TestDirectoryCooker:
-    def test_directory_simple(self, swh_storage, swh_loader_config):
+    def test_directory_simple(self, git_loader):
         repo = TestRepo()
         with repo as rp:
             (rp / "file").write_text(TEST_CONTENT)
@@ -206,13 +211,13 @@ class TestDirectoryCooker:
             (rp / "dir1/dir2").mkdir(parents=True)
             (rp / "dir1/dir2/file").write_text(TEST_CONTENT)
             c = repo.commit()
-            loader = git_loader(swh_storage, str(rp), config=swh_loader_config)
+            loader = git_loader(str(rp))
             loader.load()
 
             obj_id_hex = repo.repo[c].tree.decode()
             obj_id = hashutil.hash_to_bytes(obj_id_hex)
 
-        with cook_extract_directory(swh_storage, obj_id) as p:
+        with cook_extract_directory(loader.storage, obj_id) as p:
             assert (p / "file").stat().st_mode == 0o100644
             assert (p / "file").read_text() == TEST_CONTENT
             assert (p / "executable").stat().st_mode == 0o100755
This revision is now accepted and ready to land.Oct 2 2020, 6:35 PM

Looks good ! I think we could simplify the git loader creation by making git_loader a pytest fixture. This could be added in a second commit or I can open a diff with my local experiments (see diff extract below)

thanks, it crossed my mind...
then I saw the str(rp) and did not quite know what to do of it ;)

Thanks for the suggestion \m/

I'll push this and i'll happily review your suggestion as diff.

Cheers mate,

This revision was automatically updated to reflect the committed changes.

I'll push this and i'll happily review your suggestion as diff.

Cheers mate,

D4135