Skip to content

Commit 173cfef

Browse files
biefanromanlutzCopilot
authored
Normalize SeedPrompt file extension detection (#1501)
Co-authored-by: Roman Lutz <romanlutz@users.noreply.github.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Co-authored-by: Roman Lutz <romanlutz13@gmail.com>
1 parent bde0ed1 commit 173cfef

2 files changed

Lines changed: 49 additions & 1 deletion

File tree

pyrit/models/seeds/seed_prompt.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def __post_init__(self) -> None:
6767
# Note: Does not assign 'error' or 'url' implicitly
6868
if os.path.isfile(self.value):
6969
_, ext = os.path.splitext(self.value)
70-
ext = ext.lstrip(".")
70+
ext = ext.lstrip(".").lower()
7171
if ext in ["mp4", "avi", "mov", "mkv", "ogv", "flv", "wmv", "webm"]:
7272
self.data_type = "video_path"
7373
elif ext in ["flac", "mp3", "mpeg", "mpga", "m4a", "ogg", "wav"]:

tests/unit/models/test_seed.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,54 @@ def test_seed_prompt_initialization(seed_prompt_fixture):
7474
assert seed_prompt_fixture.parameters == ["param1"]
7575

7676

77+
@pytest.mark.parametrize(
78+
("suffix", "expected_data_type"),
79+
[
80+
# Video — uppercase
81+
(".MP4", "video_path"),
82+
(".AVI", "video_path"),
83+
(".MOV", "video_path"),
84+
(".MKV", "video_path"),
85+
(".OGV", "video_path"),
86+
(".FLV", "video_path"),
87+
(".WMV", "video_path"),
88+
(".WEBM", "video_path"),
89+
# Audio — uppercase
90+
(".FLAC", "audio_path"),
91+
(".MP3", "audio_path"),
92+
(".MPEG", "audio_path"),
93+
(".MPGA", "audio_path"),
94+
(".M4A", "audio_path"),
95+
(".OGG", "audio_path"),
96+
(".WAV", "audio_path"),
97+
# Image — uppercase
98+
(".JPG", "image_path"),
99+
(".JPEG", "image_path"),
100+
(".PNG", "image_path"),
101+
(".GIF", "image_path"),
102+
(".BMP", "image_path"),
103+
(".TIFF", "image_path"),
104+
(".TIF", "image_path"),
105+
# Mixed case
106+
(".Mp4", "video_path"),
107+
(".Wav", "audio_path"),
108+
(".Png", "image_path"),
109+
(".jPeG", "image_path"),
110+
(".FlaC", "audio_path"),
111+
(".wEbM", "video_path"),
112+
],
113+
)
114+
def test_seed_prompt_infers_file_type_from_case_insensitive_extension(suffix, expected_data_type):
115+
with tempfile.NamedTemporaryFile(suffix=suffix, delete=False) as temp_file:
116+
file_path = temp_file.name
117+
118+
try:
119+
seed_prompt = SeedPrompt(value=file_path)
120+
assert seed_prompt.data_type == expected_data_type
121+
finally:
122+
os.remove(file_path)
123+
124+
77125
def test_seed_prompt_render_template_success(seed_prompt_fixture):
78126
seed_prompt_fixture.value = "Test prompt with param1={{ param1 }}"
79127
result = seed_prompt_fixture.render_template_value(param1="value1")

0 commit comments

Comments
 (0)