blob: 916aac2b593d0c2a2f95a2d131cfabaccf73276c (
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
|
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()
|