Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_image_encoding(self):
"""For compatibility with OS X/iTunes.
See https://github.com/beetbox/beets/issues/899#issuecomment-62437773
"""
for v23 in [True, False]:
mf = self._make_test(id3v23=v23)
try:
mf.images = [
mediafile.Image(b'data', desc=u""),
mediafile.Image(b'data', desc=u"foo"),
mediafile.Image(b'data', desc=u"\u0185"),
]
mf.save()
apic_frames = mf.mgfile.tags.getall('APIC')
encodings = dict([(f.desc, f.encoding) for f in apic_frames])
self.assertEqual(encodings, {
u"": mutagen.id3.Encoding.LATIN1,
u"foo": mutagen.id3.Encoding.LATIN1,
u"\u0185": mutagen.id3.Encoding.UTF16,
})
finally:
self._delete_test()
def test_image_encoding(self):
"""For compatibility with OS X/iTunes.
See https://github.com/beetbox/beets/issues/899#issuecomment-62437773
"""
for v23 in [True, False]:
mf = self._make_test(id3v23=v23)
try:
mf.images = [
mediafile.Image(b'data', desc=u""),
mediafile.Image(b'data', desc=u"foo"),
mediafile.Image(b'data', desc=u"\u0185"),
]
mf.save()
apic_frames = mf.mgfile.tags.getall('APIC')
encodings = dict([(f.desc, f.encoding) for f in apic_frames])
self.assertEqual(encodings, {
u"": mutagen.id3.Encoding.LATIN1,
u"foo": mutagen.id3.Encoding.LATIN1,
u"\u0185": mutagen.id3.Encoding.UTF16,
})
finally:
self._delete_test()
def setUp(self):
self.create_temp_dir()
self.key = "READ_ONLY_TEST"
self.field = mediafile.MediaField(
mediafile.MP3StorageStyle(self.key, read_only=True),
mediafile.MP4StorageStyle(
"----:com.apple.iTunes:" + self.key, read_only=True),
mediafile.StorageStyle(self.key, read_only=True),
mediafile.ASFStorageStyle(self.key, read_only=True),
)
if "read_only_test" not in mediafile.MediaFile.fields():
mediafile.MediaFile.add_field("read_only_test", self.field)
def __copy_file(self, dest_path, metadata):
# Copy files
resource_path = os.path.join(_common.RSRC, b'full.mp3')
shutil.copy(resource_path, dest_path)
medium = MediaFile(dest_path)
# Set metadata
for attr in metadata:
setattr(medium, attr, metadata[attr])
medium.save()
def test_write_extended_tag_from_item(self):
plugin = BeetsPlugin()
plugin.add_media_field('customtag', field_extension)
try:
mf = self._mediafile_fixture('empty')
self.assertIsNone(mf.customtag)
item = Item(path=mf.path, customtag=u'Gb')
item.write()
mf = mediafile.MediaFile(mf.path)
self.assertEqual(mf.customtag, u'Gb')
finally:
delattr(mediafile.MediaFile, 'customtag')
Item._media_fields.remove('customtag')
def test_delete_tag(self):
mediafile = self._mediafile_fixture('full')
keys = self.full_initial_tags.keys()
for key in set(keys) - set(['art', 'month', 'day']):
self.assertIsNotNone(getattr(mediafile, key))
for key in keys:
delattr(mediafile, key)
mediafile.save()
mediafile = MediaFile(mediafile.path)
for key in keys:
self.assertIsNone(getattr(mediafile, key))
def test_write_genre_list(self):
mediafile = self._mediafile_fixture('empty')
mediafile.genres = [u'one', u'two']
mediafile.save()
mediafile = MediaFile(mediafile.path)
assertCountEqual(self, mediafile.genres, [u'one', u'two'])
def test_embed_art_from_album(self):
self._setup_data()
album = self.add_album_fixture()
item = album.items()[0]
album.artpath = self.small_artpath
album.store()
self.run_command('embedart', '-y')
mediafile = MediaFile(syspath(item.path))
self.assertEqual(mediafile.images[0].data, self.image_data)
def test_write_dates(self):
mediafile = self._mediafile_fixture('full')
mediafile.date = datetime.date(2001, 1, 2)
mediafile.original_date = datetime.date(1999, 12, 30)
mediafile.save()
mediafile = MediaFile(mediafile.path)
self.assertEqual(mediafile.year, 2001)
self.assertEqual(mediafile.month, 1)
self.assertEqual(mediafile.day, 2)
self.assertEqual(mediafile.date, datetime.date(2001, 1, 2))
self.assertEqual(mediafile.original_year, 1999)
self.assertEqual(mediafile.original_month, 12)
self.assertEqual(mediafile.original_day, 30)
self.assertEqual(mediafile.original_date, datetime.date(1999, 12, 30))
def test_unicode_label_in_m4a(self):
self.mf.label = u'foo\xe8bar'
self.mf.save()
new_mf = mediafile.MediaFile(self.path)
self.assertEqual(new_mf.label, u'foo\xe8bar')