diff options
| author | Yuval Adam <_@yuv.al> | 2026-07-24 12:11:54 +0200 |
|---|---|---|
| committer | Yuval Adam <_@yuv.al> | 2026-07-24 12:11:54 +0200 |
| commit | df594d42ad1206fcb246bedb1945949527d7e039 (patch) | |
| tree | a8fe0e95404d1712331c90cb5095f1df4844c513 /tests/test_persistence.py | |
Implement initial terminal-independent transcription core
Diffstat (limited to 'tests/test_persistence.py')
| -rw-r--r-- | tests/test_persistence.py | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/tests/test_persistence.py b/tests/test_persistence.py new file mode 100644 index 0000000..eecb378 --- /dev/null +++ b/tests/test_persistence.py @@ -0,0 +1,39 @@ +from datetime import datetime, timezone +from pathlib import Path +import tempfile +import unittest + +from parley.persistence import save_transcript + + +class PersistenceTests(unittest.TestCase): + def setUp(self) -> None: + self.temporary = tempfile.TemporaryDirectory() + self.directory = Path(self.temporary.name) / "transcripts" + self.now = datetime(2026, 7, 24, 12, 34, 56, 123456, timezone.utc) + + def tearDown(self) -> None: + self.temporary.cleanup() + + def test_writes_utf8_with_one_final_newline(self) -> None: + path = save_transcript("héllo\n\n", self.directory, clock=lambda: self.now) + self.assertEqual(path.read_text(encoding="utf-8"), "héllo\n") + self.assertEqual( + path.name, "transcript_2026-07-24_12-34-56_123456+0000.txt" + ) + + def test_uses_counter_on_collision(self) -> None: + first = save_transcript("one", self.directory, clock=lambda: self.now) + second = save_transcript("two", self.directory, clock=lambda: self.now) + self.assertNotEqual(first, second) + self.assertEqual(second.stem[-2:], "_1") + self.assertEqual(first.read_text(), "one\n") + self.assertEqual(second.read_text(), "two\n") + + def test_leaves_no_temporary_file(self) -> None: + save_transcript("text", self.directory, clock=lambda: self.now) + self.assertFalse(any(path.suffix == ".tmp" for path in self.directory.iterdir())) + + +if __name__ == "__main__": + unittest.main() |
