|
@@ -1,4 +1,5 @@
|
|
|
import os
|
|
|
+import re
|
|
|
|
|
|
import mutagen
|
|
|
import pytest
|
|
@@ -16,14 +17,39 @@ def test_get_track_path(tracks_dir_path, track_name):
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize(('track_name', 'tag_label', 'expected_text'), [
|
|
|
- ('id3v2.4-empty.mp3', 'TPE1', None),
|
|
|
('id3v2.4-typical.mp3', 'TPE1', 'some artist'),
|
|
|
('id3v2.4-typical.mp3', 'COMM::eng', 'some comment'),
|
|
|
- ('id3v2.4-typical.mp3', 'COMM', None),
|
|
|
])
|
|
|
-def test__get_single_text(tracks_dir_path, track_name, tag_label, expected_text):
|
|
|
+def test__get_str(tracks_dir_path, track_name, tag_label, expected_text):
|
|
|
iface = ID3(mutagen.File(os.path.join(tracks_dir_path, track_name)))
|
|
|
- assert expected_text == iface._get_single_text(tag_label)
|
|
|
+ assert expected_text == iface._get_str(tag_label)
|
|
|
+
|
|
|
+
|
|
|
+@pytest.mark.parametrize(('track_name', 'tag_label'), [
|
|
|
+ ('id3v2.4-empty.mp3', 'TPE1'),
|
|
|
+ ('id3v2.4-typical.mp3', 'COMM'),
|
|
|
+])
|
|
|
+def test__get_str_missing(tracks_dir_path, track_name, tag_label):
|
|
|
+ iface = ID3(mutagen.File(os.path.join(tracks_dir_path, track_name)))
|
|
|
+ with pytest.raises(KeyError, match=re.escape(tag_label)):
|
|
|
+ iface._get_str(tag_label)
|
|
|
+
|
|
|
+
|
|
|
+def test__get_free_str(empty_id3_path):
|
|
|
+ mutagen_file = mutagen.File(empty_id3_path)
|
|
|
+ mutagen_file.tags.add(mutagen.id3.TXXX(
|
|
|
+ desc='foo',
|
|
|
+ text='bar',
|
|
|
+ ))
|
|
|
+ mutagen_file.save()
|
|
|
+ id3_iface = ID3(mutagen.File(empty_id3_path))
|
|
|
+ assert id3_iface._get_free_str('foo') == 'bar'
|
|
|
+
|
|
|
+
|
|
|
+def test__get_free_str_missing(empty_id3_path):
|
|
|
+ iface = ID3(mutagen.File(empty_id3_path))
|
|
|
+ with pytest.raises(KeyError, match=r'TXXX:foo'):
|
|
|
+ iface._get_free_str('foo')
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize(('track_name', 'expected_comment'), [
|
|
@@ -49,3 +75,35 @@ def test_set_comment(empty_id3_path):
|
|
|
assert isinstance(tag, mutagen.id3.COMM)
|
|
|
assert tag.lang == 'eng'
|
|
|
assert tag.text == ['你好']
|
|
|
+
|
|
|
+
|
|
|
+@pytest.mark.parametrize(('tag_label', 'tag_value', 'expected_value'), [
|
|
|
+ ('foo', '21/42', (21, 42)),
|
|
|
+ ('bar', '-1/4', (-1, 4)),
|
|
|
+ ('ham:egg', '0/-3', (0, -3)),
|
|
|
+])
|
|
|
+def test_get_free_int_ratio(empty_id3_path, tag_label, tag_value, expected_value):
|
|
|
+ mutagen_file = mutagen.File(empty_id3_path)
|
|
|
+ mutagen_file.tags.add(mutagen.id3.TXXX(
|
|
|
+ encoding=mutagen.id3.Encoding.LATIN1,
|
|
|
+ desc=tag_label,
|
|
|
+ text=[tag_value],
|
|
|
+ ))
|
|
|
+ mutagen_file.save()
|
|
|
+ id3_iface = ID3(mutagen.File(empty_id3_path))
|
|
|
+ assert id3_iface.get_free_int_ratio(tag_label) == expected_value
|
|
|
+
|
|
|
+
|
|
|
+@pytest.mark.parametrize(
|
|
|
+ ('tag_label', 'nominator', 'denominator', 'expected_tag_value'),
|
|
|
+ [('foo', 21, 42, '21/42'),
|
|
|
+ ('bar', -1, 4, '-1/4'),
|
|
|
+ ('ham:egg', 0, -3, '0/-3')],
|
|
|
+)
|
|
|
+def test_set_free_int_ratio(empty_id3_path, tag_label, nominator, denominator, expected_tag_value):
|
|
|
+ id3_iface = ID3(mutagen.File(empty_id3_path))
|
|
|
+ assert repr(id3_iface.set_free_int_ratio(tag_label, nominator, denominator))
|
|
|
+ id3_iface.save()
|
|
|
+ mutagen_file = mutagen.File(empty_id3_path)
|
|
|
+ assert len(mutagen_file.tags) == 1
|
|
|
+ assert mutagen_file.tags['TXXX:' + tag_label].text == [expected_tag_value]
|