-
Notifications
You must be signed in to change notification settings - Fork 4
fix: display original format name for ffmpeg files (#46) #62
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
7a1f640
062e766
ede69af
47d69ce
34c423d
d50f8dc
c003cd7
ab69fb9
f398dce
a6da74e
9660a0e
ca757e0
dda935b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -56,6 +56,35 @@ def test_frames_matches_data_length(self) -> None: | |
| data, meta = load_audio(FIXTURES_DIR / "sine_a.wav") | ||
| assert meta.frames == len(data) | ||
|
|
||
| def test_transcoded_format_name_is_correct(self, tmp_path: Path) -> None: | ||
| """Verifies that transcoded files show their original format name, not WAV.""" | ||
| from unittest.mock import patch | ||
|
|
||
| # 1. Creamos un archivo MP3 falso para pasar la validación de path.exists() | ||
| fake_mp3 = tmp_path / "test.mp3" | ||
| fake_mp3.write_text("fake audio content") | ||
|
|
||
| # 2. Simulamos que ffmpeg existe y que la lectura del WAV temporal funciona | ||
| with ( | ||
| patch("sounddiff.formats.shutil.which", return_value="ffmpeg"), | ||
| patch("sounddiff.formats.subprocess.run"), | ||
| patch("sounddiff.formats.sf.info") as mock_info, | ||
| patch("sounddiff.formats.sf.read") as mock_read, | ||
| ): | ||
| # Configuramos el mock para simular lo que devolvería el WAV temporal | ||
| class MockInfo: | ||
| format = "WAV" | ||
| subtype = "PCM_16" | ||
|
|
||
| mock_info.return_value = MockInfo() | ||
| mock_read.return_value = (np.zeros((100, 2), dtype=np.float64), 44100) | ||
|
|
||
| # 3. Llamamos a tu función | ||
| _, meta = load_audio(fake_mp3) | ||
|
|
||
| # 4. LA COMPROBACIÓN FINAL: Debe decir MP3 y no WAV | ||
| assert meta.format_name == "MP3" | ||
|
Comment on lines
+59
to
+86
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick | 🔵 Trivial Test logic is sound; consider translating comments to English. The test correctly validates the core fix by mocking the ffmpeg transcode flow and asserting that The inline comments are in Spanish; for consistency with the English codebase, consider translating them: 📝 Suggested comment translations- # 1. Creamos un archivo MP3 falso para pasar la validación de path.exists()
+ # 1. Create a fake MP3 file to pass path.exists() validation
fake_mp3 = tmp_path / "test.mp3"
fake_mp3.write_text("fake audio content")
- # 2. Simulamos que ffmpeg existe y que la lectura del WAV temporal funciona
+ # 2. Simulate ffmpeg existing and temp WAV read succeeding
with patch("sounddiff.formats.shutil.which", return_value="ffmpeg"), \
...
- # Configuramos el mock para simular lo que devolvería el WAV temporal
+ # Configure mock to simulate what the temp WAV would return
...
- # 3. Llamamos a tu función
+ # 3. Call the function under test
_, meta = load_audio(fake_mp3)
- # 4. LA COMPROBACIÓN FINAL: Debe decir MP3 y no WAV
+ # 4. Final assertion: must report MP3, not WAV
assert meta.format_name == "MP3"
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
|
||
| def test_file_size_is_populated(self) -> None: | ||
| _, meta = load_audio(FIXTURES_DIR / "sine_a.wav") | ||
| assert meta.file_size is not None | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.