-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaudio_test.py
74 lines (64 loc) · 2.05 KB
/
audio_test.py
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
71
72
73
74
from audio import download_audio, container_audio
from contextlib import contextmanager
from filecmp_custom import cmp
from os import path, remove, getcwd, chdir
from parameterized import parameterized
from unittest import main, TestCase
video_path = "4TLFaQWcqH8.webm"
video_path_expected = "4TLFaQWcqH8_expected_video.webm"
cover_path = "4TLFaQWcqH8.png"
cover_path_expected = "4TLFaQWcqH8_expected.png"
cover_path_expected_compressed = "4TLFaQWcqH8_expected_compressed.png"
url = "https://music.youtube.com/watch?v=4TLFaQWcqH8"
@contextmanager
def change_working_directory(new_dir):
current_dir = getcwd()
chdir(new_dir)
try:
yield
finally:
chdir(current_dir)
class CoverTestCase(TestCase):
@parameterized.expand(
[
(
"m4a",
"4TLFaQWcqH8.m4a",
"4TLFaQWcqH8.m4a",
"4TLFaQWcqH8_expected_audio.m4a",
"4TLFaQWcqH8_expected_audio.m4a",
"141",
),
(
"opus",
"4TLFaQWcqH8.webm",
"4TLFaQWcqH8.opus",
"4TLFaQWcqH8_expected_audio.webm",
"4TLFaQWcqH8_expected_audio.opus",
"774",
),
]
)
def test_cases(
self,
name,
audio_path_audio,
audio_path,
audio_path_expected_audio,
audio_path_expected,
format,
):
with change_working_directory("test"):
for file_path in [audio_path_audio, audio_path]:
if path.exists(file_path):
remove(file_path)
# Test download audio
audio_path_test = download_audio(url, format=format)
self.assertTrue(
cmp(audio_path_test, audio_path_expected_audio, shallow=False)
)
# Test container audio
audio_path_test = container_audio(audio_path_test)
self.assertTrue(cmp(audio_path_test, audio_path_expected, shallow=False))
if __name__ == "__main__":
main()