-
Notifications
You must be signed in to change notification settings - Fork 0
/
_unittest.py
102 lines (79 loc) · 2.89 KB
/
_unittest.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
import os
import time
import shutil
import tempfile
from pathlib import Path
from random import randint
import gp_merge_clips
# The first 3 movies on the card are not part of sequence
TEST_FRAMES_1 = (10010, 10011, 10012,
10013, 20013, 30013,
10014, 10015,
10016, 20016, 30016, 40016,
10017, 10018)
# The first movies on the card are part of a sequence
TEST_FRAMES_2 = (10013, 20013, 30013,
10014, 10015,
10016, 20016, 30016, 40016,
10017, 10018)
# There are no sequences found
TEST_FRAMES_3 = (10010, 10011, 10012,
10013, 10014, 10015)
# Let's ensure that a single shot doesn't mess up the logic
TEST_FRAMES_4 = (10013, 20013, 30013)
def _cleanup(path):
if path is not None:
shutil.rmtree(path)
def _create_test_files(frames, tmpdir):
for frame in frames:
name = 'GH{:>06d}.{}'.format(frame, gp_merge_clips.VALID[0].upper())
Path(os.path.join(tmpdir, name)).touch()
time.sleep(0.1)
def _test_results_1(results):
"Test 1"
def test_clip_names(clips, names):
for i,j in zip(clips, names):
assert os.path.basename(i) == j, "{} != {}".format(os.path.basename(i), j)
assert len(results) == 2, "Incorrect number of collections"
assert 'GH010013' in results, "Missing 'GH010013'"
assert len(results['GH010013']['clips']) == 3, "Incorrect number of clips for 'GH010013'"
test_clip_names(results['GH010013']['clips'],
('GH010013.MP4', 'GH020013.MP4', 'GH030013.MP4'))
test_clip_names(results['GH010016']['clips'],
('GH010016.MP4', 'GH020016.MP4', 'GH030016.MP4', 'GH040016.MP4'))
assert 'GH010016' in results, "Missing 'GH010016'"
assert len(results['GH010016']['clips']) == 4, "Incorrect number of clips for 'GH010016'"
def _test_results_2(results):
"Test 2"
_test_results_1(results)
def _test_results_3(results):
"Test 3"
assert len(results) == 0, "Collections found, there should not be any"
def _test_results_4(results):
"Test 4"
assert len(results) == 1, "Single collection found"
def _main():
tmpdir = None
func = None
mapping = (
(TEST_FRAMES_1, _test_results_1),
(TEST_FRAMES_2, _test_results_2),
(TEST_FRAMES_3, _test_results_3),
(TEST_FRAMES_4, _test_results_4)
)
try:
for frames, func in mapping:
tmpdir = tempfile.mkdtemp()
_create_test_files(frames, tmpdir)
results = gp_merge_clips.merge_clips(tmpdir, dryrun=True)
func(results)
print("{} has passed".format(func.__doc__))
except Exception:
if func is not None:
print("ERROR: {} has failed".format(func.__doc__))
raise
finally:
_cleanup(tmpdir)
print("All tests have passed")
if __name__ == '__main__':
_main()