-
Notifications
You must be signed in to change notification settings - Fork 8
24 implement better way to avoid overwriting h5 files #83
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
jwaiton
merged 14 commits into
nu-ZOO:main
from
Tedsmith100:24-implement-better-way-to-avoid-overwriting-h5-files
May 11, 2026
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
da797dd
edit file saving
Tedsmith100 07a674d
change `check_save_path()`
Tedsmith100 c0455ff
remove overwrite prompt
Tedsmith100 34333c0
edit test to include all config params
Tedsmith100 20af3ba
edit test to expect datetime
Tedsmith100 115b3f9
add safety net to saving
Tedsmith100 579eb97
update runtime error test
Tedsmith100 b874b9e
remove redundant file
Tedsmith100 a0451ba
include optional config args in test
Tedsmith100 6c507be
import datetime properly
Tedsmith100 12de176
fix try statement
Tedsmith100 81d4444
make max_iterations an optional arg
Tedsmith100 17dcd9a
fix counter warning test
Tedsmith100 e0bbdbf
add comments to test
Tedsmith100 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,7 @@ | ||
| from datetime import datetime | ||
| import os | ||
| import sys | ||
| import re | ||
|
|
||
| import numpy as np | ||
| import pandas as pd | ||
|
|
@@ -35,6 +37,9 @@ | |
| from hypothesis import given | ||
| from hypothesis.strategies import integers | ||
|
|
||
|
|
||
| from unittest.mock import patch, MagicMock | ||
|
|
||
| @given(integers(min_value = 1, max_value = 1000000)) | ||
| def test_rwf_type_has_correct_shape(samples): | ||
| x = rwf_type(samples) | ||
|
|
@@ -153,26 +158,27 @@ def test_save_path_exists(): | |
|
|
||
|
|
||
| def test_ensure_new_path_created(data_dir): | ||
| data_path = data_dir + 'three_channels_WD2.h5' | ||
| found_path = check_save_path(data_path, overwrite=False) | ||
|
|
||
| data_path = data_dir + 'three_channels_WD2.h5' | ||
| new_data_path = data_dir + 'three_channels_WD21.h5' | ||
|
|
||
| found_path = check_save_path(data_path, overwrite = False) | ||
| assert found_path != data_path | ||
| assert found_path.endswith('.h5') | ||
| assert re.search(r'_\d{8}_\d{6}', found_path), "Expected datetime stamp in filename" | ||
| assert not os.path.exists(found_path), "Path should not already exist" | ||
|
Comment on lines
+164
to
+167
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is no longer direct testing, which is fine but it should be noted. |
||
|
|
||
| assert found_path == new_data_path | ||
|
|
||
|
Tedsmith100 marked this conversation as resolved.
|
||
| def test_runtime_error_when_too_many_save_files(tmp_path): | ||
| timestamp = "20240101_120000" | ||
| mock_dt = MagicMock() | ||
| mock_dt.now.return_value.strftime.return_value = timestamp | ||
|
|
||
| def test_runtime_error_when_too_many_save_files(data_dir): | ||
|
|
||
| relevant_dir = data_dir + 'repetitive_data/' | ||
| # generate 101 empty files | ||
| with open(relevant_dir + f'test_.txt', 'w'): | ||
| pass | ||
| (tmp_path / f'test_{timestamp}.txt').touch() | ||
| for i in range(1, 101): | ||
| with open(relevant_dir + f'test_{i}.txt', 'w'): | ||
| pass | ||
| with raises(RuntimeError): | ||
| check_save_path(relevant_dir + 'test_.txt', overwrite=False) | ||
| (tmp_path / f'test_{timestamp}_{i}.txt').touch() | ||
|
|
||
| with patch('packs.proc.processing_utils.datetime', mock_dt): | ||
| with raises(RuntimeError): | ||
| check_save_path(str(tmp_path / 'test.txt'), overwrite=False) | ||
|
|
||
| @mark.parametrize("config, inpt, output, comparison", [("process_WD2_1channel.conf", "one_channel_WD2.bin", "one_channel_tmp.h5", "one_channel_WD2.h5"), | ||
| ("process_WD2_3channel.conf", "three_channels_WD2.bin", "three_channels_tmp.h5", "three_channels_WD2.h5")]) | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.