Beispiel #1
0
 def test_python3_strict_str(self):
     comment = VComment()
     comment.append((u"abc", u"test"))
     comment.validate()
     comment[0] = (u"abc", b"test")
     self.failUnlessRaises(ValueError, comment.validate)
     comment[0] = (b"abc", u"test")
     self.failUnlessRaises(ValueError, comment.validate)
Beispiel #2
0
def create_metadata_packet(tags):
    vc = VComment()
    vc.extend(tags)
    return "\x03vorbis"+vc.write()
Beispiel #3
0
 def test_invalid_tag_replace(self):
     data = ('\x07\x00\x00\x00Mutagen\x01\x00\x00\x00\x04\x00\x00'
             '\x00\xc2\xaa=c\x01')
     comment = VComment(data)
     self.failUnlessEqual("?=c", comment.pprint())
Beispiel #4
0
 def setUp(self):
     self.c = VComment()
     self.c.append(("artist", u"piman"))
     self.c.append(("artist", u"mu"))
     self.c.append(("title", u"more fakes"))
Beispiel #5
0
class TVComment(TestCase):

    def setUp(self):
        self.c = VComment()
        self.c.append(("artist", u"piman"))
        self.c.append(("artist", u"mu"))
        self.c.append(("title", u"more fakes"))

    def test_invalid_init(self):
        self.failUnlessRaises(TypeError, VComment, [])

    def test_equal(self):
        self.failUnlessEqual(self.c, self.c)

    def test_not_header(self):
        self.failUnlessRaises(IOError, VComment, "foo")

    def test_unset_framing_bit(self):
        self.failUnlessRaises(
            IOError, VComment, "\x00\x00\x00\x00" * 2 + "\x00")

    def test_empty_valid(self):
        self.failIf(VComment("\x00\x00\x00\x00" * 2 + "\x01"))

    def test_validate(self):
        self.failUnless(self.c.validate())

    def test_validate_broken_key(self):
        self.c.append((1, u"valid"))
        self.failUnlessRaises(ValueError, self.c.validate)
        self.failUnlessRaises(ValueError, self.c.write)

    def test_validate_broken_value(self):
        self.c.append(("valid", 1))
        self.failUnlessRaises(ValueError, self.c.validate)
        self.failUnlessRaises(ValueError, self.c.write)

    def test_validate_nonunicode_value(self):
        self.c.append(("valid", "wt\xff"))
        self.failUnlessRaises(ValueError, self.c.validate)
        self.failUnlessRaises(ValueError, self.c.write)

    def test_vendor_default(self):
        self.failUnless(self.c.vendor.startswith("Mutagen"))

    def test_vendor_set(self):
        self.c.vendor = "Not Mutagen"
        self.failUnless(self.c.write()[4:].startswith("Not Mutagen"))

    def test_vendor_invalid(self):
        self.c.vendor = "\xffNot Mutagen"
        self.failUnlessRaises(ValueError, self.c.validate)
        self.failUnlessRaises(ValueError, self.c.write)

    def test_invalid_format_strict(self):
        data = ('\x07\x00\x00\x00Mutagen\x01\x00\x00\x00\x03\x00\x00'
                '\x00abc\x01')
        self.failUnlessRaises(IOError, VComment, data, errors='strict')

    def test_invalid_format_replace(self):
        data = ('\x07\x00\x00\x00Mutagen\x01\x00\x00\x00\x03\x00\x00'
                '\x00abc\x01')
        comment = VComment(data)
        self.failUnlessEqual("abc", comment[0][1])

    def test_invalid_format_ignore(self):
        data = ('\x07\x00\x00\x00Mutagen\x01\x00\x00\x00\x03\x00\x00'
                '\x00abc\x01')
        comment = VComment(data, errors='ignore')
        self.failIf(len(comment))

    # Slightly different test data than above, we want the tag name
    # to be valid UTF-8 but not valid ASCII.
    def test_invalid_tag_strict(self):
        data = ('\x07\x00\x00\x00Mutagen\x01\x00\x00\x00\x04\x00\x00'
                '\x00\xc2\xaa=c\x01')
        self.failUnlessRaises(IOError, VComment, data, errors='strict')

    def test_invalid_tag_replace(self):
        data = ('\x07\x00\x00\x00Mutagen\x01\x00\x00\x00\x04\x00\x00'
                '\x00\xc2\xaa=c\x01')
        comment = VComment(data)
        self.failUnlessEqual("?=c", comment.pprint())

    def test_invalid_tag_ignore(self):
        data = ('\x07\x00\x00\x00Mutagen\x01\x00\x00\x00\x04\x00\x00'
                '\x00\xc2\xaa=c\x01')
        comment = VComment(data, errors='ignore')
        self.failIf(len(comment))

    def test_roundtrip(self):
        self.failUnlessEqual(self.c, VComment(self.c.write()))
