Skip to content

Commit 5c4beb2

Browse files
committed
mypy
1 parent 6ac259b commit 5c4beb2

4 files changed

Lines changed: 85 additions & 41 deletions

File tree

python/lib/sift_client/_internal/low_level_wrappers/test_results.py

Lines changed: 34 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ def simulate_update_test_report_response(
179179
if "run_id" in update_mask_paths:
180180
updates["run_id"] = proto.run_id if proto.run_id else None
181181
if "metadata" in update_mask_paths:
182-
updates["metadata"] = metadata_proto_to_dict(proto.metadata)
182+
updates["metadata"] = metadata_proto_to_dict(proto.metadata) # type: ignore
183183
if "is_archived" in update_mask_paths:
184184
updates["is_archived"] = proto.is_archived
185185

@@ -889,78 +889,79 @@ async def replay_log_file(
889889
json_str = match.group(3)
890890

891891
if request_type == "CreateTestReport":
892-
request = CreateTestReportRequest()
893-
json_format.Parse(json_str, request)
894-
simulated_proto = self.simulate_create_test_report_response(request)
892+
create_report_req = CreateTestReportRequest()
893+
json_format.Parse(json_str, create_report_req)
894+
report_proto = self.simulate_create_test_report_response(create_report_req)
895895
if response_id:
896-
simulated_proto.test_report_id = response_id
897-
simulated_report = TestReport._from_proto(simulated_proto)
896+
report_proto.test_report_id = response_id
897+
simulated_report = TestReport._from_proto(report_proto)
898898

899899
elif request_type == "CreateTestStep":
900-
request = CreateTestStepRequest()
901-
json_format.Parse(json_str, request)
902-
simulated_proto = self.simulate_create_test_step_response(request)
900+
create_step_req = CreateTestStepRequest()
901+
json_format.Parse(json_str, create_step_req)
902+
step_proto = self.simulate_create_test_step_response(create_step_req)
903903
if response_id:
904-
simulated_proto.test_step_id = response_id
905-
step = TestStep._from_proto(simulated_proto)
904+
step_proto.test_step_id = response_id
905+
step = TestStep._from_proto(step_proto)
906906
simulated_steps_by_id[step._id_or_error] = step
907907
simulated_steps_order.append(step._id_or_error)
908908

909909
elif request_type == "CreateTestMeasurement":
910-
request = CreateTestMeasurementRequest()
911-
json_format.Parse(json_str, request)
912-
simulated_proto = self.simulate_create_test_measurement_response(request)
910+
create_meas_req = CreateTestMeasurementRequest()
911+
json_format.Parse(json_str, create_meas_req)
912+
meas_proto = self.simulate_create_test_measurement_response(create_meas_req)
913913
if response_id:
914-
simulated_proto.measurement_id = response_id
915-
measurement = TestMeasurement._from_proto(simulated_proto)
914+
meas_proto.measurement_id = response_id
915+
measurement = TestMeasurement._from_proto(meas_proto)
916916
simulated_measurements_by_id[measurement._id_or_error] = measurement
917917
simulated_measurements_order.append(measurement._id_or_error)
918918

919919
elif request_type == "CreateTestMeasurements":
920-
request = CreateTestMeasurementsRequest()
921-
json_format.Parse(json_str, request)
920+
create_batch_req = CreateTestMeasurementsRequest()
921+
json_format.Parse(json_str, create_batch_req)
922922
original_ids = response_id.split(",") if response_id else []
923-
for i, tm_proto in enumerate(request.test_measurements):
923+
for i, tm_proto in enumerate(create_batch_req.test_measurements):
924924
single_request = CreateTestMeasurementRequest(test_measurement=tm_proto)
925-
simulated_proto = self.simulate_create_test_measurement_response(
925+
batch_meas_proto = self.simulate_create_test_measurement_response(
926926
single_request
927927
)
928928
if i < len(original_ids):
929-
simulated_proto.measurement_id = original_ids[i]
930-
measurement = TestMeasurement._from_proto(simulated_proto)
929+
batch_meas_proto.measurement_id = original_ids[i]
930+
measurement = TestMeasurement._from_proto(batch_meas_proto)
931931
simulated_measurements_by_id[measurement._id_or_error] = measurement
932932
simulated_measurements_order.append(measurement._id_or_error)
933933

934934
elif request_type == "UpdateTestReport":
935935
if simulated_report is None:
936936
raise ValueError("UpdateTestReport found before CreateTestReport")
937-
request = UpdateTestReportRequest()
938-
json_format.Parse(json_str, request)
937+
update_report_req = UpdateTestReportRequest()
938+
json_format.Parse(json_str, update_report_req)
939939
simulated_report = self.simulate_update_test_report_response(
940-
request, existing=simulated_report
940+
update_report_req, existing=simulated_report
941941
)
942942

943943
elif request_type == "UpdateTestStep":
944-
request = UpdateTestStepRequest()
945-
json_format.Parse(json_str, request)
946-
step_id = request.test_step.test_step_id
944+
update_step_req = UpdateTestStepRequest()
945+
json_format.Parse(json_str, update_step_req)
946+
step_id = update_step_req.test_step.test_step_id
947947
if step_id not in simulated_steps_by_id:
948948
raise ValueError(f"UpdateTestStep for unknown step: {step_id}")
949949
simulated_steps_by_id[step_id] = self.simulate_update_test_step_response(
950-
request, existing=simulated_steps_by_id[step_id]
950+
update_step_req, existing=simulated_steps_by_id[step_id]
951951
)
952952

953953
elif request_type == "UpdateTestMeasurement":
954-
request = UpdateTestMeasurementRequest()
955-
json_format.Parse(json_str, request)
956-
measurement_id = request.test_measurement.measurement_id
954+
update_meas_req = UpdateTestMeasurementRequest()
955+
json_format.Parse(json_str, update_meas_req)
956+
measurement_id = update_meas_req.test_measurement.measurement_id
957957
if measurement_id not in simulated_measurements_by_id:
958958
raise ValueError(
959959
f"UpdateTestMeasurement for unknown measurement: {measurement_id}"
960960
)
961961
simulated_measurements_by_id[measurement_id] = (
962962
self.simulate_update_test_measurement_response(
963-
request, existing=simulated_measurements_by_id[measurement_id]
963+
update_meas_req,
964+
existing=simulated_measurements_by_id[measurement_id],
964965
)
965966
)
966967

python/lib/sift_client/_internal/rest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from typing_extensions import NotRequired
77
from urllib3.util import Retry
88

9-
from sift_client._internal.grpc.transport import _clean_uri
9+
from sift_client._internal.grpc_transport.transport import _clean_uri
1010

1111
_DEFAULT_REST_RETRY = Retry(total=3, status_forcelist=[500, 502, 503, 504], backoff_factor=1)
1212

python/lib/sift_client/resources/sync_stubs/__init__.pyi

Lines changed: 49 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ if TYPE_CHECKING:
1313
import pandas as pd
1414
import pyarrow as pa
1515

16+
from sift_client._internal.low_level_wrappers.test_results import (
17+
ReplayResult,
18+
)
1619
from sift_client.client import SiftClient
1720
from sift_client.sift_types.asset import Asset, AssetUpdate
1821
from sift_client.sift_types.calculated_channel import (
@@ -1703,49 +1706,60 @@ class TestResultsAPI:
17031706
"""
17041707
...
17051708

1706-
def create(self, test_report: TestReportCreate | dict) -> TestReport:
1709+
def create(
1710+
self, test_report: TestReportCreate | dict, log_file: str | Path | None = None
1711+
) -> TestReport:
17071712
"""Create a new test report.
17081713
17091714
Args:
17101715
test_report: The test report to create (can be TestReport or TestReportCreate).
1716+
log_file: If set, log the request to this file and return a simulated response.
17111717
17121718
Returns:
17131719
The created TestReport.
17141720
"""
17151721
...
17161722

17171723
def create_measurement(
1718-
self, test_measurement: TestMeasurementCreate | dict, update_step: bool = False
1724+
self,
1725+
test_measurement: TestMeasurementCreate | dict,
1726+
update_step: bool = False,
1727+
log_file: str | Path | None = None,
17191728
) -> TestMeasurement:
17201729
"""Create a new test measurement.
17211730
17221731
Args:
17231732
test_measurement: The test measurement to create (can be TestMeasurement or TestMeasurementCreate).
17241733
update_step: Whether to update the step to failed if the measurement is being created is failed.
1734+
log_file: If set, log the request to this file and return a simulated response.
17251735
17261736
Returns:
17271737
The created TestMeasurement.
17281738
"""
17291739
...
17301740

17311741
def create_measurements(
1732-
self, test_measurements: list[TestMeasurementCreate]
1742+
self, test_measurements: list[TestMeasurementCreate], log_file: str | Path | None = None
17331743
) -> tuple[int, list[str]]:
17341744
"""Create multiple test measurements in a single request.
17351745
17361746
Args:
17371747
test_measurements: The test measurements to create.
1748+
log_file: If set, log the request to this file and return a simulated response.
17381749
17391750
Returns:
17401751
A tuple of (measurements_created_count, measurement_ids).
17411752
"""
17421753
...
17431754

1744-
def create_step(self, test_step: TestStepCreate | dict) -> TestStep:
1755+
def create_step(
1756+
self, test_step: TestStepCreate | dict, log_file: str | Path | None = None
1757+
) -> TestStep:
17451758
"""Create a new test step.
17461759
17471760
Args:
17481761
test_step: The test step to create (can be TestStep or TestStepCreate).
1762+
log_file: If set, log the request to this file and return a simulated response.
17491763
17501764
Returns:
17511765
The created TestStep.
@@ -1949,6 +1963,21 @@ class TestResultsAPI:
19491963
"""
19501964
...
19511965

1966+
def replay_log_file(self, log_file: str | Path) -> ReplayResult:
1967+
"""Replay a log file by parsing each entry, simulating the results, then creating for real.
1968+
1969+
This method reads a log file created by the simulation logging, reconstructs
1970+
all the objects via simulation, and then creates them via the actual API.
1971+
IDs are mapped from simulated to real during the creation process.
1972+
1973+
Args:
1974+
log_file: Path to the log file to replay.
1975+
1976+
Returns:
1977+
A ReplayResult containing the created report, steps, and measurements.
1978+
"""
1979+
...
1980+
19521981
def unarchive(self, *, test_report: str | TestReport) -> TestReport:
19531982
"""Unarchive a test report.
19541983
@@ -1957,12 +1986,18 @@ class TestResultsAPI:
19571986
"""
19581987
...
19591988

1960-
def update(self, test_report: str | TestReport, update: TestReportUpdate | dict) -> TestReport:
1989+
def update(
1990+
self,
1991+
test_report: str | TestReport,
1992+
update: TestReportUpdate | dict,
1993+
log_file: str | Path | None = None,
1994+
) -> TestReport:
19611995
"""Update a TestReport.
19621996
19631997
Args:
19641998
test_report: The TestReport or test report ID to update.
19651999
update: Updates to apply to the TestReport.
2000+
log_file: If set, log the request to this file and return a simulated response.
19662001
19672002
Returns:
19682003
The updated TestReport.
@@ -1974,25 +2009,33 @@ class TestResultsAPI:
19742009
test_measurement: TestMeasurement,
19752010
update: TestMeasurementUpdate | dict,
19762011
update_step: bool = False,
2012+
log_file: str | Path | None = None,
19772013
) -> TestMeasurement:
19782014
"""Update a TestMeasurement.
19792015
19802016
Args:
19812017
test_measurement: The TestMeasurement or measurement ID to update.
19822018
update: Updates to apply to the TestMeasurement.
19832019
update_step: Whether to update the step to failed if the measurement is being updated to failed.
2020+
log_file: If set, log the request to this file and return a simulated response.
19842021
19852022
Returns:
19862023
The updated TestMeasurement.
19872024
"""
19882025
...
19892026

1990-
def update_step(self, test_step: str | TestStep, update: TestStepUpdate | dict) -> TestStep:
2027+
def update_step(
2028+
self,
2029+
test_step: str | TestStep,
2030+
update: TestStepUpdate | dict,
2031+
log_file: str | Path | None = None,
2032+
) -> TestStep:
19912033
"""Update a TestStep.
19922034
19932035
Args:
19942036
test_step: The TestStep or test step ID to update.
19952037
update: Updates to apply to the TestStep.
2038+
log_file: If set, log the request to this file and return a simulated response.
19962039
19972040
Returns:
19982041
The updated TestStep.

python/lib/sift_client/transport/grpc_transport.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from typing import Any
1414
from urllib.parse import urlparse
1515

16-
from sift_client._internal.grpc.transport import (
16+
from sift_client._internal.grpc_transport.transport import (
1717
SiftChannelConfig,
1818
use_sift_async_channel,
1919
)

0 commit comments

Comments
 (0)