aboutsummaryrefslogtreecommitdiff
path: root/tests/test_audio.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test_audio.py')
-rw-r--r--tests/test_audio.py57
1 files changed, 57 insertions, 0 deletions
diff --git a/tests/test_audio.py b/tests/test_audio.py
new file mode 100644
index 0000000..a629224
--- /dev/null
+++ b/tests/test_audio.py
@@ -0,0 +1,57 @@
+"""Tests for audio helpers: speed parameters and chunk cleanup."""
+
+import tempfile
+import unittest
+from pathlib import Path
+
+from converter import config
+from converter.audio import cleanup_chunks, speed_export_params
+
+
+class SpeedExportParamsTests(unittest.TestCase):
+ def test_normal_speed_no_filter(self):
+ self.assertEqual(speed_export_params(1.0), [])
+
+ def test_simple_speedup(self):
+ self.assertEqual(speed_export_params(1.5), ["-filter:a", "atempo=1.5"])
+
+ def test_simple_slowdown(self):
+ self.assertEqual(speed_export_params(0.75), ["-filter:a", "atempo=0.75"])
+
+ def test_chained_speedup_beyond_2x(self):
+ self.assertEqual(speed_export_params(3.0), ["-filter:a", "atempo=2.0,atempo=1.5"])
+
+ def test_chained_slowdown_below_half(self):
+ self.assertEqual(speed_export_params(0.25), ["-filter:a", "atempo=0.5,atempo=0.5"])
+
+ def test_zero_speed_rejected(self):
+ with self.assertRaises(ValueError):
+ speed_export_params(0)
+
+ def test_negative_speed_rejected(self):
+ with self.assertRaises(ValueError):
+ speed_export_params(-1.5)
+
+
+class CleanupChunksTests(unittest.TestCase):
+ def test_removes_only_chunk_files(self):
+ with tempfile.TemporaryDirectory() as tmp:
+ chunks_dir = Path(tmp)
+ (chunks_dir / "chunk_0001.wav").write_bytes(b"stale")
+ (chunks_dir / "chunk_0002.wav").write_bytes(b"stale")
+ (chunks_dir / "keep.txt").write_bytes(b"keep")
+
+ original = config.CHUNKS_FOLDER
+ config.CHUNKS_FOLDER = chunks_dir
+ try:
+ cleanup_chunks()
+ finally:
+ config.CHUNKS_FOLDER = original
+
+ self.assertFalse((chunks_dir / "chunk_0001.wav").exists())
+ self.assertFalse((chunks_dir / "chunk_0002.wav").exists())
+ self.assertTrue((chunks_dir / "keep.txt").exists())
+
+
+if __name__ == "__main__":
+ unittest.main()