blob: e79bb2b761048780a45d4d69384f4dabd6ff5637 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
import unittest
from parley.errors import TranscriptionError
from parley.transcription import parse_jsonl
class ParseJsonlTests(unittest.TestCase):
def test_skips_header_and_malformed_lines(self) -> None:
output = "\n".join(
[
"runtime diagnostic",
'{"type":"batch_header","count":1}',
'{"file":"recording.wav","text":"hello world"}',
]
)
self.assertEqual(parse_jsonl(output), "hello world")
def test_reports_error_row(self) -> None:
with self.assertRaisesRegex(TranscriptionError, "decoder failed"):
parse_jsonl('{"file":"x.wav","error":"decoder failed","text":""}')
def test_rejects_output_without_result(self) -> None:
with self.assertRaisesRegex(TranscriptionError, "no transcript"):
parse_jsonl('{"type":"batch_header"}\nnot json')
def test_accepts_empty_transcript(self) -> None:
self.assertEqual(parse_jsonl('{"text":""}'), "")
if __name__ == "__main__":
unittest.main()
|