|
@@ -7,6 +7,23 @@ import os
|
|
|
import shutil
|
|
|
|
|
|
|
|
|
+@pytest.fixture
|
|
|
+def empty_id3_iface(tmpdir, tracks_dir_path):
|
|
|
+ p = tmpdir.join('empty.mp3').strpath
|
|
|
+ shutil.copyfile(
|
|
|
+ src=os.path.join(tracks_dir_path, 'id3v2.4-empty.mp3'),
|
|
|
+ dst=p,
|
|
|
+ )
|
|
|
+ return ID3(mutagen.File(p))
|
|
|
+
|
|
|
+
|
|
|
+@pytest.mark.parametrize('track_name', ['id3v2.4-empty.mp3'])
|
|
|
+def test_get_track_path(tracks_dir_path, track_name):
|
|
|
+ track_path = os.path.join(tracks_dir_path, track_name)
|
|
|
+ iface = ID3(mutagen.File(track_path))
|
|
|
+ assert track_path == iface.track_path
|
|
|
+
|
|
|
+
|
|
|
@pytest.mark.parametrize(('track_name', 'tag_label', 'expected_text'), [
|
|
|
('id3v2.4-empty.mp3', 'TPE1', None),
|
|
|
('id3v2.4-typical.mp3', 'TPE1', 'some artist'),
|
|
@@ -25,3 +42,18 @@ def test__get_single_text(tracks_dir_path, track_name, tag_label, expected_text)
|
|
|
def test_get_comment(tracks_dir_path, track_name, expected_comment):
|
|
|
iface = ID3(mutagen.File(os.path.join(tracks_dir_path, track_name)))
|
|
|
assert expected_comment == iface.get_comment()
|
|
|
+
|
|
|
+
|
|
|
+def test_set_comment(empty_id3_iface):
|
|
|
+ assert None == empty_id3_iface.get_comment()
|
|
|
+ empty_id3_iface.set_comment('latin')
|
|
|
+ assert 'latin' == empty_id3_iface.get_comment()
|
|
|
+ empty_id3_iface.set_comment('你好')
|
|
|
+ assert '你好' == empty_id3_iface.get_comment()
|
|
|
+ empty_id3_iface.save()
|
|
|
+ tags = mutagen.File(empty_id3_iface.track_path).tags
|
|
|
+ assert len(tags) == 1
|
|
|
+ tag = tags.values()[0]
|
|
|
+ assert isinstance(tag, mutagen.id3.COMM)
|
|
|
+ assert tag.lang == 'eng'
|
|
|
+ assert tag.text == ['你好']
|