Example #1
0
 def test_encodedtextspec(self):
     from mutagen.id3 import EncodedTextSpec, Frame
     s = EncodedTextSpec('name')
     f = Frame(); f.encoding = 0
     self.assertEquals(('abcd', b'fg'), s.read(f, b'abcd\x00fg'))
     self.assertEquals(b'abcdefg\x00', s.write(f, 'abcdefg'))
     self.assertRaises(AttributeError, s.write, f, None)
Example #2
0
    def test_synchronizedtextspec(self):
        from mutagen.id3 import SynchronizedTextSpec, Frame
        s = SynchronizedTextSpec('name')
        f = Frame()

        values = [(u"A", 100), (u"\xe4xy", 0), (u"", 42), (u"", 0)]

        # utf-16
        f.encoding = 1
        self.assertEqual(s.read(f, s.write(f, values)), (values, b""))
        data = s.write(f, [(u"A", 100)])
        if sys.byteorder == 'little':
            self.assertEquals(
                data, b"\xff\xfeA\x00\x00\x00\x00\x00\x00d")
        else:
            self.assertEquals(
                data, b"\xfe\xff\x00A\x00\x00\x00\x00\x00d")

        # utf-16be
        f.encoding = 2
        self.assertEqual(s.read(f, s.write(f, values)), (values, b""))
        self.assertEquals(
            s.write(f, [(u"A", 100)]), b"\x00A\x00\x00\x00\x00\x00d")

        # utf-8
        f.encoding = 3
        self.assertEqual(s.read(f, s.write(f, values)), (values, b""))
        self.assertEquals(s.write(f, [(u"A", 100)]), b"A\x00\x00\x00\x00d")
Example #3
0
 def test_encodedtextspec(self):
     from mutagen.id3 import EncodedTextSpec, Frame
     s = EncodedTextSpec('name')
     f = Frame()
     f.encoding = 0
     self.assertEquals((u'abcd', b'fg'), s.read(f, b'abcd\x00fg'))
     self.assertEquals(b'abcdefg\x00', s.write(f, u'abcdefg'))
     self.assertRaises(AttributeError, s.write, f, None)
Example #4
0
 def test_timestampspec(self):
     from mutagen.id3 import TimeStampSpec, Frame, ID3TimeStamp
     s = TimeStampSpec('name')
     f = Frame(); f.encoding = 0
     self.assertEquals((ID3TimeStamp('ab'), b'fg'), s.read(f, b'ab\x00fg'))
     self.assertEquals((ID3TimeStamp('1234'), b''), s.read(f, b'1234\x00'))
     self.assertEquals(b'1234\x00', s.write(f, ID3TimeStamp('1234')))
     self.assertRaises(AttributeError, s.write, f, None)
Example #5
0
    def test_encodedtextspec(self):
        from mutagen.id3 import EncodedTextSpec, Frame

        s = EncodedTextSpec("name")
        f = Frame()
        f.encoding = 0
        self.assertEquals(("abcd", "fg"), s.read(f, "abcd\x00fg"))
        self.assertEquals("abcdefg\x00", s.write(f, "abcdefg"))
        self.assertRaises(AttributeError, s.write, f, None)
Example #6
0
    def test_timestampspec(self):
        from mutagen.id3 import TimeStampSpec, Frame, ID3TimeStamp

        s = TimeStampSpec("name")
        f = Frame()
        f.encoding = 0
        self.assertEquals((ID3TimeStamp("ab"), "fg"), s.read(f, "ab\x00fg"))
        self.assertEquals((ID3TimeStamp("1234"), ""), s.read(f, "1234\x00"))
        self.assertEquals("1234\x00", s.write(f, ID3TimeStamp("1234")))
        self.assertRaises(AttributeError, s.write, f, None)
Example #7
0
 def test_timestampspec(self):
     from mutagen.id3 import TimeStampSpec, Frame, ID3TimeStamp
     s = TimeStampSpec('name')
     f = Frame()
     f.encoding = 0
     self.assertEquals((ID3TimeStamp('ab'), b'fg'), s.read(f, b'ab\x00fg'))
     self.assertEquals((ID3TimeStamp('1234'), b''), s.read(f, b'1234\x00'))
     self.assertEquals(b'1234\x00', s.write(f, ID3TimeStamp('1234')))
     self.assertRaises(AttributeError, s.write, f, None)
     if PY3:
         self.assertRaises(TypeError, ID3TimeStamp, b"blah")
     self.assertEquals(text_type(ID3TimeStamp(u"2000-01-01")),
                       u"2000-01-01")
     self.assertEquals(bytes(ID3TimeStamp(u"2000-01-01")), b"2000-01-01")
Example #8
0
 def test_timestampspec(self):
     from mutagen.id3 import TimeStampSpec, Frame, ID3TimeStamp
     s = TimeStampSpec('name')
     f = Frame(); f.encoding = 0
     self.assertEquals((ID3TimeStamp('ab'), b'fg'), s.read(f, b'ab\x00fg'))
     self.assertEquals((ID3TimeStamp('1234'), b''), s.read(f, b'1234\x00'))
     self.assertEquals(b'1234\x00', s.write(f, ID3TimeStamp('1234')))
     self.assertRaises(AttributeError, s.write, f, None)
     if PY3:
         self.assertRaises(TypeError, ID3TimeStamp, b"blah")
     self.assertEquals(
         text_type(ID3TimeStamp(u"2000-01-01")),  u"2000-01-01")
     self.assertEquals(
         bytes(ID3TimeStamp(u"2000-01-01")), b"2000-01-01")