🎨 add helpers for getting files

This commit is contained in:
Ondřej Samohel 2024-12-01 16:11:23 +01:00
parent f4169769ac
commit 595a3546f3
No known key found for this signature in database
GPG key ID: 02376E18990A97C6
3 changed files with 98 additions and 3 deletions

View file

@ -139,3 +139,43 @@ def test_file_locations_validation() -> None:
with pytest.raises(TraitValidationError):
representation.validate()
def test_get_file_from_frame() -> None:
"""Test get_file_from_frame method."""
file_locations_list = [
FileLocation(
file_path=Path(f"/path/to/file.{frame}.exr"),
file_size=1024,
file_hash=None,
)
for frame in range(1001, 1051)
]
file_locations_trait: FileLocations = FileLocations(
file_paths=file_locations_list)
assert file_locations_trait.get_file_for_frame(frame=1001) == \
file_locations_list[0].file_path
assert file_locations_trait.get_file_for_frame(frame=1050) == \
file_locations_list[-1].file_path
assert file_locations_trait.get_file_for_frame(frame=1100) is None
# test with custom regex
sequence = Sequence(
frame_padding=4,
frame_regex=r"boo_(?P<frame>\d+)\.exr")
file_locations_list = [
FileLocation(
file_path=Path(f"/path/to/boo_{frame}.exr"),
file_size=1024,
file_hash=None,
)
for frame in range(1001, 1051)
]
file_locations_trait: FileLocations = FileLocations(
file_paths=file_locations_list)
assert file_locations_trait.get_file_for_frame(
frame=1001, sequence_trait=sequence) == \
file_locations_list[0].file_path