From d4fa480262a994dadaeca1eb4ea379157d6ba91b Mon Sep 17 00:00:00 2001 From: Jonathan Thiessen Date: Mon, 24 Mar 2025 10:26:29 -0700 Subject: [PATCH] Add overlapping (consistent) flake cache insert test * Additionally, update `insert`'s input type hint to support None values (as they are already selectable and (one shot) insertable). This is necessary to appease the linter wrt the added test. --- pkgs/clan-cli/clan_cli/flake.py | 4 +++- pkgs/clan-cli/tests/test_flake_caching.py | 8 ++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/pkgs/clan-cli/clan_cli/flake.py b/pkgs/clan-cli/clan_cli/flake.py index 39614c378..6dbb9910f 100644 --- a/pkgs/clan-cli/clan_cli/flake.py +++ b/pkgs/clan-cli/clan_cli/flake.py @@ -154,7 +154,9 @@ class FlakeCacheEntry: self.value = value def insert( - self, value: str | float | dict[str, Any] | list[Any], selectors: list[Selector] + self, + value: str | float | dict[str, Any] | list[Any] | None, + selectors: list[Selector], ) -> None: selector: Selector if selectors == []: diff --git a/pkgs/clan-cli/tests/test_flake_caching.py b/pkgs/clan-cli/tests/test_flake_caching.py index 56c04e56c..858bcedc3 100644 --- a/pkgs/clan-cli/tests/test_flake_caching.py +++ b/pkgs/clan-cli/tests/test_flake_caching.py @@ -17,6 +17,14 @@ def test_select() -> None: assert not test_cache.is_cached(["x", "z", 1]) +def test_insert() -> None: + test_cache = FlakeCacheEntry({}, []) + # Inserting the same thing twice should succeed + test_cache.insert(None, ["nix"]) + test_cache.insert(None, ["nix"]) + assert test_cache.select(["nix"]) is None + + def test_out_path() -> None: testdict = {"x": {"y": [123, 345, 456], "z": "/nix/store/bla"}} test_cache = FlakeCacheEntry(testdict, [])