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

Method test_uuid6_node

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

Source from the content-addressed store, hash-verified

795 self.assertLess(len(uuids), N, 'collision property does not hold')
796
797 def test_uuid6_node(self):
798 # Make sure the given node ID appears in the UUID.
799 #
800 # Note: when no node ID is specified, the same logic as for UUIDv1
801 # is applied to UUIDv6. In particular, there is no need to test that
802 # getnode() correctly returns positive integers of exactly 48 bits
803 # since this is done in test_uuid1_eui64().
804 self.assertLessEqual(self.uuid.uuid6().node.bit_length(), 48)
805
806 self.assertEqual(self.uuid.uuid6(0).node, 0)
807
808 # tests with explicit values
809 max_node = 0xffff_ffff_ffff
810 self.assertEqual(self.uuid.uuid6(max_node).node, max_node)
811 big_node = 0xE_1234_5678_ABCD # 52-bit node
812 res_node = 0x0_1234_5678_ABCD # truncated to 48 bits
813 self.assertEqual(self.uuid.uuid6(big_node).node, res_node)
814
815 # randomized tests
816 for _ in range(10):
817 # node with > 48 bits is truncated
818 for b in [24, 48, 72]:
819 node = (1 << (b - 1)) | random.getrandbits(b)
820 with self.subTest(node=node, bitlen=b):
821 self.assertEqual(node.bit_length(), b)
822 u = self.uuid.uuid6(node=node)
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.

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