Skip to content
Closed
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
5 changes: 4 additions & 1 deletion aai_cli/transcribe_batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,10 @@ def expand_sources(source: str | None, *, from_stdin: bool, sample: bool) -> lis
"""
if from_stdin:
return _stdin_sources(source, sample=sample)
if source is None or sample or source == "-" or source.startswith(_URL_PREFIXES):
if not source or sample or source == "-" or source.startswith(_URL_PREFIXES):
# `not source` also catches "": Path("") is ".", which would otherwise scan the
# whole working directory. An empty source belongs on the single-source path,
# where it reads as "Provide an audio path or URL."
return None
path = Path(source)
if path.is_dir():
Expand Down
18 changes: 17 additions & 1 deletion tests/test_transcribe_batch_sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,27 @@ def test_from_stdin_rejects_sample():
assert "--from-stdin reads sources from stdin" in result.output


@pytest.mark.parametrize("source", ["-", "https://example.com/a.mp3", None])
@pytest.mark.parametrize("source", ["-", "https://example.com/a.mp3", None, ""])
def test_non_batch_sources_return_none(source):
# An empty string is not a batch source: Path("") resolves to ".", so without
# this guard it would silently scan the whole working directory recursively.
assert transcribe_batch.expand_sources(source, from_stdin=False, sample=False) is None


def test_empty_source_argument_does_not_batch_the_working_directory(monkeypatch):
_auth()
# A loud canary: if "" ever reaches directory scanning again, every audio file
# under cwd gets queued. rglob must never run for an empty source.
monkeypatch.setattr(
transcribe_batch.Path,
"rglob",
lambda self, pattern: pytest.fail("empty source must not scan the directory"),
)
result = runner.invoke(app, ["transcribe", ""])
assert result.exit_code == 2
assert "Provide an audio path or URL." in result.output


def test_sample_returns_none_even_without_source():
assert transcribe_batch.expand_sources(None, from_stdin=False, sample=True) is None

Expand Down
Loading