Пример #1
0
    def test_uuid_deserialize(self):
        value = uuid.UUID('12345678123456781234567812345678')

        assert ProtocolBase().from_string(Uuid,
                '12345678-1234-5678-1234-567812345678') == value
        assert ProtocolBase().from_string(Uuid(serialize_as='hex'),
                '12345678123456781234567812345678') == value
        assert ProtocolBase().from_string(Uuid(serialize_as='urn'),
                'urn:uuid:12345678-1234-5678-1234-567812345678') == value
        assert ProtocolBase().from_string(Uuid(serialize_as='bytes'),
                '\x124Vx\x124Vx\x124Vx\x124Vx') == value
        assert ProtocolBase().from_string(Uuid(serialize_as='bytes_le'),
                'xV4\x124\x12xV\x124Vx\x124Vx') == value
        assert ProtocolBase().from_string(Uuid(serialize_as='fields'),
                (305419896, 4660, 22136, 18, 52, 95073701484152)) == value
        assert ProtocolBase().from_string(Uuid(serialize_as='int'),
                24197857161011715162171839636988778104) == value
Пример #2
0
    def test_uuid_serialize(self):
        value = uuid.UUID('12345678123456781234567812345678')

        assert ProtocolBase().to_string(Uuid, value) == \
                                '12345678-1234-5678-1234-567812345678'
        assert ProtocolBase().to_string(Uuid(serialize_as='hex'), value) == \
                                '12345678123456781234567812345678'
        assert ProtocolBase().to_string(Uuid(serialize_as='urn'), value) == \
                                'urn:uuid:12345678-1234-5678-1234-567812345678'
        assert ProtocolBase().to_string(Uuid(serialize_as='bytes'), value) == \
                                '\x124Vx\x124Vx\x124Vx\x124Vx'
        assert ProtocolBase().to_string(Uuid(serialize_as='bytes_le'), value) == \
                                'xV4\x124\x12xV\x124Vx\x124Vx'
        assert ProtocolBase().to_string(Uuid(serialize_as='fields'), value) == \
                                (305419896L, 4660L, 22136L, 18L, 52L, 95073701484152L)
        assert ProtocolBase().to_string(Uuid(serialize_as='int'), value) == \
                                24197857161011715162171839636988778104
Пример #3
0
 def test_uuid_validate(self):
     assert Uuid.validate_string(Uuid,
                       '12345678-1234-5678-1234-567812345678')
     assert Uuid.validate_native(Uuid,
             uuid.UUID('12345678-1234-5678-1234-567812345678'))