Skip to content

Commit ab4b2b0

Browse files
authored
Merge pull request #864 from codeflash-ai/non-round-time
more realistic time mocking
2 parents de9837a + 5439348 commit ab4b2b0

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

codeflash/verification/pytest_plugin.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ def _apply_deterministic_patches() -> None:
9898
_original_random = random.random
9999

100100
# Fixed deterministic values
101-
fixed_timestamp = 1609459200.0 # 2021-01-01 00:00:00 UTC
102-
fixed_datetime = datetime.datetime(2021, 1, 1, 0, 0, 0, tzinfo=datetime.timezone.utc)
101+
fixed_timestamp = 1761717605.108106
102+
fixed_datetime = datetime.datetime(2021, 1, 1, 2, 5, 10, tzinfo=datetime.timezone.utc)
103103
fixed_uuid = uuid.UUID("12345678-1234-5678-9abc-123456789012")
104104

105105
# Counter for perf_counter to maintain relative timing

tests/test_pytest_plugin_deterministic_patches.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ def setup_deterministic_environment(self):
4848
original_os_urandom = os.urandom
4949

5050
# Create deterministic implementations (matching pytest_plugin.py)
51-
fixed_timestamp = 1609459200.0 # 2021-01-01 00:00:00 UTC
52-
fixed_datetime = datetime.datetime(2021, 1, 1, 0, 0, 0, tzinfo=datetime.timezone.utc)
51+
fixed_timestamp = 1761717605.108106
52+
fixed_datetime = datetime.datetime(2021, 1, 1, 2, 5, 10, tzinfo=datetime.timezone.utc)
5353
fixed_uuid = uuid.UUID("12345678-1234-5678-9abc-123456789012")
5454

5555
# Counter for perf_counter
@@ -159,7 +159,7 @@ def mock_datetime_utcnow():
159159

160160
def test_time_time_deterministic(self, setup_deterministic_environment):
161161
"""Test that time.time() returns a fixed deterministic value."""
162-
expected_timestamp = 1609459200.0 # 2021-01-01 00:00:00 UTC
162+
expected_timestamp = 1761717605.108106
163163

164164
# Call multiple times and verify consistent results
165165
result1 = time.time()
@@ -311,7 +311,7 @@ def test_datetime_mocks_available(self, setup_deterministic_environment):
311311
result1 = mock_now()
312312
result2 = mock_utcnow()
313313

314-
expected_dt = datetime.datetime(2021, 1, 1, 0, 0, 0, tzinfo=datetime.timezone.utc)
314+
expected_dt = datetime.datetime(2021, 1, 1, 2, 5, 10, tzinfo=datetime.timezone.utc)
315315
assert result1 == expected_dt
316316
assert result2 == expected_dt
317317

@@ -355,7 +355,7 @@ def test_different_uuid_functions_same_result(self, setup_deterministic_environm
355355
def test_patches_applied_correctly(self, setup_deterministic_environment):
356356
"""Test that patches are applied correctly."""
357357
# Test that functions return expected deterministic values
358-
assert time.time() == 1609459200.0
358+
assert time.time() == 1761717605.108106
359359
assert uuid.uuid4() == uuid.UUID("12345678-1234-5678-9abc-123456789012")
360360
assert random.random() == 0.123456789
361361
assert os.urandom(4) == b"\x42\x42\x42\x42"
@@ -378,7 +378,7 @@ def test_edge_cases(self, setup_deterministic_environment):
378378
# Test with different timezone
379379
utc_tz = datetime.timezone.utc
380380
result_with_tz = mock_now(utc_tz)
381-
expected_with_tz = datetime.datetime(2021, 1, 1, 0, 0, 0, tzinfo=utc_tz)
381+
expected_with_tz = datetime.datetime(2021, 1, 1, 2, 5, 10, tzinfo=datetime.timezone.utc)
382382
assert result_with_tz == expected_with_tz
383383

384384
def test_integration_with_actual_optimization_scenario(self, setup_deterministic_environment):

0 commit comments

Comments
 (0)