35 lines
1.2 KiB
Python
35 lines
1.2 KiB
Python
from __future__ import annotations
|
|
|
|
from pathlib import Path
|
|
import tempfile
|
|
import unittest
|
|
|
|
from pi_dictate_service.live_smoke import MAX_SAMPLE_BYTES, _read_sample
|
|
|
|
|
|
class LiveSmokeTests(unittest.TestCase):
|
|
def test_reads_one_bounded_even_pcm_fixture(self) -> None:
|
|
with tempfile.TemporaryDirectory() as directory:
|
|
sample = Path(directory) / "sample.pcm"
|
|
sample.write_bytes(b"\x00\x01" * 100)
|
|
self.assertEqual(_read_sample(sample), sample.read_bytes())
|
|
|
|
def test_rejects_symlink_odd_and_oversized_fixtures(self) -> None:
|
|
with tempfile.TemporaryDirectory() as directory:
|
|
root = Path(directory)
|
|
valid = root / "valid.pcm"
|
|
valid.write_bytes(b"\x00\x00")
|
|
link = root / "link.pcm"
|
|
link.symlink_to(valid)
|
|
odd = root / "odd.pcm"
|
|
odd.write_bytes(b"x")
|
|
oversized = root / "oversized.pcm"
|
|
oversized.write_bytes(b"x" * (MAX_SAMPLE_BYTES + 2))
|
|
for path in (link, odd, oversized):
|
|
with self.subTest(path=path), self.assertRaises((OSError, ValueError)):
|
|
_read_sample(path)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|