Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions codeflash/verification/pytest_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ def _apply_deterministic_patches() -> None:
_original_random = random.random

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

# Counter for perf_counter to maintain relative timing
Expand Down
12 changes: 6 additions & 6 deletions tests/test_pytest_plugin_deterministic_patches.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ def setup_deterministic_environment(self):
original_os_urandom = os.urandom

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

# Counter for perf_counter
Expand Down Expand Up @@ -159,7 +159,7 @@ def mock_datetime_utcnow():

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

# Call multiple times and verify consistent results
result1 = time.time()
Expand Down Expand Up @@ -311,7 +311,7 @@ def test_datetime_mocks_available(self, setup_deterministic_environment):
result1 = mock_now()
result2 = mock_utcnow()

expected_dt = datetime.datetime(2021, 1, 1, 0, 0, 0, tzinfo=datetime.timezone.utc)
expected_dt = datetime.datetime(2021, 1, 1, 2, 5, 10, tzinfo=datetime.timezone.utc)
assert result1 == expected_dt
assert result2 == expected_dt

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

def test_integration_with_actual_optimization_scenario(self, setup_deterministic_environment):
Expand Down
Loading