Пример #1
0
    def test_uuid_ctr_02(self):
        for py_u in test_uuids:
            c_u = c_UUID(py_u.bytes)
            self.ensure_equal(py_u, c_u)

        for py_u in test_uuids:
            c_u = c_UUID(str(py_u))
            self.ensure_equal(py_u, c_u)
Пример #2
0
    def test_uuid_ctr_02(self):
        for py_u in test_uuids:
            c_u = c_UUID(py_u.bytes)
            self.assertEqual(c_u.bytes, py_u.bytes)
            self.assertEqual(c_u.int, py_u.int)
            self.assertEqual(str(c_u), str(py_u))

        for py_u in test_uuids:
            c_u = c_UUID(str(py_u))
            self.assertEqual(c_u.bytes, py_u.bytes)
            self.assertEqual(c_u.int, py_u.int)
            self.assertEqual(str(c_u), str(py_u))
Пример #3
0
 def test_uuid_pickle(self):
     u = c_UUID('de197476-4763-11e9-91bf-7311c6dc588e')
     d = pickle.dumps(u)
     u2 = pickle.loads(d)
     self.assertEqual(u, u2)
     self.assertEqual(str(u), str(u2))
     self.assertEqual(u.bytes, u2.bytes)
Пример #4
0
    def test_uuid_compare(self):
        u = c_UUID('de197476-4763-11e9-91bf-7311c6dc588e')
        us = uuid.UUID(bytes=u.bytes)

        for us2 in test_uuids:
            u2 = c_UUID(us2.bytes)

            if us < us2:
                self.assertLess(u, u2)
                self.assertGreater(u2, u)
            elif us > us2:
                self.assertGreater(u, u2)
                self.assertLess(u2, u)

        u3 = c_UUID('de197476-4763-11e9-91bf-7311c6dc588e')
        self.assertTrue(u == u3)
        self.assertFalse(u != u3)
        self.assertTrue(u >= u3)
        self.assertTrue(u <= u3)

        a = c_UUID('10000000-0000-0000-0000-000000000001')
        b = c_UUID('10000000-0000-0000-0000-000000000000')
        self.assertGreater(a, b)
        self.assertLess(b, a)
Пример #5
0
    def test_uuid_props_methods(self):
        for py_u in test_uuids:
            c_u = c_UUID(py_u.bytes)

            self.assertEqual(c_u, py_u)
            self.assertNotEqual(c_u, uuid.uuid4())

            self.assertEqual(hash(c_u), hash(py_u))
            self.assertEqual(repr(c_u), repr(py_u))

            for prop in {
                    'bytes_le', 'fields', 'time_low', 'time_mid',
                    'time_hi_version', 'clock_seq_hi_variant', 'clock_seq_low',
                    'time', 'clock_seq', 'node', 'urn', 'variant', 'version'
            }:
                self.assertEqual(getattr(c_u, prop), getattr(py_u, prop))
Пример #6
0
    def test_uuid_comp(self):
        for _ in range(100):
            ll = random.choice(test_uuids)
            rr = random.choice(test_uuids)

            if ll > rr:
                self.assertTrue(c_UUID(ll.bytes) > rr)

            if ll < rr:
                self.assertTrue(c_UUID(ll.bytes) < rr)

            if ll != rr:
                self.assertTrue(c_UUID(ll.bytes) != rr)

            self.assertTrue(c_UUID(ll.bytes) >= ll)
            self.assertTrue(c_UUID(ll.bytes) <= ll)

            self.assertTrue(c_UUID(ll.bytes) == ll)
            self.assertTrue(c_UUID(ll.bytes) == ll)
Пример #7
0
import uuid
from uuid import UUID as std_UUID
from edgedb.protocol.protocol import UUID as c_UUID

import time

TEST_UUID = uuid.uuid4()
TEST_CUUID = c_UUID(TEST_UUID.bytes)

ubytes = uuid.uuid4().bytes
ustr = str(std_UUID(bytes=ubytes))

print(str(std_UUID(bytes=ubytes)))
print(str(c_UUID(ubytes)))

N = 1_000_000

assert issubclass(c_UUID, std_UUID)
assert isinstance(c_UUID(ubytes), std_UUID)
assert c_UUID(ubytes).bytes == std_UUID(bytes=ubytes).bytes, \
    f'{ubytes}: {c_UUID(ubytes).bytes}'
assert c_UUID(ubytes).hex == std_UUID(bytes=ubytes).hex
assert c_UUID(ubytes).int == std_UUID(bytes=ubytes).int
assert c_UUID(str(std_UUID(bytes=ubytes))).int == std_UUID(bytes=ubytes).int
assert str(c_UUID(ubytes)) == str(std_UUID(bytes=ubytes))
assert hash(c_UUID(ubytes)) == hash(std_UUID(bytes=ubytes))

print()

