def test_duplicate_keys(self): self.c = VCommentDict() keys = ("key", "Key", "KEY") for key in keys: self.c.append((key, "value")) self.failUnlessEqual(len(self.c.keys()), 1) self.failUnlessEqual(len(self.c.as_dict()), 1)
def tags_to_vorbis(tags, tags_type): out_tags = VCommentDict() for tkey, tval in tags.items(): key = None if tags_type == TAGS_ID3: tf = id3_to_vorbis_text_frame.get(tval.__class__, None) to_text = lambda x: x if tf: key = tf elif isinstance(tval, mutagen.id3.TXXX): key = tval.desc elif isinstance(tval, mutagen.id3.TRCK): key = 'tracknumber' elif isinstance(tval, mutagen.id3.TPOS): key = 'discnumber' elif isinstance(tval, mutagen.id3.TDRC): key = 'date' to_text = lambda x: x.text if key: for txt in tval.text: out_tags.append((key, to_text(txt))) elif tags_type == TAGS_MP4: def append_numtot_pairs(num_name, tot_name, pairs): for num_tot in pairs: (num, tot) = num_tot if len(num_tot) > 1 else (num_tot[0], None) out_tags.append((num_name, str(num))) if tot: out_tags.append((tot_name, str(tot))) tf = mp4_to_vorbis_text_frame.get(tkey, None) if tf: key = tf elif tkey.startswith('----:com.apple.iTunes:'): key = tkey.split(':', 2)[2] elif tkey == 'trkn': append_numtot_pairs('tracknumber', 'tracktotal', tval) elif tkey == 'disk': append_numtot_pairs('discnumber', 'disctotal', tval) if key: for txt in tval: out_tags.append((key, txt)) else: raise ValueError("unsupported tags type: 0x%x" % tags_type) return out_tags
def test_empty(self): self.c = VCommentDict() self.failIf(self.c.keys()) self.failIf(self.c.values()) self.failIf(self.c.items())
class TVCommentDict(TestCase): Kind = VCommentDict def setUp(self): self.c = self.Kind() self.c["artist"] = ["mu", "piman"] self.c["title"] = u"more fakes" def test_correct_len(self): self.failUnlessEqual(len(self.c), 3) def test_keys(self): self.failUnless("artist" in self.c.keys()) self.failUnless("title" in self.c.keys()) def test_values(self): self.failUnless(["mu", "piman"] in self.c.values()) self.failUnless(["more fakes"] in self.c.values()) def test_items(self): self.failUnless(("artist", ["mu", "piman"]) in self.c.items()) self.failUnless(("title", ["more fakes"]) in self.c.items()) def test_equal(self): self.failUnlessEqual(self.c, self.c) def test_get(self): self.failUnlessEqual(self.c["artist"], ["mu", "piman"]) self.failUnlessEqual(self.c["title"], ["more fakes"]) def test_set(self): self.c["woo"] = "bar" self.failUnlessEqual(self.c["woo"], ["bar"]) def test_del(self): del(self.c["title"]) self.failUnlessRaises(KeyError, self.c.__getitem__, "title") def test_contains(self): self.failIf("foo" in self.c) self.failUnless("title" in self.c) def test_get_case(self): self.failUnlessEqual(self.c["ARTIST"], ["mu", "piman"]) def test_set_case(self): self.c["TITLE"] = "another fake" self.failUnlessEqual(self.c["title"], ["another fake"]) def test_set_preserve_case(self): del(self.c["title"]) self.c["TiTlE"] = "blah" self.failUnless(("TiTlE", "blah") in list(self.c)) self.failUnless("title" in self.c) def test_contains_case(self): self.failUnless("TITLE" in self.c) def test_del_case(self): del(self.c["TITLE"]) self.failUnlessRaises(KeyError, self.c.__getitem__, "title") def test_get_failure(self): self.failUnlessRaises(KeyError, self.c.__getitem__, "woo") def test_del_failure(self): self.failUnlessRaises(KeyError, self.c.__delitem__, "woo") def test_roundtrip(self): self.failUnlessEqual(self.c, self.Kind(self.c.write())) def test_roundtrip_vc(self): self.failUnlessEqual(self.c, VComment(self.c.write())) def test_case_items_426(self): self.c.append(("WOO", "bar")) self.failUnless(("woo", ["bar"]) in self.c.items()) def test_empty(self): self.c = VCommentDict() self.failIf(self.c.keys()) self.failIf(self.c.values()) self.failIf(self.c.items()) def test_as_dict(self): d = self.c.as_dict() self.failUnless("artist" in d) self.failUnless("title" in d) self.failUnlessEqual(d["artist"], self.c["artist"]) self.failUnlessEqual(d["title"], self.c["title"]) def test_bad_key(self): self.failUnlessRaises(UnicodeError, self.c.get, u"\u1234") self.failUnlessRaises( UnicodeError, self.c.__setitem__, u"\u1234", "foo") self.failUnlessRaises( UnicodeError, self.c.__delitem__, u"\u1234") def test_duplicate_keys(self): self.c = VCommentDict() keys = ("key", "Key", "KEY") for key in keys: self.c.append((key, "value")) self.failUnlessEqual(len(self.c.keys()), 1) self.failUnlessEqual(len(self.c.as_dict()), 1)
class TVCommentDict(TestCase): uses_mmap = False Kind = VCommentDict def setUp(self): self.c = self.Kind() self.c["artist"] = ["mu", "piman"] self.c["title"] = u"more fakes" def test_correct_len(self): self.failUnlessEqual(len(self.c), 3) def test_keys(self): self.failUnless("artist" in self.c.keys()) self.failUnless("title" in self.c.keys()) def test_values(self): self.failUnless(["mu", "piman"] in self.c.values()) self.failUnless(["more fakes"] in self.c.values()) def test_items(self): self.failUnless(("artist", ["mu", "piman"]) in self.c.items()) self.failUnless(("title", ["more fakes"]) in self.c.items()) def test_equal(self): self.failUnlessEqual(self.c, self.c) def test_get(self): self.failUnlessEqual(self.c["artist"], ["mu", "piman"]) self.failUnlessEqual(self.c["title"], ["more fakes"]) def test_set(self): self.c["woo"] = "bar" self.failUnlessEqual(self.c["woo"], ["bar"]) def test_del(self): del (self.c["title"]) self.failUnlessRaises(KeyError, self.c.__getitem__, "title") def test_contains(self): self.failIf("foo" in self.c) self.failUnless("title" in self.c) def test_get_case(self): self.failUnlessEqual(self.c["ARTIST"], ["mu", "piman"]) def test_set_case(self): self.c["TITLE"] = "another fake" self.failUnlessEqual(self.c["title"], ["another fake"]) def test_contains_case(self): self.failUnless("TITLE" in self.c) def test_del_case(self): del (self.c["TITLE"]) self.failUnlessRaises(KeyError, self.c.__getitem__, "title") def test_get_failure(self): self.failUnlessRaises(KeyError, self.c.__getitem__, "woo") def test_del_failure(self): self.failUnlessRaises(KeyError, self.c.__delitem__, "woo") def test_roundtrip(self): self.failUnlessEqual(self.c, self.Kind(self.c.write())) def test_roundtrip_vc(self): self.failUnlessEqual(self.c, VComment(self.c.write())) def test_case_items_426(self): self.c.append(("WOO", "bar")) self.failUnless(("woo", ["bar"]) in self.c.items()) def test_empty(self): self.c = VCommentDict() self.failIf(self.c.keys()) self.failIf(self.c.values()) self.failIf(self.c.items()) def test_as_dict(self): d = self.c.as_dict() self.failUnless("artist" in d) self.failUnless("title" in d) self.failUnlessEqual(d["artist"], self.c["artist"]) self.failUnlessEqual(d["title"], self.c["title"]) def test_bad_key(self): self.failUnlessRaises(UnicodeError, self.c.get, u"\u1234") self.failUnlessRaises(UnicodeError, self.c.__setitem__, u"\u1234", "foo") self.failUnlessRaises(UnicodeError, self.c.__delitem__, u"\u1234")
class TVCommentDict(TestCase): Kind = VCommentDict def setUp(self): self.c = self.Kind() self.c["artist"] = ["mu", "piman"] self.c["title"] = u"more fakes" def test_correct_len(self): self.failUnlessEqual(len(self.c), 3) def test_keys(self): self.failUnless("artist" in self.c.keys()) self.failUnless("title" in self.c.keys()) def test_values(self): self.failUnless(["mu", "piman"] in self.c.values()) self.failUnless(["more fakes"] in self.c.values()) def test_items(self): self.failUnless(("artist", ["mu", "piman"]) in self.c.items()) self.failUnless(("title", ["more fakes"]) in self.c.items()) def test_equal(self): self.failUnlessEqual(self.c, self.c) def test_get(self): self.failUnlessEqual(self.c["artist"], ["mu", "piman"]) self.failUnlessEqual(self.c["title"], ["more fakes"]) def test_set(self): self.c["woo"] = "bar" self.failUnlessEqual(self.c["woo"], ["bar"]) def test_slice(self): l = [("foo", "bar"), ("foo", "bar2")] self.c[:] = l self.assertEqual(self.c[:], l) self.failUnlessEqual(self.c["foo"], ["bar", "bar2"]) del self.c[:] self.assertEqual(self.c[:], []) def test_iter(self): self.assertEqual(next(iter(self.c)), ("artist", "mu")) self.assertEqual(list(self.c)[0], ("artist", "mu")) def test_del(self): del (self.c["title"]) self.failUnlessRaises(KeyError, self.c.__getitem__, "title") def test_contains(self): self.failIf("foo" in self.c) self.failUnless("title" in self.c) def test_get_case(self): self.failUnlessEqual(self.c["ARTIST"], ["mu", "piman"]) def test_set_case(self): self.c["TITLE"] = "another fake" self.failUnlessEqual(self.c["title"], ["another fake"]) def test_set_preserve_case(self): del (self.c["title"]) self.c["TiTlE"] = "blah" self.failUnless(("TiTlE", "blah") in list(self.c)) self.failUnless("title" in self.c) def test_contains_case(self): self.failUnless("TITLE" in self.c) def test_del_case(self): del (self.c["TITLE"]) self.failUnlessRaises(KeyError, self.c.__getitem__, "title") def test_get_failure(self): self.failUnlessRaises(KeyError, self.c.__getitem__, "woo") def test_del_failure(self): self.failUnlessRaises(KeyError, self.c.__delitem__, "woo") def test_roundtrip(self): self.failUnlessEqual(self.c, self.Kind(self.c.write())) def test_roundtrip_vc(self): self.failUnlessEqual(self.c, VComment(self.c.write())) def test_case_items_426(self): self.c.append(("WOO", "bar")) self.failUnless(("woo", ["bar"]) in self.c.items()) def test_empty(self): self.c = VCommentDict() self.failIf(list(self.c.keys())) self.failIf(list(self.c.values())) self.failIf(list(self.c.items())) def test_as_dict(self): d = self.c.as_dict() self.failUnless("artist" in d) self.failUnless("title" in d) self.failUnlessEqual(d["artist"], self.c["artist"]) self.failUnlessEqual(d["title"], self.c["title"]) def test_bad_key(self): self.failUnlessRaises(ValueError, self.c.get, u"\u1234") self.failUnlessRaises(ValueError, self.c.__setitem__, u"\u1234", "foo") self.failUnlessRaises(ValueError, self.c.__delitem__, u"\u1234") if PY3: def test_py3_bad_key(self): self.failUnlessRaises(TypeError, self.c.get, b"a") self.failUnlessRaises(TypeError, self.c.__setitem__, b"a", "foo") self.failUnlessRaises(TypeError, self.c.__delitem__, b"a") def test_duplicate_keys(self): self.c = VCommentDict() keys = ("key", "Key", "KEY") for key in keys: self.c.append((key, "value")) self.failUnlessEqual(len(self.c.keys()), 1) self.failUnlessEqual(len(self.c.as_dict()), 1)