MCPcopy Index your code
hub / github.com/RustPython/RustPython / test_uuid6_uniqueness

Method test_uuid6_uniqueness

Lib/test/test_uuid.py:762–790  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

760 equal(u.fields[5], fake_node_value)
761
762 def test_uuid6_uniqueness(self):
763 # Test that UUIDv6-generated values are unique.
764
765 # Unlike UUIDv8, only 62 bits can be randomized for UUIDv6.
766 # In practice, however, it remains unlikely to generate two
767 # identical UUIDs for the same 60-bit timestamp if neither
768 # the node ID nor the clock sequence is specified.
769 uuids = {self.uuid.uuid6() for _ in range(1000)}
770 self.assertEqual(len(uuids), 1000)
771 versions = {u.version for u in uuids}
772 self.assertSetEqual(versions, {6})
773
774 timestamp = 0x1ec9414c_232a_b00
775 fake_nanoseconds = (timestamp - 0x1b21dd21_3814_000) * 100
776
777 with mock.patch('time.time_ns', return_value=fake_nanoseconds):
778 def gen():
779 with mock.patch.object(self.uuid, '_last_timestamp_v6', None):
780 return self.uuid.uuid6(node=0, clock_seq=None)
781
782 # By the birthday paradox, sampling N = 1024 UUIDs with identical
783 # node IDs and timestamps results in duplicates with probability
784 # close to 1 (not having a duplicate happens with probability of
785 # order 1E-15) since only the 14-bit clock sequence is randomized.
786 N = 1024
787 uuids = {gen() for _ in range(N)}
788 self.assertSetEqual({u.node for u in uuids}, {0})
789 self.assertSetEqual({u.time for u in uuids}, {timestamp})
790 self.assertLess(len(uuids), N, 'collision property does not hold')
791
792 def test_uuid6_node(self):
793 # Make sure the given node ID appears in the UUID.

Callers

nothing calls this directly

Calls 5

lenFunction · 0.85
assertSetEqualMethod · 0.80
genFunction · 0.70
assertEqualMethod · 0.45
assertLessMethod · 0.45

Tested by

no test coverage detected