print(repr(std_UUID(bytes=ubytes)))
print(repr(c_UUID(ubytes)))
Пример #8
0
    def test_uuid_ctr_01(self):
        with self.assertRaisesRegex(ValueError, r'invalid UUID.*got 4'):
            c_UUID('test')

        with self.assertRaisesRegex(ValueError,
                                    r'invalid UUID.*decodes to less'):
            c_UUID('49e3b4e4-4761-11e9-9160-2f38d067497')

        for v in {
                '49e3b4e4476111e991602f38d067497aaaaa',
                '49e3b4e4476111e991602f38d067497aaaa',
                '49e3b4e4476111e991602f38d067497aaa',
                '49e3b4e4476111e991602f38d067497aa',
                '49e3b4e4476111e-991602f-38d067497aa'
        }:
            with self.assertRaisesRegex(ValueError,
                                        r'invalid UUID.*decodes to more'):
                print(c_UUID(v))

        with self.assertRaisesRegex(ValueError,
                                    r"invalid UUID.*unexpected.*'x'"):
            c_UUID('49e3b4e4-4761-11e9-9160-2f38dx67497a')

        with self.assertRaisesRegex(ValueError, r"invalid UUID.*unexpected"):
            c_UUID('49e3b4e4-4761-11160-2f😱3867497a')

        with self.assertRaisesRegex(ValueError, r"invalid UUID.*unexpected"):
            c_UUID('49e3b4e4-4761-11eE-\xAA60-2f38dx67497a')
Пример #9
0
 def test_uuid_instance(self):
     u = c_UUID('de197476-4763-11e9-91bf-7311c6dc588e')
     self.assertTrue(isinstance(u, uuid.UUID))
     self.assertTrue(issubclass(c_UUID, uuid.UUID))
Пример #10
0
    def test_uuid_comp(self):
        for _ in range(1000):
            ll = random.choice(test_uuids)
            rr = random.choice(test_uuids)

            # Testing comparison operators.
            # Explicitly use > and not assertGreater;
            # we want all comparisons to be explicit in this test.

            if ll > rr:
                self.assertTrue(c_UUID(ll.bytes) > rr)
                self.assertTrue(c_UUID(ll.bytes) > c_UUID(rr.bytes))
                self.assertTrue(ll > c_UUID(rr.bytes))

            if ll < rr:
                self.assertTrue(c_UUID(ll.bytes) < rr)
                self.assertTrue(c_UUID(ll.bytes) < c_UUID(rr.bytes))
                self.assertTrue(ll < c_UUID(rr.bytes))

            if ll >= rr:
                self.assertTrue(c_UUID(ll.bytes) >= rr)
                self.assertTrue(c_UUID(ll.bytes) >= c_UUID(rr.bytes))
                self.assertTrue(ll >= c_UUID(rr.bytes))

            if ll <= rr:
                self.assertTrue(c_UUID(ll.bytes) <= rr)
                self.assertTrue(c_UUID(ll.bytes) <= c_UUID(rr.bytes))
                self.assertTrue(ll <= c_UUID(rr.bytes))

            if ll != rr:
                self.assertTrue(c_UUID(ll.bytes) != rr)
                self.assertTrue(c_UUID(ll.bytes) != c_UUID(rr.bytes))
                self.assertTrue(ll != c_UUID(rr.bytes))

            if ll == rr:
                self.assertTrue(c_UUID(ll.bytes) == rr)
                self.assertTrue(c_UUID(ll.bytes) == c_UUID(rr.bytes))
                self.assertTrue(ll == c_UUID(rr.bytes))

            self.assertTrue(c_UUID(ll.bytes) >= ll)
            self.assertTrue(c_UUID(ll.bytes) <= ll)

            self.assertTrue(c_UUID(ll.bytes) == ll)
            self.assertTrue(c_UUID(ll.bytes) == ll)
Пример #11
0
import uuid
from uuid import UUID as std_UUID
from edgedb.protocol.protocol import UUID as c_UUID

import time

ubytes = uuid.uuid4().bytes
ustr = str(std_UUID(bytes=ubytes))

print(str(std_UUID(bytes=ubytes)))
print(str(c_UUID(ubytes)))

N = 1_000_000

assert isinstance(c_UUID(ubytes), std_UUID)
assert c_UUID(ubytes).bytes == std_UUID(bytes=ubytes).bytes, \
    f'{ubytes}: {c_UUID(ubytes).bytes}'
assert c_UUID(ubytes).int == std_UUID(bytes=ubytes).int
assert c_UUID(str(std_UUID(bytes=ubytes))).int == std_UUID(bytes=ubytes).int
assert str(c_UUID(ubytes)) == str(std_UUID(bytes=ubytes))

print()

print(repr(std_UUID(bytes=ubytes)))
print(repr(c_UUID(ubytes)))

print()

st = time.monotonic()
for _ in range(N):
    std_UUID(bytes=ubytes)