Skip to content

Commit d69b437

Browse files
authored
Replace deprecated datetime.utcfromtimestamp (#7676)
Address DeprecationWarning about datetime.utcfromtimestamp. Also suppress pytest warning about using `pytest.raises` with an empty `match` pattern. Use `None` to skip checking exception message instead. Reference: https://docs.python.org/3.12/library/datetime.html#datetime.datetime.utcfromtimestamp
1 parent efb296e commit d69b437

File tree

4 files changed

+8
-8
lines changed

4 files changed

+8
-8
lines changed

cirq-google/cirq_google/engine/engine_processor_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -808,7 +808,7 @@ def test_get_schedule_time_filter_behavior(list_time_slots):
808808
processor.get_schedule(from_time=datetime.timedelta(seconds=200), to_time=None)
809809
list_time_slots.assert_called_with('proj', 'p0', f'end_time > {now + 200}')
810810

811-
test_timestamp = datetime.datetime.utcfromtimestamp(52)
811+
test_timestamp = datetime.datetime.fromtimestamp(52, datetime.UTC)
812812
utc_ts = int(test_timestamp.timestamp())
813813
processor.get_schedule(from_time=test_timestamp, to_time=None)
814814
list_time_slots.assert_called_with('proj', 'p0', f'end_time > {utc_ts}')
@@ -852,7 +852,7 @@ def test_list_reservations_time_filter_behavior(list_reservations):
852852
processor.list_reservations(from_time=datetime.timedelta(seconds=200), to_time=None)
853853
list_reservations.assert_called_with('proj', 'p0', f'end_time > {now + 200}')
854854

855-
test_timestamp = datetime.datetime.utcfromtimestamp(52)
855+
test_timestamp = datetime.datetime.fromtimestamp(52, datetime.UTC)
856856
utc_ts = int(test_timestamp.timestamp())
857857
processor.list_reservations(from_time=test_timestamp, to_time=None)
858858
list_reservations.assert_called_with('proj', 'p0', f'end_time > {utc_ts}')

cirq-ionq/cirq_ionq/ionq_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ def list_calibrations(
338338
"""
339339

340340
params = {}
341-
epoch = datetime.datetime.utcfromtimestamp(0)
341+
epoch = datetime.datetime.fromtimestamp(0, datetime.UTC)
342342
if start:
343343
params['start'] = int((start - epoch).total_seconds() * 1000)
344344
if end:

cirq-ionq/cirq_ionq/ionq_client_test.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def test_ionq_client_invalid_remote_host():
4040
for invalid_url in ('', 'url', 'http://', 'ftp://', 'http://'):
4141
with pytest.raises(AssertionError, match='not a valid url'):
4242
_ = ionq.ionq_client._IonQClient(remote_host=invalid_url, api_key='a')
43-
with pytest.raises(AssertionError, match=invalid_url):
43+
with pytest.raises(AssertionError, match=invalid_url or None):
4444
_ = ionq.ionq_client._IonQClient(remote_host=invalid_url, api_key='a')
4545

4646

@@ -1050,8 +1050,8 @@ def test_ionq_client_list_calibrations_dates(mock_get):
10501050
mock_get.return_value.json.return_value = {'calibrations': [{'id': '1'}, {'id': '2'}]}
10511051
client = ionq.ionq_client._IonQClient(remote_host='http://example.com', api_key='to_my_heart')
10521052
response = client.list_calibrations(
1053-
start=datetime.datetime.utcfromtimestamp(1284286794),
1054-
end=datetime.datetime.utcfromtimestamp(1284286795),
1053+
start=datetime.datetime.fromtimestamp(1284286794, datetime.UTC),
1054+
end=datetime.datetime.fromtimestamp(1284286795, datetime.UTC),
10551055
)
10561056
assert response == [{'id': '1'}, {'id': '2'}]
10571057

cirq-ionq/cirq_ionq/service_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,8 @@ def test_service_list_calibrations():
209209
calibrations = [{'id': '1', 'qubits': '1'}, {'id': '2', 'qubits': 2}]
210210
mock_client.list_calibrations.return_value = calibrations
211211
service._client = mock_client
212-
start = datetime.datetime.utcfromtimestamp(1284286794)
213-
end = datetime.datetime.utcfromtimestamp(1284286795)
212+
start = datetime.datetime.fromtimestamp(1284286794, datetime.UTC)
213+
end = datetime.datetime.fromtimestamp(1284286795, datetime.UTC)
214214

215215
listed_calibrations = service.list_calibrations(start=start, end=end, limit=10, batch_size=2)
216216
assert listed_calibrations[0].num_qubits() == 1

0 commit comments

Comments
 (0)