13 |
|
|
14 |
class TaggingTest(TestCase): |
class TaggingTest(TestCase): |
15 |
def setUp(self): |
def setUp(self): |
16 |
|
# we should use setUpClass, but it's only available in python 2.7 |
17 |
|
# so we workaround this by making sure we call setUp code only once |
18 |
|
# FIXME: blet, reinitializina visa objekta pries kiekviena metoda |
19 |
|
if not hasattr(self, 'field_test_map') and not hasattr(self, 'test_files'): |
20 |
|
print "WTF" |
21 |
|
if getattr(self, 'initialized', None): |
22 |
|
return |
23 |
|
|
24 |
|
self.initialized = True |
25 |
# list of tag properties we try to set/get |
# list of tag properties we try to set/get |
26 |
# (<property name>, <property type>, <test value>) |
# (<property name>, <property type>, <test value>) |
27 |
# if <test value> == None, default test value according to type will be used |
# if <test value> == None, default test value according to type will be used |
28 |
self.field_test_map = [ |
self.field_test_map = ( |
29 |
# basic fields |
# basic fields |
30 |
('album', 'str', None), |
#('album', 'str', None), |
31 |
('comment', 'str', None), |
#('comment', 'str', None), |
32 |
('title', 'str', None), |
#('title', 'str', None), |
33 |
('track', 'int', None), |
#('track', 'int', None), |
34 |
('year', 'int', None), |
#('year', 'int', None), |
35 |
# extended fields |
# extended fields |
36 |
('album_artists', 'array', None), |
('album_artists', 'array', None), |
37 |
('album_artists_sort', 'array', None), |
('album_artists_sort', 'array', None), |
60 |
('performers', 'array', None), |
('performers', 'array', None), |
61 |
('performers_sort', 'array', None), |
('performers_sort', 'array', None), |
62 |
('title_sort', 'str', None), |
('title_sort', 'str', None), |
63 |
('track_count', 'int', None)] |
#('track_count', 'int', None) |
64 |
|
) |
65 |
base_dir = os.path.dirname(os.path.dirname(__file__)) |
base_dir = os.path.dirname(os.path.dirname(__file__)) |
66 |
orig_test_dir = os.path.join(base_dir, 'tests', 'music_tagger') |
orig_test_dir = os.path.join(base_dir, 'tests', 'music_tagger') |
67 |
# files for testing (should be in tests/music_tagger directory) |
# files for testing (should be in tests/music_tagger directory) |
68 |
self.test_files = ('l.flac', 'l.mp3', 'l.mpc', 'l.ogg')#, 'l.ape') |
#self.test_files = ('l.flac', 'l.mp3', 'l.mpc', 'l.ogg')#, 'l.ape') |
69 |
|
self.test_files = ('l.mpc',) |
70 |
# we don't want to damage our test files during the test, so just copy them |
# we don't want to damage our test files during the test, so just copy them |
71 |
self.test_dir = tempfile.mkdtemp() |
self.test_dir = tempfile.mkdtemp() |
72 |
|
print "test dir is '%s'" % self.test_dir |
73 |
for file in self.test_files: |
for file in self.test_files: |
74 |
shutil.copy(os.path.join(orig_test_dir, file), os.path.join(self.test_dir, file)) |
shutil.copy(os.path.join(orig_test_dir, file), os.path.join(self.test_dir, file)) |
75 |
|
|
76 |
def tearDown(self): |
def tearDown(self): |
77 |
shutil.rmtree(self.test_dir, True) |
# FIXME: how to make sure this is called only after all test methods are run??? |
78 |
|
# shutil.rmtree(self.test_dir, True) |
79 |
|
pass |
80 |
|
|
81 |
def test1_fields_set_get(self): |
def test1_fields_set_get(self): |
82 |
""" |
""" |
85 |
""" |
""" |
86 |
def test_field(tag, field, test_value=None): |
def test_field(tag, field, test_value=None): |
87 |
if not test_value: |
if not test_value: |
88 |
test_value = u'string with some ąčę' |
test_value = u'string with some ąčę %d' % random.randint(1, 100) |
89 |
setattr(tag, field, test_value) |
setattr(tag, field, test_value) |
90 |
cached_value = getattr(tag, field) |
cached_value = getattr(tag, field) |
91 |
self.assertEqual(test_value, cached_value) |
self.assertEqual(test_value, cached_value) |
109 |
for test_filename in self.test_files: |
for test_filename in self.test_files: |
110 |
print "testing %s" % test_filename |
print "testing %s" % test_filename |
111 |
filename = os.path.join(self.test_dir, test_filename) |
filename = os.path.join(self.test_dir, test_filename) |
112 |
|
print "f1: %s" % filename |
113 |
file = MetaFile(filename) |
file = MetaFile(filename) |
114 |
tag = file.tag |
tag = file.tag |
115 |
mem = dict() |
mem = dict() |
128 |
mem[prop] = value |
mem[prop] = value |
129 |
|
|
130 |
# save and reopen |
# save and reopen |
131 |
|
print "before save" |
132 |
file.save() |
file.save() |
133 |
file = MetaFile(filename) |
del file |
134 |
tag = file.tag |
file2 = MetaFile(filename) |
135 |
|
tag2 = file2.tag |
136 |
|
print "f2: %s" % filename |
137 |
|
for k in tag2.map.keys(): |
138 |
|
print k |
139 |
# check what we set previously |
# check what we set previously |
140 |
for prop, value in mem.items(): |
for prop, value in mem.items(): |
141 |
err_msg = "property '%s' did not have correct value after rereading file '%s'" % (prop, test_filename) |
#print prop |
142 |
self.assertEqual(value, getattr(tag, prop), err_msg) |
#err_msg = "property '%s' did not have correct value after rereading file '%s'" % (prop, test_filename) |
143 |
|
self.assertEqual(value, getattr(tag2, prop))#, err_msg) |
144 |
|
|
145 |
def test2_fields_copy(self): |
def test2_fields_copy(self): |
146 |
""" |
""" |