@@ -13,10 +13,10 @@ def test_file_cache(config_file):
1313 # Get engine from the fixture
1414 engine = get_engine (config_file , "main" )
1515 store = engine .store
16-
16+
1717 # Create a timestamp for test data
1818 now = datetime .now (timezone .utc )
19-
19+
2020 # Create a test file
2121 test_file = File (
2222 file_id = "test_file_id" ,
@@ -30,18 +30,18 @@ def test_file_cache(config_file):
3030 modified_at = now ,
3131 size = 100 ,
3232 content_type = "text/plain" ,
33- data_spec_version = "v1"
33+ data_spec_version = "v1" ,
3434 )
35-
35+
3636 # Create a test revision with the file
3737 revision = Revision (
3838 revision_id = 1 ,
3939 created_at = now ,
4040 description = "Test revision" ,
4141 modified_files = [test_file ],
42- source = {"source_type" : SourceType .MANUAL , "source_id" : "test" }
42+ source = {"source_type" : SourceType .MANUAL , "source_id" : "test" },
4343 )
44-
44+
4545 # Create a test dataset with the revision
4646 dataset = Dataset (
4747 bucket = "test-bucket" ,
@@ -55,41 +55,44 @@ def test_file_cache(config_file):
5555 created_at = now ,
5656 updated_at = now ,
5757 last_modified_at = now ,
58- revisions = [revision ]
58+ revisions = [revision ],
5959 )
60-
60+
6161 # Create a simple pass-through reader function to replace the gzip reader
6262 def simple_reader (stream ):
6363 return stream
64-
64+
6565 # Mock both the file repository and the _prepare_read_stream method
66- with patch .object (store .file_repository , 'load_content' ) as mock_load_content , \
67- patch .object (store , '_prepare_read_stream' ) as mock_prepare_read_stream :
68-
66+ with patch .object (
67+ store .file_repository , "load_content"
68+ ) as mock_load_content , patch .object (
69+ store , "_prepare_read_stream"
70+ ) as mock_prepare_read_stream :
71+
6972 # Set up the mocks
7073 mock_load_content .return_value = BytesIO (b"test content" )
7174 mock_prepare_read_stream .return_value = (simple_reader , "" )
72-
75+
7376 # Test without caching - should load files twice
7477 store .load_files (dataset )
7578 store .load_files (dataset )
76-
79+
7780 # Should have called load_content twice (without caching)
7881 assert mock_load_content .call_count == 2
79-
82+
8083 # Reset the mock
8184 mock_load_content .reset_mock ()
82-
85+
8386 # Test with caching - should load files only once
8487 with store .with_file_cache ():
8588 store .load_files (dataset )
8689 store .load_files (dataset )
87-
90+
8891 # Should have called load_content only once (with caching)
8992 assert mock_load_content .call_count == 1
90-
93+
9194 # After exiting context, caching should be disabled
9295 store .load_files (dataset )
93-
96+
9497 # Should have called load_content again
9598 assert mock_load_content .call_count == 2
0 commit comments