Beispiel #6
0
class TVComment(TestCase):
    Kind = VComment

    def setUp(self):
        self.c = VComment()
        self.c.append(("artist", u"piman"))
        self.c.append(("artist", u"mu"))
        self.c.append(("title", u"more fakes"))

    def test_invalid_init(self):
        self.failUnlessRaises(TypeError, VComment, [])

    def test_equal(self):
        self.failUnlessEqual(self.c, self.c)

    def test_not_header(self):
        self.failUnlessRaises(IOError, VComment, b"foo")

    def test_unset_framing_bit(self):
        self.failUnlessRaises(
            IOError, VComment, b"\x00\x00\x00\x00" * 2 + b"\x00")

    def test_empty_valid(self):
        self.failIf(VComment(b"\x00\x00\x00\x00" * 2 + b"\x01"))

    def test_validate(self):
        self.failUnless(self.c.validate())

    def test_validate_broken_key(self):
        self.c.append((1, u"valid"))
        self.failUnlessRaises(ValueError, self.c.validate)
        self.failUnlessRaises(ValueError, self.c.write)

    def test_validate_broken_value(self):
        self.c.append((u"valid", 1))
        self.failUnlessRaises(ValueError, self.c.validate)
        self.failUnlessRaises(ValueError, self.c.write)

    def test_validate_nonunicode_value(self):
        self.c.append((u"valid", b"wt\xff"))
        self.failUnlessRaises(ValueError, self.c.validate)
        self.failUnlessRaises(ValueError, self.c.write)

    def test_vendor_default(self):
        self.failUnless(self.c.vendor.startswith(u"Mutagen"))

    def test_vendor_set(self):
        self.c.vendor = u"Not Mutagen"
        self.failUnless(self.c.write()[4:].startswith(b"Not Mutagen"))

    def test_vendor_invalid(self):
        self.c.vendor = b"\xffNot Mutagen"
        self.failUnlessRaises(ValueError, self.c.validate)
        self.failUnlessRaises(ValueError, self.c.write)

    def test_invalid_format_strict(self):
        data = (b'\x07\x00\x00\x00Mutagen\x01\x00\x00\x00\x03\x00\x00'
                b'\x00abc\x01')
        self.failUnlessRaises(IOError, VComment, data, errors='strict')

    def test_invalid_format_replace(self):
        data = (b'\x07\x00\x00\x00Mutagen\x01\x00\x00\x00\x03\x00\x00'
                b'\x00abc\x01')
        comment = VComment(data)
        self.failUnlessEqual(u"abc", comment[0][1])

    def test_python_key_value_type(self):
        data = (b'\x07\x00\x00\x00Mutagen\x01\x00\x00\x00\x03\x00\x00'
                b'\x00abc\x01')
        comment = VComment(data)
        self.assertTrue(isinstance(comment[0][0], type('')))
        self.assertTrue(isinstance(comment[0][1], text_type))

    if PY3:
        def test_python3_strict_str(self):
            comment = VComment()
            comment.append((u"abc", u"test"))
            comment.validate()
            comment[0] = (u"abc", b"test")
            self.failUnlessRaises(ValueError, comment.validate)
            comment[0] = (b"abc", u"test")
            self.failUnlessRaises(ValueError, comment.validate)

    def test_invalid_format_ignore(self):
        data = (b'\x07\x00\x00\x00Mutagen\x01\x00\x00\x00\x03\x00\x00'
                b'\x00abc\x01')
        comment = VComment(data, errors='ignore')
        self.failIf(len(comment))

    # Slightly different test data than above, we want the tag name
    # to be valid UTF-8 but not valid ASCII.
    def test_invalid_tag_strict(self):
        data = (b'\x07\x00\x00\x00Mutagen\x01\x00\x00\x00\x04\x00\x00'
                b'\x00\xc2\xaa=c\x01')
        self.failUnlessRaises(IOError, VComment, data, errors='strict')

    def test_invalid_tag_replace(self):
        data = (b'\x07\x00\x00\x00Mutagen\x01\x00\x00\x00\x04\x00\x00'
                b'\x00\xc2\xaa=c\x01')
        comment = VComment(data)
        self.failUnlessEqual(u"?=c", comment.pprint())

    def test_invalid_tag_ignore(self):
        data = (b'\x07\x00\x00\x00Mutagen\x01\x00\x00\x00\x04\x00\x00'
                b'\x00\xc2\xaa=c\x01')
        comment = VComment(data, errors='ignore')
        self.failIf(len(comment))

    def test_roundtrip(self):
        self.assertReallyEqual(self.c, VComment(self.c.write()))
Beispiel #7
0
 def test_invalid_tag_replace(self):
     data = (b'\x07\x00\x00\x00Mutagen\x01\x00\x00\x00\x04\x00\x00'
             b'\x00\xc2\xaa=c\x01')
     comment = VComment(data)
     self.failUnlessEqual(u"?=c", comment.pprint())
Beispiel #8
0
 def test_invalid_format_ignore(self):
     data = (b'\x07\x00\x00\x00Mutagen\x01\x00\x00\x00\x03\x00\x00'
             b'\x00abc\x01')
     comment = VComment(data, errors='ignore')
     self.failIf(len(comment))
Beispiel #9
0
 def test_python_key_value_type(self):
     data = (b'\x07\x00\x00\x00Mutagen\x01\x00\x00\x00\x03\x00\x00'
             b'\x00abc\x01')
     comment = VComment(data)
     self.assertTrue(isinstance(comment[0][0], type('')))
     self.assertTrue(isinstance(comment[0][1], str))