forked from ercanserteli/condenser
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
149 lines (118 loc) · 5.22 KB
/
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
import json
import subprocess as sp
import unittest
import os
import shutil
import inspect
delete_outputs = True
def current_function_name():
return inspect.currentframe().f_back.f_code.co_name
def config_set(key, val):
shutil.copy("config.json", "config.json.bak")
with open("config.json", "r", encoding="utf-8") as f:
config = json.load(f)
config[key] = val
with open("config.json", "w", encoding="utf-8") as f:
json.dump(config, f)
def restore_config():
if os.path.exists("config.json.bak"):
shutil.copy("config.json.bak", "config.json")
os.remove("config.json.bak")
def create_test_class(base_class, output_format):
# noinspection PyPep8Naming
class TestClass(base_class):
_output_format = output_format
@classmethod
def setUpClass(cls):
print("Setting output format to {}".format(cls._output_format))
config_set("output_format", cls._output_format)
@classmethod
def tearDownClass(cls):
super().tearDownClass()
restore_config()
return TestClass
class TestSinglesBase(unittest.TestCase):
_output_format = "mp3"
@classmethod
def tearDownClass(cls):
if delete_outputs:
for filename in ["test_vids/1a1s_con", "test_vids/3a1s_con", "test_vids/1a0s_con"]:
try:
os.remove("{}.{}".format(filename, cls._output_format))
except Exception:
pass
def test1a1s(self):
print(current_function_name())
result = sp.run(["python", "condenser.py", "test_vids/1a1s.mkv"], capture_output=True)
msg = str(result.stdout) + "\n" + str(result.stderr)
print(result.stdout)
self.assertEqual(result.returncode, 0, msg)
self.assertIn("Finished", str(result.stdout), msg)
def test3a1s(self):
print(current_function_name())
result = sp.run(["python", "condenser.py", "test_vids/3a1s.mkv"], capture_output=True)
msg = str(result.stdout) + "\n" + str(result.stderr)
print(result.stdout)
self.assertEqual(result.returncode, 0, msg)
self.assertIn("Finished", str(result.stdout), msg)
def test1a0s(self):
print(current_function_name())
result = sp.run(["python", "condenser.py", "test_vids/1a0s.mkv"], capture_output=True)
msg = str(result.stdout) + "\n" + str(result.stderr)
print(result.stdout)
self.assertEqual(result.returncode, 0, msg)
self.assertIn("Finished", str(result.stdout), msg)
# def test3a2s(self):
# print(current_function_name())
# result = sp.run(["python", "condenser.py", "test_vids/3a2s.mkv"], capture_output=True)
# msg = str(result.stdout) + "\n" + str(result.stderr)
# print(result.stdout)
# self.assertEqual(result.returncode, 0, msg)
# self.assertIn("Finished", str(result.stdout), msg)
class TestFoldersBase(unittest.TestCase):
@classmethod
def tearDownClass(cls):
if delete_outputs:
for filename in ["test_vids/1a1s_con", "test_vids/3a1s_con", "test_vids/3a2s_con", "test_vids/1a0s_con",
"test_vids/mix_con"]:
shutil.rmtree(filename, ignore_errors=True)
def test1a1s(self):
print(current_function_name())
result = sp.run(["python", "condenser.py", "test_vids/1a1s"], capture_output=True)
msg = str(result.stdout) + "\n" + str(result.stderr)
print(result.stdout)
self.assertEqual(result.returncode, 0, msg)
self.assertIn("Finished", str(result.stdout), msg)
def test3a1s(self):
print(current_function_name())
result = sp.run(["python", "condenser.py", "test_vids/3a1s"], capture_output=True)
msg = str(result.stdout) + "\n" + str(result.stderr)
print(result.stdout)
self.assertEqual(result.returncode, 0, msg)
self.assertIn("Finished", str(result.stdout), msg)
def test3a2s(self):
print(current_function_name())
result = sp.run(["python", "condenser.py", "test_vids/3a2s"], capture_output=True)
msg = str(result.stdout) + "\n" + str(result.stderr)
print(result.stdout)
self.assertEqual(result.returncode, 0, msg)
self.assertIn("Finished", str(result.stdout), msg)
def test1a0s(self):
print(current_function_name())
result = sp.run(["python", "condenser.py", "test_vids/1a0s"], capture_output=True)
msg = str(result.stdout) + "\n" + str(result.stderr)
print(result.stdout)
self.assertEqual(result.returncode, 0, msg)
self.assertIn("Finished", str(result.stdout), msg)
def testmix(self):
print(current_function_name())
result = sp.run(["python", "condenser.py", "test_vids/mix"], capture_output=True)
msg = str(result.stdout) + "\n" + str(result.stderr)
print(result.stdout)
self.assertEqual(result.returncode, 0, msg)
# self.assertIn("Videos in folder are not uniform", str(result.stdout), msg)
self.assertIn("Finished", str(result.stdout), msg)
TestSinglesFLAC = create_test_class(TestSinglesBase, "flac")
TestFoldersFLAC = create_test_class(TestFoldersBase, "flac")
if __name__ == '__main__':
unittest.main()