-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_filename_group_normaliser.py
60 lines (50 loc) · 2.43 KB
/
test_filename_group_normaliser.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
from unittest import TestCase
from filename_parser import FilenameParser
from filename_group_normaliser import FilenameGroupNormaliser
from test_filename_parser import CASES as NEGATIVE_CASES
CASES = [
([
'01 - UPHONIX - Shimmer - HEART TWICE 008.wav',
'02 - UPHONIX - Purple Dub - HEART TWICE 008.wav',
], [
('HEART TWICE 008', 'UPHONIX', 'Shimmer'),
('HEART TWICE 008', 'UPHONIX', 'Purple Dub'),
]), ([
'SEXTASY - check point - HEART TWICE 006.wav',
'SEXTASY - far beyond - HEART TWICE 006.wav',
'SEXTASY - give it back - HEART TWICE 006.wav',
], [
('HEART TWICE 006', 'SEXTASY', 'check point'),
('HEART TWICE 006', 'SEXTASY', 'far beyond'),
('HEART TWICE 006', 'SEXTASY', 'give it back'),
]),
]
class FilenameGroupNormaliserTestCase(TestCase):
def test_filename_group_normalising(self):
for infiles, label_artist_titles in CASES:
fnps = []
for infile in infiles:
with self.subTest(msg=infile):
fnp = FilenameParser(infile)
assert fnp.analyse()
fnps.append(fnp)
assert len(fnps) == len(infiles)
fnp_group = FilenameGroupNormaliser(fnps)
mutation_count = fnp_group.normalise()
assert mutation_count > 0
with self.subTest(msg=', '.join(infiles)):
for (fnp, lat) in zip(fnps, label_artist_titles):
assert fnp.label == lat[0], "label: expected {}, got {}".format(lat[0], fnp.label)
assert fnp.artist == lat[1], "artist: expected {}, got {}".format(lat[1], fnp.artist)
assert fnp.title == lat[2], "title: expected {}, got {}".format(lat[2], fnp.title)
def test_filename_group_normalising_doesnt_break_ordinary_things(self):
# this is a little contorted because the NEGATIVE_CASES are pairs of (filename, (label, artist, title))
# convert it to a list of (FilenameParser(filename), (label, artist, title)) and analyse them
fnps = [(FilenameParser(infile), lat) for infile, lat in NEGATIVE_CASES]
assert len(fnps) == len(NEGATIVE_CASES)
for fnp in fnps:
fnp[0].analyse()
# now we need just a list of the FilenameParsers.
fnp_group = FilenameGroupNormaliser([fnp[0] for fnp in fnps])
mutation_count = fnp_group.normalise()
assert mutation_count == 0