Validate edge padding CLI arguments - #9
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
This PR moves edge-padding validation (--clip-pad-seconds / --edge-pad-seconds) to immediately after CLI argument parsing so negative values consistently fail via argparse (exit code 2) across both normal and event-driven modes, avoiding broad exception handling/tracebacks.
Changes:
- Add a post-
parse_args()validation that rejects negativeclip_pad_secondsvalues with anargparseerror. - Remove the prior event-mode-only negative padding validation to ensure consistent behavior across modes.
- Add a regression test ensuring negative edge-padding values fail via
argparsewithout tracebacks when not using--event-time.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
scripts/generate_spectrograms.py |
Moves negative padding validation to immediately after argument parsing and removes the event-only check. |
tests/test_generate_spectrograms_cli.py |
Adds a regression test for negative padding values (both CLI aliases) in non-event mode. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+61
to
+65
| @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
+90
| @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, | ||
| ): | ||
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changed
--clip-pad-secondsand--edge-pad-secondsvalues immediately after argument parsing--event-timeWhy
The edge-padding validation was nested inside event-mode validation. Negative padding in other modes reached the broad exception handler and could be reported as an unexpected error with a traceback.
User impact
Invalid edge-padding values now produce concise
argparseusage errors with exit code 2 in every CLI mode.Validation
5 passedin the focused CLI suite66 passed, 2 deselectedin the full offline suitegit diff --check