Skip to content
Merged
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
7 changes: 5 additions & 2 deletions scripts/generate_spectrograms.py
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,11 @@ def main():

args = parser.parse_args()

if args.clip_pad_seconds is not None and args.clip_pad_seconds < 0:
parser.error(
"--clip-pad-seconds/--edge-pad-seconds must be non-negative"
)

if args.event_time is not None:
if not args.input_file:
parser.error("--event-time requires --input-file")
Expand All @@ -674,8 +679,6 @@ def main():
parser.error("--event-pad-after must be non-negative")
if args.event_pad_before + event_pad_after <= 0:
parser.error("event padding must retain more than zero seconds")
if args.clip_pad_seconds is not None and args.clip_pad_seconds < 0:
parser.error("--edge-pad-seconds must be non-negative")

try:
print_header("CUSTOM SPECTROGRAM GENERATOR")
Expand Down
32 changes: 32 additions & 0 deletions tests/test_generate_spectrograms_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,35 @@ def test_event_argument_errors_use_argparse_without_traceback(
assert f"error: {message}" in completed.stderr
assert "Traceback" not in completed.stderr
assert "Unexpected error" not in completed.stdout + completed.stderr


@pytest.mark.parametrize("flag", ["--clip-pad-seconds", "--edge-pad-seconds"])
def test_negative_clip_pad_without_event_uses_argparse_without_traceback(
tmp_path: Path,
flag: str,
):
Comment on lines +61 to +65
input_path = tmp_path / "audio.wav"
input_path.touch()

completed = subprocess.run(
[
sys.executable,
str(SCRIPT),
"--input-file",
str(input_path),
flag,
"-0.1",
],
cwd=REPO_ROOT,
text=True,
capture_output=True,
check=False,
)

assert completed.returncode == 2
assert (
"error: --clip-pad-seconds/--edge-pad-seconds must be non-negative"
in completed.stderr
)
assert "Traceback" not in completed.stderr
assert "Unexpected error" not in completed.stdout + completed.stderr
Comment on lines +61 to +90