Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def save_metadata(filename, metadata):
f = picard.formats.open_(filename)
loaded_metadata = f._load(filename)
f._copy_loaded_metadata(loaded_metadata)
f._save(filename, metadata)
def test_cover_art_with_types(self):
expected = set('abcdefg'[:]) if self.supports_types else set('a')
f = picard.formats.open_(self.filename)
f._save(self.filename, self._cover_metadata())
f = picard.formats.open_(self.filename)
loaded_metadata = f._load(self.filename)
found = set([chr(img.data[-1]) for img in loaded_metadata.images])
self.assertEqual(expected, found)
def save_metadata(filename, metadata):
f = picard.formats.open_(filename)
f._save(filename, metadata)
def _move_additional_files(self, files):
f = picard.formats.open_(files['old_mp3'])
f._move_additional_files(files['old_mp3'], files['new_mp3'])
self._assertFile(files['new_img'])
self._assertNoFile(files['old_img'])
def _test_cover_art_types(self, filename, expect):
self._set_up(filename)
expect = {ord(char) for char in expect}
try:
f = picard.formats.open_(self.filename)
f._save(self.filename, self._cover_metadata())
f = picard.formats.open_(self.filename)
loaded_metadata = f._load(self.filename)
found = set()
for n, image in enumerate(loaded_metadata.images):
found.add(image.data[-1])
self.assertEqual(expect, found)
finally:
self._tear_down()
def _test_cover_art_types_only_front(self, filename, expect):
self._set_up(filename, {'embed_only_one_front_image': True})
expect = {ord(char) for char in expect}
try:
f = picard.formats.open_(self.filename)
f._save(self.filename, self._cover_metadata())
f = picard.formats.open_(self.filename)
loaded_metadata = f._load(self.filename)
found = set()
for n, image in enumerate(loaded_metadata.images):
found.add(image.data[-1])
self.assertEqual(expect, found)
finally:
self._tear_down()
def test_split_ext(self):
f = picard.formats.open_(self.filename)
self.assertEqual(f._fixed_splitext(f.filename), os.path.splitext(f.filename))
self.assertEqual(f._fixed_splitext(f.EXTENSIONS[0]), ('', f.EXTENSIONS[0]))
self.assertEqual(f._fixed_splitext('.test'), os.path.splitext('.test'))
self.assertNotEqual(f._fixed_splitext(f.EXTENSIONS[0]), os.path.splitext(f.EXTENSIONS[0]))
def test_guess_format(self):
temp_file = self.copy_of_original_testfile()
audio = picard.formats.guess_format(temp_file)
audio_original = picard.formats.open_(self.filename)
self.assertEqual(type(audio), type(audio_original))
def _test_cover_art(self, filename):
self._set_up(filename)
try:
source_types = ["front", "booklet"]
# Use reasonable large data > 64kb.
# This checks a mutagen error with ASF files.
tests = [
CoverArtImage(data=self.jpegdata + b"a" * 1024 * 128, types=source_types),
CoverArtImage(data=self.pngdata + b"a" * 1024 * 128, types=source_types),
]
for test in tests:
self._file_save_image(self.filename, test)
f = picard.formats.open_(self.filename)
loaded_metadata = f._load(self.filename)
image = loaded_metadata.images[0]
self.assertEqual(test.mimetype, image.mimetype)
self.assertEqual(test, image)
finally:
self._tear_down()