示例#1
0
def test_compression():
    f = open(__file__, "rb")
    try:
        data = f.read()
        compressed = Frame.compress(data)
        assert data == Frame.decompress(compressed)
    finally:
        f.close()
示例#2
0
def test_compression():
    f = open(__file__, "rb")
    try:
        data = f.read()
        compressed = Frame.compress(data)
        assert data == Frame.decompress(compressed)
    finally:
        f.close()
示例#3
0
 def testTextDelim(self):
     for enc in [LATIN1_ENCODING, UTF_16BE_ENCODING, UTF_16_ENCODING,
                 UTF_8_ENCODING]:
         f = Frame(b"XXXX")
         f.encoding = enc
         if enc in [LATIN1_ENCODING, UTF_8_ENCODING]:
             assert (f.text_delim == b"\x00")
         else:
             assert (f.text_delim == b"\x00\x00")
示例#4
0
 def testTextDelim(self):
     for enc in [
             LATIN1_ENCODING, UTF_16BE_ENCODING, UTF_16_ENCODING,
             UTF_8_ENCODING
     ]:
         f = Frame(b"XXXX")
         f.encoding = enc
         if enc in [LATIN1_ENCODING, UTF_8_ENCODING]:
             assert (f.text_delim == b"\x00")
         else:
             assert (f.text_delim == b"\x00\x00")
示例#5
0
    def testCtor(self):
        f = Frame(b"ABCD")
        assert f.id == b"ABCD"
        assert f.header is None
        assert f.decompressed_size == 0
        assert f.group_id is None
        assert f.encrypt_method is None
        assert f.data is None
        assert f.data_len == 0
        assert f.encoding is None

        f = Frame(b"EFGH")
        assert f.id == b"EFGH"
        assert f.header is None
        assert f.decompressed_size == 0
        assert f.group_id is None
        assert f.encrypt_method is None
        assert f.data is None
        assert f.data_len == 0
        assert f.encoding is None
示例#6
0
    def testInitEncoding(self):
        # Default encodings per version
        for ver in [ID3_V1_0, ID3_V1_1, ID3_V2_3, ID3_V2_4]:
            f = Frame(b"XXXX")
            f.header = FrameHeader(f.id, ver)
            f._initEncoding()
            if ver[0] == 1:
                assert (f.encoding == LATIN1_ENCODING)
            elif ver[:2] == (2, 3):
                assert (f.encoding == UTF_16_ENCODING)
            else:
                assert (f.encoding == UTF_8_ENCODING)

        # Invalid encoding for a version is coerced
        for ver in [ID3_V1_0, ID3_V1_1]:
            for enc in [UTF_8_ENCODING, UTF_16_ENCODING, UTF_16BE_ENCODING]:
                f = Frame(b"XXXX")
                f.header = FrameHeader(f.id, ver)
                f.encoding = enc
                f._initEncoding()
                assert (f.encoding == LATIN1_ENCODING)

        for ver in [ID3_V2_3]:
            for enc in [UTF_8_ENCODING, UTF_16BE_ENCODING]:
                f = Frame(b"XXXX")
                f.header = FrameHeader(f.id, ver)
                f.encoding = enc
                f._initEncoding()
                assert (f.encoding == UTF_16_ENCODING)

        # No coersion for v2.4
        for ver in [ID3_V2_4]:
            for enc in [LATIN1_ENCODING, UTF_8_ENCODING, UTF_16BE_ENCODING,
                        UTF_16_ENCODING]:
                f = Frame(b"XXXX")
                f.header = FrameHeader(f.id, ver)
                f.encoding = enc
                f._initEncoding()
                assert (f.encoding == enc)
示例#7
0
def test_encryption():
    with pytest.raises(NotImplementedError):
        Frame.encrypt("Iceburn")
    with pytest.raises(NotImplementedError):
        Frame.decrypt("Iceburn")
示例#8
0
    def testInitEncoding(self):
        # Default encodings per version
        for ver in [ID3_V1_0, ID3_V1_1, ID3_V2_3, ID3_V2_4]:
            f = Frame(b"XXXX")
            f.header = FrameHeader(f.id, ver)
            f._initEncoding()
            if ver[0] == 1:
                assert (f.encoding == LATIN1_ENCODING)
            elif ver[:2] == (2, 3):
                assert (f.encoding == UTF_16_ENCODING)
            else:
                assert (f.encoding == UTF_8_ENCODING)

        # Invalid encoding for a version is coerced
        for ver in [ID3_V1_0, ID3_V1_1]:
            for enc in [UTF_8_ENCODING, UTF_16_ENCODING, UTF_16BE_ENCODING]:
                f = Frame(b"XXXX")
                f.header = FrameHeader(f.id, ver)
                f.encoding = enc
                f._initEncoding()
                assert (f.encoding == LATIN1_ENCODING)

        for ver in [ID3_V2_3]:
            for enc in [UTF_8_ENCODING, UTF_16BE_ENCODING]:
                f = Frame(b"XXXX")
                f.header = FrameHeader(f.id, ver)
                f.encoding = enc
                f._initEncoding()
                assert (f.encoding == UTF_16_ENCODING)

        # No coersion for v2.4
        for ver in [ID3_V2_4]:
            for enc in [
                    LATIN1_ENCODING, UTF_8_ENCODING, UTF_16BE_ENCODING,
                    UTF_16_ENCODING
            ]:
                f = Frame(b"XXXX")
                f.header = FrameHeader(f.id, ver)
                f.encoding = enc
                f._initEncoding()
                assert (f.encoding == enc)
示例#9
0
def test_encryption():
    assert "Iceburn" == Frame.encrypt("Iceburn")
    assert "Iceburn" == Frame.decrypt("Iceburn")
示例#10
0
def test_encryption():
    with pytest.raises(NotImplementedError):
        Frame.encrypt("Iceburn")
    with pytest.raises(NotImplementedError):
        Frame.decrypt("Iceburn")