Skip to content

Commit c3ad621

Browse files
committed
Code formatting
1 parent b7e706e commit c3ad621

File tree

2 files changed

+29
-26
lines changed

2 files changed

+29
-26
lines changed

ingestify/application/dataset_store.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,19 +61,19 @@ def set_event_bus(self, event_bus: EventBus):
6161
def dispatch(self, event):
6262
if self.event_bus:
6363
self.event_bus.dispatch(event)
64-
64+
6565
@contextmanager
6666
def with_file_cache(self):
6767
"""Context manager to enable file caching during its scope.
68-
68+
6969
Files loaded within this context will be cached and reused,
7070
avoiding multiple downloads of the same file.
71-
71+
7272
Example:
7373
# Without caching (loads files twice)
7474
analyzer1 = StatsAnalyzer(store, dataset)
7575
analyzer2 = VisualizationTool(store, dataset)
76-
76+
7777
# With caching (files are loaded once and shared)
7878
with store.with_file_cache():
7979
analyzer1 = StatsAnalyzer(store, dataset)
@@ -82,7 +82,7 @@ def with_file_cache(self):
8282
# Enable caching for this thread
8383
self._thread_local.use_file_cache = True
8484
self._thread_local.file_cache = {}
85-
85+
8686
try:
8787
yield
8888
finally:
@@ -419,11 +419,11 @@ def get_stream(file_):
419419
def make_loaded_file():
420420
return LoadedFile(
421421
stream_=get_stream if lazy else get_stream(file),
422-
**file.model_dump()
422+
**file.model_dump(),
423423
)
424424

425425
# Using getattr with a default value of False - simple one-liner
426-
if getattr(self._thread_local, 'use_file_cache', False):
426+
if getattr(self._thread_local, "use_file_cache", False):
427427
key = (dataset.dataset_id, current_revision.revision_id, file.file_id)
428428
if key not in self._thread_local.file_cache:
429429
self._thread_local.file_cache[key] = make_loaded_file()

ingestify/tests/test_file_cache.py

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)