本文整理汇总了Python中mutagen.flac.FLAC.values方法的典型用法代码示例。如果您正苦于以下问题:Python FLAC.values方法的具体用法?Python FLAC.values怎么用?Python FLAC.values使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mutagen.flac.FLAC
的用法示例。
在下文中一共展示了FLAC.values方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TFLAC
# 需要导入模块: from mutagen.flac import FLAC [as 别名]
# 或者: from mutagen.flac.FLAC import values [as 别名]
class TFLAC(TestCase):
SAMPLE = os.path.join("tests", "data", "silence-44-s.flac")
NEW = SAMPLE + ".new"
def setUp(self):
shutil.copy(self.SAMPLE, self.NEW)
self.failUnlessEqual(open(self.SAMPLE).read(), open(self.NEW).read())
self.flac = FLAC(self.NEW)
def test_delete(self):
self.failUnless(self.flac.tags)
self.flac.delete()
self.failIf(self.flac.tags)
flac = FLAC(self.NEW)
self.failIf(flac.tags)
def test_module_delete(self):
delete(self.NEW)
flac = FLAC(self.NEW)
self.failIf(flac.tags)
def test_info(self):
self.failUnlessAlmostEqual(FLAC(self.NEW).info.length, 3.7, 1)
def test_keys(self):
self.failUnlessEqual(self.flac.keys(), self.flac.tags.keys())
def test_values(self):
self.failUnlessEqual(self.flac.values(), self.flac.tags.values())
def test_items(self):
self.failUnlessEqual(self.flac.items(), self.flac.tags.items())
def test_vc(self):
self.failUnlessEqual(self.flac['title'][0], 'Silence')
def test_write_nochange(self):
f = FLAC(self.NEW)
f.save()
self.failUnlessEqual(open(self.SAMPLE).read(), open(self.NEW).read())
def test_write_changetitle(self):
f = FLAC(self.NEW)
f["title"] = "A New Title"
f.save()
f = FLAC(self.NEW)
self.failUnlessEqual(f["title"][0], "A New Title")
def test_write_changetitle_unicode_value(self):
f = FLAC(self.NEW)
f["title"] = u"A Unicode Title \u2022"
f.save()
f = FLAC(self.NEW)
self.failUnlessEqual(f["title"][0], u"A Unicode Title \u2022")
def test_write_changetitle_unicode_key(self):
f = FLAC(self.NEW)
f[u"title"] = "A New Title"
f.save()
f = FLAC(self.NEW)
self.failUnlessEqual(f[u"title"][0], "A New Title")
def test_write_changetitle_unicode_key_and_value(self):
f = FLAC(self.NEW)
f[u"title"] = u"A Unicode Title \u2022"
f.save()
f = FLAC(self.NEW)
self.failUnlessEqual(f[u"title"][0], u"A Unicode Title \u2022")
def test_force_grow(self):
f = FLAC(self.NEW)
f["faketag"] = ["a" * 1000] * 1000
f.save()
f = FLAC(self.NEW)
self.failUnlessEqual(f["faketag"], ["a" * 1000] * 1000)
def test_force_shrink(self):
self.test_force_grow()
f = FLAC(self.NEW)
f["faketag"] = "foo"
f.save()
f = FLAC(self.NEW)
self.failUnlessEqual(f["faketag"], ["foo"])
def test_add_vc(self):
f = FLAC(os.path.join("tests", "data", "no-tags.flac"))
self.failIf(f.tags)
f.add_tags()
self.failUnless(f.tags == [])
self.failUnlessRaises(ValueError, f.add_tags)
def test_add_vc_implicit(self):
f = FLAC(os.path.join("tests", "data", "no-tags.flac"))
self.failIf(f.tags)
f["foo"] = "bar"
self.failUnless(f.tags == [("foo", "bar")])
self.failUnlessRaises(ValueError, f.add_tags)
def test_ooming_vc_header(self):
# issue 112: Malformed FLAC Vorbis header causes out of memory error
# http://code.google.com/p/mutagen/issues/detail?id=112
#.........这里部分代码省略.........
示例2: TFLAC
# 需要导入模块: from mutagen.flac import FLAC [as 别名]
# 或者: from mutagen.flac.FLAC import values [as 别名]
class TFLAC(TestCase):
SAMPLE = os.path.join(DATA_DIR, "silence-44-s.flac")
def setUp(self):
self.NEW = get_temp_copy(self.SAMPLE)
self.flac = FLAC(self.NEW)
def tearDown(self):
os.unlink(self.NEW)
def test_zero_samples(self):
# write back zero sample count and load again
self.flac.info.total_samples = 0
self.flac.save()
new = FLAC(self.flac.filename)
assert new.info.total_samples == 0
assert new.info.bitrate == 0
assert new.info.length == 0.0
def test_bitrate(self):
assert self.flac.info.bitrate == 101430
old_file_size = os.path.getsize(self.flac.filename)
self.flac.save(padding=lambda x: 9999)
new_flac = FLAC(self.flac.filename)
assert os.path.getsize(new_flac.filename) > old_file_size
assert new_flac.info.bitrate == 101430
def test_padding(self):
for pad in [0, 42, 2**24 - 1, 2 ** 24]:
self.flac.save(padding=lambda x: pad)
new = FLAC(self.flac.filename)
expected = min(2**24 - 1, pad)
self.assertEqual(new.metadata_blocks[-1].length, expected)
def test_save_multiple_padding(self):
# we don't touch existing padding blocks on save, but will
# replace them in the file with one at the end
def num_padding(f):
blocks = f.metadata_blocks
return len([b for b in blocks if isinstance(b, Padding)])
num_blocks = num_padding(self.flac)
self.assertEqual(num_blocks, 1)
block = Padding()
block.length = 42
self.flac.metadata_blocks.append(block)
block = Padding()
block.length = 24
self.flac.metadata_blocks.append(block)
self.flac.save()
self.assertEqual(num_padding(self.flac), num_blocks + 2)
new = FLAC(self.flac.filename)
self.assertEqual(num_padding(new), 1)
self.assertTrue(isinstance(new.metadata_blocks[-1], Padding))
def test_increase_size_new_padding(self):
self.assertEqual(self.flac.metadata_blocks[-1].length, 3060)
value = u"foo" * 100
self.flac[u"foo"] = [value]
self.flac.save()
new = FLAC(self.NEW)
self.assertEqual(new.metadata_blocks[-1].length, 2752)
self.assertEqual(new[u"foo"], [value])
def test_delete(self):
self.failUnless(self.flac.tags)
self.flac.delete()
self.assertTrue(self.flac.tags is not None)
self.assertFalse(self.flac.tags)
flac = FLAC(self.NEW)
self.assertTrue(flac.tags is None)
def test_delete_change_reload(self):
self.flac.delete()
self.flac.tags["FOO"] = ["BAR"]
self.flac.save()
assert FLAC(self.flac.filename)["FOO"] == ["BAR"]
# same with delete failing due to IO etc.
with pytest.raises(MutagenError):
self.flac.delete(os.devnull)
self.flac.tags["FOO"] = ["QUUX"]
self.flac.save()
assert FLAC(self.flac.filename)["FOO"] == ["QUUX"]
def test_module_delete(self):
delete(self.NEW)
flac = FLAC(self.NEW)
self.failIf(flac.tags)
def test_info(self):
self.failUnlessAlmostEqual(FLAC(self.NEW).info.length, 3.7, 1)
def test_keys(self):
self.failUnlessEqual(
list(self.flac.keys()), list(self.flac.tags.keys()))
def test_values(self):
#.........这里部分代码省略.........