Ejemplo n.º 1
0
def test_ascii85_decode(data, expected_value, exception):
    if exception:
        with pytest.raises(exception):
            ASCII85Codec.decode(data)
    else:
        value = ASCII85Codec.decode(data)
        assert value == expected_value
        assert isinstance(value, bytes_type)
Ejemplo n.º 2
0
def test_ascii85_decode(data, expected_value, exception):
    """ [EXPLAIN THIS.] """
    if exception:
        with pytest.raises(exception):
            ASCII85Codec.decode(data)
    else:
        value = ASCII85Codec.decode(data)
        assert value == expected_value
        assert isinstance(value, BytesType)
Ejemplo n.º 3
0
    def testWithOverflow(self):
        inputs = (v + "~>"
                  for v in '\x00\x01\x02\x03\x04\x05\x06\x07\x08\x0e\x0f'
                  '\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a'
                  '\x1b\x1c\x1d\x1e\x1fvwxy{|}~\x7f\x80\x81\x82'
                  '\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d'
                  '\x8e\x8f\x90\x91\x92\x93\x94\x95\x96\x97\x98'
                  '\x99\x9a\x9b\x9c\x9d\x9e\x9f\xa0¡¢£¤¥¦§¨©ª«¬'
                  '\xad®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇ')

        for i in inputs:
            with self.assertRaises(ValueError, msg="char = " + repr(i)):
                ASCII85Codec.decode(i)
Ejemplo n.º 4
0
    def testFiveZeroBytes(self):
        """
        From ISO 32000 (2008) sect. 7.4.3:
        «As a special case, if all five bytes are 0, they shall be represented
        by the character with code 122 (z) instead of by five exclamation
        points (!!!!!).»
        """
        inputs = (b"z~>", b"zz~>", b"zzz~>")
        exp_outputs = (
            b"\x00\x00\x00\x00",
            b"\x00\x00\x00\x00" * 2,
            b"\x00\x00\x00\x00" * 3,
        )

        self.assertEqual(ASCII85Codec.decode(b"!!!!!~>"), ASCII85Codec.decode(b"z~>"))

        for o__, i in zip(exp_outputs, inputs):
            self.assertEqual(o__, ASCII85Codec.decode(i))
Ejemplo n.º 5
0
def testASCII85Encode(data, expected_value):
    """ [EXPLAIN THIS.] """
    value = ASCII85Codec.encode(data)
    assert value == expected_value
    assert isinstance(value, BytesType)
Ejemplo n.º 6
0
def testASCII85Encode(data, expected_value):
    value = ASCII85Codec.encode(data)
    assert value == expected_value
    assert isinstance(value, bytes_type)