-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_transcode.py
More file actions
66 lines (53 loc) · 1.94 KB
/
test_transcode.py
File metadata and controls
66 lines (53 loc) · 1.94 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
from dataclasses import dataclass, field
from pathlib import Path
import json
import shutil
from unittest.mock import patch
import ffmpeg
import app
import transcode
import common
fixtures = Path("fixtures")
@dataclass
class MockedStub:
transcriptions: dict = field(default_factory=dict)
transcode_stub = MockedStub()
@patch("transcode.app", new=transcode_stub)
@patch("common.app", new=transcode_stub)
@patch("common.transcriptions", new=dict())
def test_transcode(transcription_id="overgrown.mp3"):
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)
updates = list(
transcode.transcode.local(
transcription_id,
media_path=media_path,
force_reprocessing=True,
)
)
assert len(updates) >= 3
assert updates[-2].percent_done == 100
assert updates[-1].percent_done == 100
track = updates[-1].track
assert track.title == "Overgrown"
assert track.artist == "Totonoko"
assert track.album == "Totonoko EP"
assert track.comment == "Totonoko comment one, comment two"
assert track.date == "2014"
probe = ffmpeg.probe(t.transcoded_file)
assert probe["format"]["format_name"] == "wav"
assert int(float(probe["format"]["duration"])) == 222