MCPcopy Index your code
hub / github.com/python/cpython / test_uuid6_clock_seq

Method test_uuid6_clock_seq

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

Source from the content-addressed store, hash-verified

823 self.assertEqual(u.node, node & 0xffff_ffff_ffff)
824
825 def test_uuid6_clock_seq(self):
826 # Make sure the supplied clock sequence appears in the UUID.
827 #
828 # For UUIDv6, clock sequence bits are stored from bit 48 to bit 62,
829 # with the convention that the least significant bit is bit 0 and
830 # the most significant bit is bit 127.
831 get_clock_seq = lambda u: (u.int >> 48) & 0x3fff
832
833 u = self.uuid.uuid6()
834 self.assertLessEqual(get_clock_seq(u).bit_length(), 14)
835
836 # tests with explicit values
837 big_clock_seq = 0xffff # 16-bit clock sequence
838 res_clock_seq = 0x3fff # truncated to 14 bits
839 u = self.uuid.uuid6(clock_seq=big_clock_seq)
840 self.assertEqual(get_clock_seq(u), res_clock_seq)
841
842 # some randomized tests
843 for _ in range(10):
844 # clock_seq with > 14 bits is truncated
845 for b in [7, 14, 28]:
846 node = random.getrandbits(48)
847 clock_seq = (1 << (b - 1)) | random.getrandbits(b)
848 with self.subTest(node=node, clock_seq=clock_seq, bitlen=b):
849 self.assertEqual(clock_seq.bit_length(), b)
850 u = self.uuid.uuid6(node=node, clock_seq=clock_seq)
851 self.assertEqual(get_clock_seq(u), clock_seq & 0x3fff)
852
853 def test_uuid6_test_vectors(self):
854 equal = self.assertEqual

Callers

nothing calls this directly

Calls 5

assertLessEqualMethod · 0.80
bit_lengthMethod · 0.80
assertEqualMethod · 0.45
getrandbitsMethod · 0.45
subTestMethod · 0.45

Tested by

no test coverage detected