Skip to content

Commit

Permalink
Don't display warning if the watcher discovers a temp file (#329)
Browse files Browse the repository at this point in the history
* Suppress warnings for a watcher temp file

* Fix tests to watch for warnings correctly
  • Loading branch information
alex-l-kong authored Mar 20, 2023
1 parent 66a7a6a commit 330b2cd
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
4 changes: 4 additions & 0 deletions src/toffy/fov_watcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ def check_run_condition(self, path: str) -> Tuple[bool, str]:

filename = Path(path).parts[-1]

# if filename starts with a '.' (temp file), it should be ignored
if filename[0] == ".":
return False, ""

# filename is not corrct format of fov.bin or fov.json
if len(filename.split(".")) != 2:
warnings.warn(
Expand Down
12 changes: 9 additions & 3 deletions tests/fov_watcher_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def _slow_copy_sample_tissue_data(dest: str, delta: int = 10, one_blank: bool =


@parametrize_with_cases("run_json, expected_files", cases=RunStructureCases)
def test_run_structure(run_json, expected_files):
def test_run_structure(run_json, expected_files, recwarn):
with RunStructureTestContext(run_json, files=expected_files) as (
tmpdir,
run_structure,
Expand All @@ -73,9 +73,15 @@ def test_run_structure(run_json, expected_files):
run_structure.check_run_condition(os.path.join(tmpdir, file))
assert all(run_structure.check_fov_progress().values())

# check for hidden files
# hidden files should not throw an invalid FOV file warning but still be skipped
exist, name = run_structure.check_run_condition(os.path.join(tmpdir, ".fake_file.txt"))
for warn_data in recwarn.list:
assert "not a valid FOV file and will be skipped" not in str(warn_data.message)
assert not exist and name == ""

# check for invalid file format
with pytest.warns(Warning, match="is not a valid FOV file and will be skipped"):
exist, name = run_structure.check_run_condition(os.path.join(tmpdir, ".fake_file.txt"))
exist, name = run_structure.check_run_condition(os.path.join(tmpdir, "fov.bin.txt"))
assert not exist and name == ""

# check for fake files
Expand Down

0 comments on commit 330b2cd

Please sign in to comment.