Skip to content

Commit

Permalink
Add test for deleted files in which_package
Browse files Browse the repository at this point in the history
Signed-off-by: Marcel Bargull <[email protected]>
  • Loading branch information
mbargull committed Jan 16, 2024
1 parent 31cc7d5 commit 672e8b9
Showing 1 changed file with 30 additions and 2 deletions.
32 changes: 30 additions & 2 deletions tests/test_inspect_pkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,13 @@ def test_which_package(tmp_path: Path):
(tmp_path / "internal").symlink_to(tmp_path / "hardlinkA") # packageA
(tmp_path / "external").symlink_to(tmp_path / "hardlinkB") # packageA
(tmp_path / "hardlinkB").touch() # packageB
# Files might be deleted from the prefix during the build, but they should
# still be recognized since they will be present in the run environment.
(tmp_path / "deleted").unlink(missing_ok=True) # packageA
(tmp_path / "deleted_shared").unlink(missing_ok=True) # packageA & packageB

# a dummy package with a hardlink file, shared file, internal softlink, and external softlink
# a dummy package with a hardlink file, shared file, internal softlink,
# external softlink, deleted file, and deleted shared file
(tmp_path / "conda-meta" / "packageA-1-0.json").write_text(
json.dumps(
{
Expand Down Expand Up @@ -56,14 +61,24 @@ def test_which_package(tmp_path: Path):
"path_type": "softlink",
"size_in_bytes": 0,
},
{
"_path": "deleted",
"path_type": "hardlink",
"size_in_bytes": 0,
},
{
"_path": "deleted_shared",
"path_type": "hardlink",
"size_in_bytes": 0,
},
],
"paths_version": 1,
},
"version": "1",
}
)
)
# a dummy package with a hardlink file and shared file
# a dummy package with a hardlink file, shared file, deleted shared file
(tmp_path / "conda-meta" / "packageB-1-0.json").write_text(
json.dumps(
{
Expand All @@ -84,6 +99,11 @@ def test_which_package(tmp_path: Path):
"path_type": "hardlink",
"size_in_bytes": 0,
},
{
"_path": "deleted_shared",
"path_type": "hardlink",
"size_in_bytes": 0,
},
],
"paths_version": 1,
},
Expand Down Expand Up @@ -121,6 +141,14 @@ def test_which_package(tmp_path: Path):
assert len(precs_hardlinkB) == 1
assert set(precs_hardlinkB) == {precB}

precs_deleted = list(which_package(tmp_path / "deleted", tmp_path))
assert len(precs_deleted) == 1
assert set(precs_deleted) == {precA}

precs_deleted_shared = list(which_package(tmp_path / "deleted_shared", tmp_path))
assert len(precs_deleted_shared) == 2
assert set(precs_deleted_shared) == {precA, precB}


@pytest.mark.benchmark
def test_which_package_battery(tmp_path: Path):
Expand Down

0 comments on commit 672e8b9

Please sign in to comment.