Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyrit/models/seeds/seed_prompt.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def __post_init__(self) -> None:
# Note: Does not assign 'error' or 'url' implicitly
if os.path.isfile(self.value):
_, ext = os.path.splitext(self.value)
ext = ext.lstrip(".")
ext = ext.lstrip(".").lower()
if ext in ["mp4", "avi", "mov", "mkv", "ogv", "flv", "wmv", "webm"]:
self.data_type = "video_path"
elif ext in ["flac", "mp3", "mpeg", "mpga", "m4a", "ogg", "wav"]:
Expand Down
18 changes: 18 additions & 0 deletions tests/unit/models/test_seed.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,24 @@ def test_seed_prompt_initialization(seed_prompt_fixture):
assert seed_prompt_fixture.parameters == ["param1"]


@pytest.mark.parametrize(
("suffix", "expected_data_type"),
[
(".PNG", "image_path"),
(".WAV", "audio_path"),
],
)
def test_seed_prompt_infers_file_type_from_uppercase_extension(suffix, expected_data_type):
with tempfile.NamedTemporaryFile(suffix=suffix, delete=False) as temp_file:
file_path = temp_file.name

try:
seed_prompt = SeedPrompt(value=file_path)
assert seed_prompt.data_type == expected_data_type
finally:
os.remove(file_path)


def test_seed_prompt_render_template_success(seed_prompt_fixture):
seed_prompt_fixture.value = "Test prompt with param1={{ param1 }}"
result = seed_prompt_fixture.render_template_value(param1="value1")
Expand Down