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_invalid_descriptor(self):
with self.assertRaises(ValueError) as cm:
mediafile.MediaFile.add_field('somekey', True)
self.assertIn(u'must be an instance of MediaField',
six.text_type(cm.exception))
def test_overwrite_property(self):
with self.assertRaises(ValueError) as cm:
mediafile.MediaFile.add_field('artist', mediafile.MediaField())
self.assertIn(u'property "artist" already exists',
six.text_type(cm.exception))
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 add_media_field(self, name, descriptor):
"""Add a field that is synchronized between media files and items.
When a media field is added ``item.write()`` will set the name
property of the item's MediaFile to ``item[name]`` and save the
changes. Similarly ``item.read()`` will set ``item[name]`` to
the value of the name property of the media file.
``descriptor`` must be an instance of ``mediafile.MediaField``.
"""
# Defer import to prevent circular dependency
from beets import library
mediafile.MediaFile.add_field(name, descriptor)
library.Item._media_fields.add(name)