From 8a27f5f9d816caac7bceb7b3a80f37d82b8b5110 Mon Sep 17 00:00:00 2001 From: Wolf Vollprecht Date: Sun, 1 Dec 2024 08:57:57 +0100 Subject: [PATCH] add a test --- py-rattler-build/README.md | 2 +- py-rattler-build/rattler_build/__init__.py | 3 ++- py-rattler-build/tests/unit/test_basic.py | 3 ++- test-data/recipes/cache/recipe-symlinks.yaml | 1 + .../test_symlinks/test_symlink_cache.json | 7 +++++++ test/end-to-end/test_symlinks.py | 16 ++++++++++++++-- 6 files changed, 27 insertions(+), 5 deletions(-) diff --git a/py-rattler-build/README.md b/py-rattler-build/README.md index 822727f9f..f03ae8b78 100644 --- a/py-rattler-build/README.md +++ b/py-rattler-build/README.md @@ -1 +1 @@ -# Python bindings to rattler-build \ No newline at end of file +# Python bindings to rattler-build diff --git a/py-rattler-build/rattler_build/__init__.py b/py-rattler-build/rattler_build/__init__.py index ec70e0e08..c4062e10d 100644 --- a/py-rattler-build/rattler_build/__init__.py +++ b/py-rattler-build/rattler_build/__init__.py @@ -1,4 +1,5 @@ -from .rattler_build import get_rattler_build_version_py as _get_rattler_build_version_py +from .rattler_build import \ + get_rattler_build_version_py as _get_rattler_build_version_py def rattler_build_version() -> str: diff --git a/py-rattler-build/tests/unit/test_basic.py b/py-rattler-build/tests/unit/test_basic.py index 39f146b4f..9a59d162d 100644 --- a/py-rattler-build/tests/unit/test_basic.py +++ b/py-rattler-build/tests/unit/test_basic.py @@ -1,6 +1,7 @@ -import rattler_build from pathlib import Path +import rattler_build + def test_basic() -> None: parent_cargo_toml = Path(__file__).parent.parent.parent.parent / "Cargo.toml" diff --git a/test-data/recipes/cache/recipe-symlinks.yaml b/test-data/recipes/cache/recipe-symlinks.yaml index 8c9ec28fc..ee39622f6 100644 --- a/test-data/recipes/cache/recipe-symlinks.yaml +++ b/test-data/recipes/cache/recipe-symlinks.yaml @@ -14,6 +14,7 @@ cache: ln -s $PREFIX/foo.txt $PREFIX/absolute-symlink.txt ln -s $PREFIX/non-existent-file $PREFIX/broken-symlink.txt ln -s ./foo.txt $PREFIX/relative-symlink.txt + echo ${{ PREFIX }} > $PREFIX/prefix.txt outputs: - package: diff --git a/test/end-to-end/__snapshots__/test_symlinks/test_symlink_cache.json b/test/end-to-end/__snapshots__/test_symlinks/test_symlink_cache.json index d2d735b8a..9e062586b 100644 --- a/test/end-to-end/__snapshots__/test_symlinks/test_symlink_cache.json +++ b/test/end-to-end/__snapshots__/test_symlinks/test_symlink_cache.json @@ -24,6 +24,13 @@ "sha256": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "size_in_bytes": 0 }, + { + "_path": "prefix.txt", + "file_mode": "text", + "path_type": "hardlink", + "sha256": "1f7c780c5a35eeab2ffd8a7d38f9db34974e84ca569db0ff99af21159b5d02d6", + "size_in_bytes": 256 + }, { "_path": "relative-symlink.txt", "path_type": "softlink", diff --git a/test/end-to-end/test_symlinks.py b/test/end-to-end/test_symlinks.py index e269a37ff..804445c87 100644 --- a/test/end-to-end/test_symlinks.py +++ b/test/end-to-end/test_symlinks.py @@ -4,6 +4,7 @@ import pytest from helpers import RattlerBuild, get_extracted_package +from syrupy.filters import paths as filter_paths @pytest.mark.skipif( @@ -34,10 +35,11 @@ def test_symlink_cache( paths_json = pkg / "info/paths.json" j = json.loads(paths_json.read_text()) - assert snapshot_json == j + # prefix placeholder always changes, and we test it later + assert snapshot_json(exclude=filter_paths("paths.4.prefix_placeholder")) == j paths = j["paths"] - assert len(paths) == 5 + assert len(paths) == 6 for p in paths: if "symlink" in p["_path"]: assert p["path_type"] == "softlink" @@ -61,3 +63,13 @@ def test_symlink_cache( relative_symlink = pkg / "bin/exe-symlink" assert relative_symlink.is_symlink() assert relative_symlink.readlink() == Path("exe") + + prefix_txt = pkg / "prefix.txt" + assert prefix_txt.exists() + contents = prefix_txt.read_text() + assert contents.len() > 0 + # find the path in paths.json for the prefix.txt + for p in paths: + if p["_path"] == "prefix.txt": + assert p["path_type"] == "hardlink" + assert p["prefix_placeholder"] == contents.strip()