Skip to content

Commit

Permalink
os to pathlib
Browse files Browse the repository at this point in the history
  • Loading branch information
Sparks29032 committed Dec 9, 2024
1 parent 290e839 commit 29a8fe8
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions tests/test_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,16 @@ def test_nn_value(self, setup):
pytest.approx(tools.nn_value(-value, name=None), abs(-value))

def test_field_sort(self, setup):
sequence_files = [*os.listdir(testsequence_dir)]
sequence_files = [file for file in Path(testsequence_dir).iterdir()]
to_remove = []
for file in sequence_files:
if file.is_dir():
to_remove.append(file)
for d in to_remove:
sequence_files.remove(d)
absolute_sf = []
for file in sequence_files:
absolute_sf.append(os.path.join(testsequence_dir, file))
absolute_sf.append(Path(testsequence_dir) / file.name)

# Fisher-Yates randomization
import random
Expand All @@ -84,8 +90,8 @@ def test_field_sort(self, setup):
sorted_sequence.append(path.name)

# Temperature sort should produce same result as alphanumerical if leading character is removed
sequence_files.sort(key=lambda entry: entry[2:])
assert sequence_files == sorted_sequence
sequence_files.sort(key=lambda entry: entry.name[2:])
assert [file.name for file in sequence_files] == sorted_sequence

# Check temperatures are correct
assert fvs == [174, 180, 186, 192, 198, 204, 210]
Expand All @@ -98,15 +104,15 @@ def test_field_sort(self, setup):

# Reversed sort should match alphanumerical sort
sequence_files.sort()
assert sequence_files == reversed_sequence
assert [file.name for file in sequence_files] == reversed_sequence

# Check we get the same sequence when we load header information from a serial file
serial_file = os.path.join(testdata_dir, "testsequence_serialfile.json")
metadata_path_sequence = tools.field_sort(path_sequence, "temperature", serfile=serial_file, reverse=True)
metadata_sequence = []
for path in metadata_path_sequence:
metadata_sequence.append(path.name)
assert sequence_files == metadata_sequence
assert [file.name for file in sequence_files] == metadata_sequence

# Check error thrown when field does not exist
with pytest.raises(KeyError):
Expand Down

0 comments on commit 29a8fe8

Please sign in to comment.