|
16 | 16 | # under the License. |
17 | 17 | # pylint: disable=redefined-outer-name,arguments-renamed,fixme |
18 | 18 | from tempfile import TemporaryDirectory |
19 | | -from unittest import mock |
20 | 19 |
|
21 | 20 | import fastavro |
22 | 21 | import pytest |
|
49 | 48 |
|
50 | 49 | @pytest.fixture(autouse=True) |
51 | 50 | def reset_global_manifests_cache() -> None: |
52 | | - with manifest_module._manifest_cache_lock: |
53 | | - manifest_module._manifest_cache = manifest_module._init_manifest_cache() |
54 | 51 | clear_manifest_cache() |
55 | 52 |
|
56 | 53 |
|
@@ -1001,45 +998,3 @@ def test_clear_manifest_cache() -> None: |
1001 | 998 | cache_after = manifest_module._manifest_cache |
1002 | 999 | assert cache_after is not None, "Cache should still be enabled after clear" |
1003 | 1000 | assert len(cache_after) == 0, "Cache should be empty after clear" |
1004 | | - |
1005 | | - |
1006 | | -@pytest.mark.parametrize( |
1007 | | - "env_vars,expected_enabled,expected_size", |
1008 | | - [ |
1009 | | - ({}, True, 128), # defaults |
1010 | | - ({"PYICEBERG_MANIFEST_CACHE_SIZE": "64"}, True, 64), |
1011 | | - ({"PYICEBERG_MANIFEST_CACHE_SIZE": "256"}, True, 256), |
1012 | | - ({"PYICEBERG_MANIFEST_CACHE_SIZE": "0"}, False, 0), # size=0 disables cache |
1013 | | - ], |
1014 | | -) |
1015 | | -def test_manifest_cache_config_valid_values(env_vars: dict[str, str], expected_enabled: bool, expected_size: int) -> None: |
1016 | | - """Test that valid config values are applied correctly.""" |
1017 | | - import os |
1018 | | - |
1019 | | - with mock.patch.dict(os.environ, env_vars, clear=False): |
1020 | | - with manifest_module._manifest_cache_lock: |
1021 | | - manifest_module._manifest_cache = manifest_module._init_manifest_cache() |
1022 | | - cache = manifest_module._manifest_cache |
1023 | | - |
1024 | | - if expected_enabled: |
1025 | | - assert cache is not None, "Cache should be enabled" |
1026 | | - assert cache.maxsize == expected_size, f"Cache size should be {expected_size}" |
1027 | | - else: |
1028 | | - assert cache is None, "Cache should be disabled" |
1029 | | - |
1030 | | - |
1031 | | -@pytest.mark.parametrize( |
1032 | | - "env_vars,expected_error_substring", |
1033 | | - [ |
1034 | | - ({"PYICEBERG_MANIFEST_CACHE_SIZE": "abc"}, "manifest-cache-size should be an integer"), |
1035 | | - ({"PYICEBERG_MANIFEST_CACHE_SIZE": "-5"}, "manifest-cache-size must be >= 0"), |
1036 | | - ], |
1037 | | -) |
1038 | | -def test_manifest_cache_config_invalid_values(env_vars: dict[str, str], expected_error_substring: str) -> None: |
1039 | | - """Test that invalid config values raise ValueError with appropriate message.""" |
1040 | | - import os |
1041 | | - |
1042 | | - with mock.patch.dict(os.environ, env_vars, clear=False): |
1043 | | - with pytest.raises(ValueError, match=expected_error_substring): |
1044 | | - with manifest_module._manifest_cache_lock: |
1045 | | - manifest_module._manifest_cache = manifest_module._init_manifest_cache() |
0 commit comments