@@ -1920,21 +1920,21 @@ async def test_zip_adapter_missing_coverage() -> None:
1920
1920
assert schemes == []
1921
1921
1922
1922
# Test ZIP with storage options (should ignore them)
1923
- with tempfile .NamedTemporaryFile ( suffix = ".zip" , delete = False ) as tmp :
1924
- tmp_path = tmp . name
1923
+ with tempfile .TemporaryDirectory ( ) as temp_dir :
1924
+ tmp_path = Path ( temp_dir ) / "test.zip"
1925
1925
1926
- # Create a zip file with zarr data
1927
- with zipfile .ZipFile (tmp_path , "w" ) as zf :
1928
- zf .writestr (".zgroup" , "{}" ) # Valid zarr group
1926
+ # Create a zip file with zarr data
1927
+ with zipfile .ZipFile (tmp_path , "w" ) as zf :
1928
+ zf .writestr (".zgroup" , "{}" ) # Valid zarr group
1929
1929
1930
- try :
1931
1930
segment = URLSegment (adapter = "zip" , path = "" )
1932
1931
result = await ZipAdapter .from_url_segment (
1933
1932
segment , f"file:{ tmp_path } " , storage_options = {"some_option" : "value" }
1934
1933
)
1935
1934
assert result is not None
1936
- finally :
1937
- Path (tmp_path ).unlink (missing_ok = True )
1935
+ # Close the store to release the file handle on Windows
1936
+ result .close ()
1937
+ # File will be automatically cleaned up when temp_dir is removed
1938
1938
1939
1939
1940
1940
async def test_logging_adapter_missing_coverage () -> None :
@@ -2494,10 +2494,9 @@ async def test_zip_adapter_remote_functionality() -> None:
2494
2494
segment = URLSegment (adapter = "zip" , path = "inner" )
2495
2495
2496
2496
# Create a temporary zip file to test with
2497
- with tempfile .NamedTemporaryFile ( suffix = ".zip" , delete = False ) as tmp :
2498
- tmp_path = tmp . name
2497
+ with tempfile .TemporaryDirectory ( ) as temp_dir :
2498
+ tmp_path = Path ( temp_dir ) / "test.zip"
2499
2499
2500
- try :
2501
2500
# Create a valid zip file
2502
2501
with zipfile .ZipFile (tmp_path , "w" ) as zf :
2503
2502
zf .writestr (".zgroup" , "{}" )
@@ -2506,9 +2505,9 @@ async def test_zip_adapter_remote_functionality() -> None:
2506
2505
# Test with file: URL (should convert to local path)
2507
2506
result = await ZipAdapter .from_url_segment (segment , f"file:{ tmp_path } " )
2508
2507
assert result is not None
2509
-
2510
- finally :
2511
- Path ( tmp_path ). unlink ( missing_ok = True )
2508
+ # Close the store to release the file handle on Windows
2509
+ result . close ()
2510
+ # File will be automatically cleaned up when temp_dir is removed
2512
2511
2513
2512
2514
2513
async def test_zip_adapter_remote_error_handling () -> None :
0 commit comments