def test_padding(): x = ksuid.from_bytes(b'\xff' * ksuid.BYTE_LENGTH) x_encoded = x.bytes empty_encoded = ksuid.Empty.bytes assert len(x_encoded) == len( empty_encoded ), "Encoding should produce equal-length strings for zero and max case"
def test_parse(): with pytest.raises(TypeError): ksuid.parse(b'123') parsed = ksuid.parse(b'0' * ksuid.STRING_ENCODED_LENGTH) assert parsed == ksuid.Empty parsed = ksuid.parse(u'0' * ksuid.STRING_ENCODED_LENGTH) assert parsed == ksuid.Empty max_bytes_ksuid = ksuid.from_bytes(b'\xff' * ksuid.BYTE_LENGTH) max_parse_ksuid = ksuid.parse(ksuid.MAX_ENCODED) assert max_bytes_ksuid == max_parse_ksuid
def test_encoding(): x = ksuid.from_bytes(b'\x00' * ksuid.BYTE_LENGTH) assert not x, "Zero-byte array should be empty!" encoded = x.encoded assert encoded == b'0' * ksuid.STRING_ENCODED_LENGTH
def test_empty(): assert not bool(ksuid.Empty) x = ksuid.from_bytes(b'\x00' * ksuid.BYTE_LENGTH) assert x == ksuid.Empty