1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- import pytest
- from symuid.tag_interface import ID3
- import mutagen
- 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'),
- ('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):
- iface = ID3(mutagen.File(os.path.join(tracks_dir_path, track_name)))
- assert expected_text == iface._get_single_text(tag_label)
- @pytest.mark.parametrize(('track_name', 'expected_comment'), [
- ('id3v2.4-empty.mp3', None),
- ('id3v2.4-typical.mp3', 'some comment'),
- ])
- 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 == ['你好']
|