diff options
Diffstat (limited to 'tests/test_storage.py')
| -rw-r--r-- | tests/test_storage.py | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/tests/test_storage.py b/tests/test_storage.py new file mode 100644 index 0000000..389f199 --- /dev/null +++ b/tests/test_storage.py @@ -0,0 +1,33 @@ +import os +import subprocess +from datetime import datetime, timezone + +import numpy as np + +from mic_clipper.storage import ClipWriter + + +def test_writer_creates_private_opus_clip_in_segment_start_date(tmp_path): + started_at = datetime(2026, 9, 29, 23, 59, 59, tzinfo=timezone.utc) + samples = np.sin(np.linspace(0, 100, 16_000, dtype=np.float32)) + writer = ClipWriter(tmp_path) + + clip = writer.open(started_at) + clip.write(samples) + clip.close() + + destination = tmp_path / "2026-09-29" + files = list(destination.glob("*.opus")) + assert len(files) == 1 + assert files[0].name.startswith("23-59-59") + assert os.stat(destination).st_mode & 0o777 == 0o700 + assert os.stat(files[0]).st_mode & 0o777 == 0o600 + assert files[0].read_bytes()[:4] == b"OggS" + assert b"OpusHead" in files[0].read_bytes()[:128] + + decoded = subprocess.run( + ["ffmpeg", "-v", "error", "-i", str(files[0]), "-f", "f32le", "pipe:1"], + check=True, + capture_output=True, + ) + assert len(decoded.stdout) > 0 |
