-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_annotate.py
More file actions
70 lines (60 loc) · 2.32 KB
/
test_annotate.py
File metadata and controls
70 lines (60 loc) · 2.32 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
from dataclasses import dataclass, field
from pathlib import Path
import json
import shutil
from unittest.mock import patch
import app
from annotate import annotate
import common
fixtures = Path("fixtures")
@dataclass
class MockedStub:
transcriptions: dict = field(default_factory=dict)
annotate_stub = MockedStub()
@patch("annotate.app", new=annotate_stub)
@patch("common.app", new=annotate_stub)
@patch("common.transcriptions", new=dict())
def test_annotate_one_speaker(transcription_id="one.wav"):
with common.tmpdir_scope() as tmp:
media_path = Path(tmp)
with patch("common.db", new=common.Store(media_path)):
from_file = fixtures / transcription_id
to_file = media_path / transcription_id
shutil.copyfile(from_file, to_file)
t = common.Transcription(
transcription_id=transcription_id,
path=to_file,
upload=common.UploadInfo(
filename="file.name",
content_type="audio/mp3",
size_bytes=15,
),
)
common.db.create(t)
diarization = annotate.local(transcription_id)
assert len(diarization.turns) == 1
assert diarization.turns[0].speaker == "Speaker"
@patch("annotate.app", new=annotate_stub)
@patch("common.app", new=annotate_stub)
@patch("common.transcriptions", new=dict())
def test_annotate_two_speakers(transcription_id="two.wav"):
with common.tmpdir_scope() as tmp:
media_path = Path(tmp)
with patch("common.db", new=common.Store(media_path)):
from_file = fixtures / transcription_id
to_file = media_path / transcription_id
shutil.copyfile(from_file, to_file)
t = common.Transcription(
transcription_id=transcription_id,
path=to_file,
upload=common.UploadInfo(
filename="file.name",
content_type="audio/mp3",
size_bytes=15,
),
)
common.db.create(t)
diarization = annotate.local(transcription_id)
assert len(diarization.turns) == 2
assert diarization.turns[0].speaker == "Speaker One"
assert diarization.turns[1].speaker == "Speaker Two"