Skip to content

Commit

Permalink
improve UUIDv7 tests readability
Browse files Browse the repository at this point in the history
  • Loading branch information
picnixz committed Dec 19, 2024
1 parent f7f536e commit aee2898
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions Lib/test/test_uuid.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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 (
Expand Down

0 comments on commit aee2898

Please sign in to comment.