Skip to content
Merged
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
14 changes: 14 additions & 0 deletions cirq-google/cirq_google/engine/engine_processor_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from __future__ import annotations

import datetime
import functools
from unittest import mock

import duet
Expand Down Expand Up @@ -194,6 +195,17 @@ def _to_timestamp(json_string):
)


class _FrozenDateTime(datetime.datetime):
"""Frozen datetime for testing time related behavior."""

_stock_datetime = datetime.datetime

@classmethod
@functools.cache
def now(cls, tz=None):
return cls._stock_datetime.now(tz)


class FakeEngineContext(EngineContext):
"""Fake engine context for testing."""

Expand Down Expand Up @@ -769,6 +781,7 @@ def test_get_schedule_filter_by_time_slot(list_time_slots):
)


@mock.patch('datetime.datetime', _FrozenDateTime)
@mock.patch('cirq_google.engine.engine_client.EngineClient.list_time_slots_async')
def test_get_schedule_time_filter_behavior(list_time_slots):
list_time_slots.return_value = []
Expand Down Expand Up @@ -811,6 +824,7 @@ def test_get_schedule_time_filter_behavior(list_time_slots):
list_time_slots.assert_called_with('proj', 'p0', f'start_time < {utc_ts}')


@mock.patch('datetime.datetime', _FrozenDateTime)
@mock.patch('cirq_google.engine.engine_client.EngineClient.list_reservations_async')
def test_list_reservations_time_filter_behavior(list_reservations):
list_reservations.return_value = []
Expand Down
Loading