@@ -808,9 +808,9 @@ def test_manifest_cache_deduplicates_manifest_files() -> None:
808808
809809 # Verify cache size - should only have 3 unique ManifestFile objects
810810 # instead of 1 + 2 + 3 = 6 objects as with the old approach
811- cache = manifest_module ._manifest_cache
812- assert cache is not None , "Manifest cache should be enabled for this test "
813- assert len ( cache ) == 3 , f"Cache should contain exactly 3 unique ManifestFile objects, but has { len ( cache ) } "
811+ assert len ( manifest_module ._manifest_cache ) == 3 , (
812+ f"Cache should contain exactly 3 unique ManifestFile objects, but has { len ( manifest_module . _manifest_cache ) } "
813+ )
814814
815815
816816def test_manifest_cache_efficiency_with_many_overlapping_lists () -> None :
@@ -883,11 +883,9 @@ def test_manifest_cache_efficiency_with_many_overlapping_lists() -> None:
883883 # With the new approach, we should have exactly N objects
884884
885885 # Verify cache has exactly N unique entries
886- cache = manifest_module ._manifest_cache
887- assert cache is not None , "Manifest cache should be enabled for this test"
888- assert len (cache ) == num_manifests , (
886+ assert len (manifest_module ._manifest_cache ) == num_manifests , (
889887 f"Cache should contain exactly { num_manifests } ManifestFile objects, "
890- f"but has { len (cache )} . "
888+ f"but has { len (manifest_module . _manifest_cache )} . "
891889 f"Old approach would have { num_manifests * (num_manifests + 1 ) // 2 } objects."
892890 )
893891
@@ -1035,27 +1033,22 @@ def test_clear_manifest_cache() -> None:
10351033 _manifests (io , list_path )
10361034
10371035 # Verify cache has entries
1038- cache = manifest_module ._manifest_cache
1039- assert cache is not None , "Cache should be enabled"
1040- assert len (cache ) > 0 , "Cache should have entries after reading manifests"
1036+ assert len (manifest_module ._manifest_cache ) > 0 , "Cache should have entries after reading manifests"
10411037
10421038 # Clear the cache
10431039 clear_manifest_cache ()
10441040
10451041 # Verify cache is empty but still enabled
1046- cache_after = manifest_module ._manifest_cache
1047- assert cache_after is not None , "Cache should still be enabled after clear"
1048- assert len (cache_after ) == 0 , "Cache should be empty after clear"
1042+ assert len (manifest_module ._manifest_cache ) == 0 , "Cache should be empty after clear"
10491043
10501044
1051- @pytest .mark .parametrize ("cache_size" , ["0" , "-1" ])
1052- def test_manifest_cache_can_be_disabled_with_non_positive_size (monkeypatch : pytest .MonkeyPatch , cache_size : str ) -> None :
1053- """Test that non-positive manifest-cache-size values disable caching."""
1054- monkeypatch .setenv ("PYICEBERG_MANIFEST_CACHE_SIZE" , cache_size )
1045+ def test_manifest_cache_can_be_disabled_with_size_zero (monkeypatch : pytest .MonkeyPatch ) -> None :
1046+ """Test that manifest-cache-size=0 disables caching."""
1047+ monkeypatch .setenv ("PYICEBERG_MANIFEST_CACHE_SIZE" , "0" )
10551048 importlib .reload (manifest_module )
10561049
10571050 try :
1058- assert manifest_module ._manifest_cache_size == 0
1051+ assert manifest_module ._manifest_cache . maxsize == 0
10591052 assert len (manifest_module ._manifest_cache ) == 0
10601053
10611054 io = PyArrowFileIO ()
@@ -1079,7 +1072,7 @@ def test_manifest_cache_respects_positive_env_size(monkeypatch: pytest.MonkeyPat
10791072 importlib .reload (manifest_module )
10801073
10811074 try :
1082- assert manifest_module ._manifest_cache_size == 1
1075+ assert manifest_module ._manifest_cache . maxsize == 1
10831076
10841077 io = PyArrowFileIO ()
10851078
@@ -1112,7 +1105,7 @@ def test_manifest_cache_reads_size_from_configuration_file(monkeypatch: pytest.M
11121105 importlib .reload (manifest_module )
11131106
11141107 try :
1115- assert manifest_module ._manifest_cache_size == 2
1108+ assert manifest_module ._manifest_cache . maxsize == 2
11161109
11171110 io = PyArrowFileIO ()
11181111
@@ -1141,3 +1134,15 @@ def test_invalid_manifest_cache_size_raises_value_error(monkeypatch: pytest.Monk
11411134 finally :
11421135 monkeypatch .delenv ("PYICEBERG_MANIFEST_CACHE_SIZE" , raising = False )
11431136 importlib .reload (manifest_module )
1137+
1138+
1139+ def test_negative_manifest_cache_size_raises_value_error (monkeypatch : pytest .MonkeyPatch ) -> None :
1140+ """Test that negative manifest-cache-size values raise a helpful error."""
1141+ monkeypatch .setenv ("PYICEBERG_MANIFEST_CACHE_SIZE" , "-1" )
1142+
1143+ try :
1144+ with pytest .raises (ValueError , match = "manifest-cache-size should be a non-negative integer or left unset" ):
1145+ importlib .reload (manifest_module )
1146+ finally :
1147+ monkeypatch .delenv ("PYICEBERG_MANIFEST_CACHE_SIZE" , raising = False )
1148+ importlib .reload (manifest_module )
0 commit comments