From aee2898bab2928f01df17e35246094bd10951c83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A9n=C3=A9dikt=20Tran?= <10796600+picnixz@users.noreply.github.com> Date: Thu, 19 Dec 2024 18:00:26 +0100 Subject: [PATCH] improve UUIDv7 tests readability --- Lib/test/test_uuid.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Lib/test/test_uuid.py b/Lib/test/test_uuid.py index f3dae65c0007be..6361818f9cf669 100755 --- a/Lib/test/test_uuid.py +++ b/Lib/test/test_uuid.py @@ -704,7 +704,7 @@ def test_uuid7(self): random_bits = counter << 32 | tail # set all remaining MSB of fake random bits to 1 to ensure that - # the implementation correctly remove them + # the implementation correctly removes them random_bits = (((1 << 7) - 1) << 73) | random_bits random_data = random_bits.to_bytes(10) @@ -754,7 +754,7 @@ def test_uuid7_monotonicity(self): with mock.patch.multiple( self.uuid, _last_timestamp_v7=0, - _last_counter_v7=0 + _last_counter_v7=0, ): # 1 Jan 2023 12:34:56.123_456_789 timestamp_ns = 1672533296_123_456_789 # ns precision @@ -764,6 +764,7 @@ def test_uuid7_monotonicity(self): counter_hi = random.getrandbits(11) counter_lo = random.getrandbits(29) counter = (counter_hi << 30) | counter_lo + self.assertLess(counter + 1, 0x3ff_ffff_ffff) tail = random.getrandbits(32) random_bits = counter << 32 | tail @@ -816,6 +817,7 @@ def test_uuid7_timestamp_backwards(self): counter_hi = random.getrandbits(11) counter_lo = random.getrandbits(29) counter = (counter_hi << 30) | counter_lo + self.assertLess(counter + 1, 0x3ff_ffff_ffff) tail_bytes = os.urandom(4) tail = int.from_bytes(tail_bytes) @@ -854,7 +856,7 @@ def test_uuid7_overflow_counter(self): new_counter = (new_counter_hi << 30) | new_counter_lo tail = random.getrandbits(32) - random_bits = new_counter << 32 | tail + random_bits = (new_counter << 32) | tail random_data = random_bits.to_bytes(10) with (