1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- import mutagen
- import pytest
- from symuid._tag_interface import MP4
- # pylint: disable=protected-access
- def test_set_comment(empty_mp4_path):
- iface = MP4(mutagen.File(empty_mp4_path))
- assert iface.get_comment() is None
- iface.set_comment('latin')
- assert iface.get_comment() == 'latin'
- iface.set_comment('mp4 你好')
- assert iface.get_comment() == 'mp4 你好'
- iface.save()
- iface_reread = MP4(mutagen.File(empty_mp4_path))
- assert iface_reread.get_comment() == 'mp4 你好'
- tags = mutagen.File(iface.track_path).tags
- assert len(tags) == 1
- assert tags.items()[0] == ('©cmt', ['mp4 你好'])
- def test__get_free_uuid(empty_mp4_path):
- uuid = b'h\x97\x8c_1?B\t\x9d\xa3$\xdf\xd0Y\xa1\xc2'
- mutagen_file = mutagen.File(empty_mp4_path)
- mutagen_file['----:foo:bar'] = mutagen.mp4.MP4FreeForm(
- dataformat=mutagen.mp4.AtomDataType.UUID, data=uuid)
- mutagen_file.save()
- mp4_iface = MP4(mutagen.File(empty_mp4_path))
- assert mp4_iface._get_free_uuid('foo:bar') == uuid
- def test_get_track_uuid(empty_mp4_path):
- uuid = b'h\x97\x8c_1?B\t\x9d\xa3$\xdf\xd0Y\xa1\xc2'
- mutagen_file = mutagen.File(empty_mp4_path)
- mutagen_file['----:symuid:uuid'] = mutagen.mp4.MP4FreeForm(
- dataformat=mutagen.mp4.AtomDataType.UUID, data=uuid)
- mutagen_file.save()
- mp4_iface = MP4(mutagen.File(empty_mp4_path))
- assert mp4_iface.get_track_uuid() == uuid
- @pytest.mark.parametrize(('nominator', 'denominator'), [
- (21, 42),
- (-21, 42),
- (21, -42),
- (-21, -42),
- (0, 42),
- ])
- def test_get_free_int_ratio(empty_mp4_path, nominator, denominator):
- mutagen_file = mutagen.File(empty_mp4_path)
- mutagen_file.tags['----:foo:bar'] = [
- mutagen.mp4.MP4FreeForm(dataformat=mutagen.mp4.AtomDataType.INTEGER,
- data=i.to_bytes(4, byteorder='big', signed=True))
- for i in (nominator, denominator)]
- mutagen_file.save()
- mp4_iface = MP4(mutagen.File(empty_mp4_path))
- assert mp4_iface.get_free_int_ratio('foo:bar') == (nominator, denominator)
|