Skip to content

Commit 9a846e6

Browse files
authored
fix: Fix typing in examples and tests (#166)
Make mypy checking more strict for Pydantic models and fix or suppress the resulting errors.
1 parent 281da01 commit 9a846e6

File tree

16 files changed

+118
-66
lines changed

16 files changed

+118
-66
lines changed

examples/assetmanagement/assets.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from datetime import datetime, timezone
2+
13
from nisystemlink.clients.assetmanagement import AssetManagementClient
24
from nisystemlink.clients.assetmanagement.models import (
35
AssetBusType,
@@ -27,7 +29,7 @@
2729
model_name="NI PXIe-6368",
2830
serial_number="01BB877A",
2931
vendor_name="NI",
30-
vendor_number="4244",
32+
vendor_number=4244,
3133
bus_type=AssetBusType.ACCESSORY,
3234
name="PCISlot2",
3335
asset_type=AssetType.DEVICE_UNDER_TEST,
@@ -41,7 +43,7 @@
4143
self_calibration=SelfCalibration(
4244
temperature_sensors=[TemperatureSensor(name="Sensor0", reading=25.8)],
4345
is_limited=False,
44-
date="2022-06-07T18:58:05.000Z",
46+
date=datetime(2022, 6, 7, 18, 58, 5, tzinfo=timezone.utc),
4547
),
4648
is_NI_asset=True,
4749
workspace="your-workspace-id",
@@ -50,19 +52,23 @@
5052
),
5153
external_calibration=ExternalCalibration(
5254
temperature_sensors=[TemperatureSensor(name="Sensor0", reading=25.8)],
53-
date="2022-06-07T18:58:05.000Z",
55+
date=datetime(2022, 6, 7, 18, 58, 5, tzinfo=timezone.utc),
5456
recommended_interval=10,
55-
next_recommended_date="2023-11-14T20:42:11.583Z",
56-
next_custom_due_date="2024-11-14T20:42:11.583Z",
57-
resolved_due_date="2022-06-07T18:58:05.000Z",
57+
next_recommended_date=datetime(
58+
2023, 11, 14, 20, 42, 11, 583000, tzinfo=timezone.utc
59+
),
60+
next_custom_due_date=datetime(
61+
2024, 11, 14, 20, 42, 11, 583000, tzinfo=timezone.utc
62+
),
63+
resolved_due_date=datetime(2022, 6, 7, 18, 58, 5, tzinfo=timezone.utc),
5864
),
5965
properties={"Key1": "Value1"},
6066
keywords=["Keyword1"],
6167
discovery_type=AssetDiscoveryType.MANUAL,
6268
file_ids=["608a5684800e325b48837c2a"],
6369
supports_self_test=True,
6470
supports_reset=True,
65-
partNumber="A1234 B5",
71+
part_number="A1234 B5",
6672
)
6773
]
6874

@@ -80,8 +86,8 @@
8086
take=1,
8187
descending=False,
8288
calibratable_only=False,
83-
returnCount=False,
84-
)
89+
return_count=False,
90+
) # type: ignore
8591
client.query_assets(query=query_asset_request)
8692

8793
# Link files to the created asset.

examples/dataframe/create_write_data.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,15 @@
3131

3232
# Append via explicit AppendTableDataRequest (JSON)
3333
frame_request = DataFrame(
34-
data=[[i, random.random(), datetime.now().isoformat()] for i in range(3)]
34+
data=[[str(i), str(random.random()), datetime.now().isoformat()] for i in range(3)]
3535
)
3636
client.append_table_data(table_id, AppendTableDataRequest(frame=frame_request))
3737

3838
# Append via DataFrame model directly (JSON)
3939
frame_direct = DataFrame(
40-
data=[[i + 3, random.random(), datetime.now().isoformat()] for i in range(3)]
40+
data=[
41+
[str(i + 3), str(random.random()), datetime.now().isoformat()] for i in range(3)
42+
]
4143
)
4244
client.append_table_data(table_id, frame_direct)
4345

examples/dataframe/export_data.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
from nisystemlink.clients.dataframe.models import (
55
ColumnFilter,
66
ColumnOrderBy,
7+
ColumnType,
8+
DataType,
79
ExportFormat,
810
ExportTableDataRequest,
911
FilterOperation,
@@ -14,13 +16,26 @@
1416
# List a table
1517
response = client.list_tables(take=1)
1618
table = response.tables[0]
19+
index_column = next(
20+
(col for col in table.columns if col.column_type == ColumnType.Index)
21+
)
22+
order_column = next(
23+
(col for col in table.columns if col.name != index_column.name), index_column
24+
)
25+
filter_value = (
26+
"0001-01-01T00:00:00Z" if index_column.data_type == DataType.Timestamp else "0"
27+
)
1728

1829
# Export table data with query options
1930
request = ExportTableDataRequest(
20-
columns=["col1"],
21-
order_by=[ColumnOrderBy(column="col2", descending=True)],
31+
columns=[index_column.name],
32+
order_by=[ColumnOrderBy(column=order_column.name, descending=True)],
2233
filters=[
23-
ColumnFilter(column="col1", operation=FilterOperation.NotEquals, value="0")
34+
ColumnFilter(
35+
column=index_column.name,
36+
operation=FilterOperation.NotEquals,
37+
value=filter_value,
38+
)
2439
],
2540
response_format=ExportFormat.CSV,
2641
)
Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from nisystemlink.clients.dataframe import DataFrameClient
22
from nisystemlink.clients.dataframe.models import (
3+
ColumnType,
34
DecimationMethod,
45
DecimationOptions,
56
QueryDecimatedDataRequest,
@@ -10,17 +11,22 @@
1011
# List a table
1112
response = client.list_tables(take=1)
1213
table = response.tables[0]
14+
y_column = next(
15+
(col for col in table.columns if col.column_type != ColumnType.Index),
16+
table.columns[0],
17+
)
1318

1419
# Get table metadata by table id
1520
client.get_table_metadata(table.id)
1621

1722
# Query decimated table data
1823
request = QueryDecimatedDataRequest(
1924
decimation=DecimationOptions(
20-
x_column="index",
21-
y_columns=["col1"],
25+
x_column=None,
26+
y_columns=[y_column.name],
2227
intervals=1,
2328
method=DecimationMethod.MaxMin,
2429
)
2530
)
26-
client.query_decimated_data(table.id, request)
31+
rows = client.query_decimated_data(table.id, request)
32+
print(rows.frame.model_dump())

examples/spec/get_and_query_specs.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
ConditionRange,
66
ConditionType,
77
CreateSpecificationsRequest,
8+
CreateSpecificationsRequestObject,
89
NumericConditionValue,
910
QuerySpecificationsRequest,
10-
SpecificationDefinition,
1111
SpecificationLimit,
1212
SpecificationType,
1313
)
@@ -22,7 +22,7 @@
2222
# Create the spec requests
2323
product = "Amplifier"
2424
spec_requests = [
25-
SpecificationDefinition(
25+
CreateSpecificationsRequestObject(
2626
product_id=product,
2727
spec_id="spec1",
2828
type=SpecificationType.PARAMETRIC,
@@ -31,7 +31,7 @@
3131
limit=SpecificationLimit(min=1.2, max=1.5),
3232
unit="mV",
3333
),
34-
SpecificationDefinition(
34+
CreateSpecificationsRequestObject(
3535
product_id=product,
3636
spec_id="spec2",
3737
type=SpecificationType.PARAMETRIC,
@@ -58,7 +58,7 @@
5858
),
5959
],
6060
),
61-
SpecificationDefinition(
61+
CreateSpecificationsRequestObject(
6262
product_id=product,
6363
spec_id="spec3",
6464
type=SpecificationType.FUNCTIONAL,

examples/spec/update_and_delete_specs.py

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1+
from typing import cast
2+
13
from nisystemlink.clients.core import HttpConfiguration
24
from nisystemlink.clients.spec import SpecClient
35
from nisystemlink.clients.spec.models import (
46
QuerySpecificationsRequest,
5-
SpecificationDefinition,
67
SpecificationType,
78
UpdateSpecificationsRequest,
9+
UpdateSpecificationsRequestObject,
810
)
911

1012
# Setup the server configuration to point to your instance of SystemLink Enterprise
@@ -27,22 +29,22 @@
2729
print(f"Original spec1 block: {original_spec1.block}")
2830
print(f"Original spec1 version: {original_spec1.version}")
2931

30-
# make the modifications
31-
modified_spec = SpecificationDefinition(
32-
id=original_spec1.id,
33-
product_id=original_spec1.product_id,
34-
spec_id=original_spec1.spec_id,
35-
type=SpecificationType.FUNCTIONAL,
36-
keywords=["work", "reviewed"],
37-
block="modifiedBlock",
38-
version=original_spec1.version,
39-
workspace=original_spec1.workspace,
40-
)
41-
update_response = client.update_specs(
42-
specs=UpdateSpecificationsRequest(specs=[modified_spec])
43-
)
44-
if update_response and update_response.updated_specs:
45-
print(f"New spec1 version: {update_response.updated_specs[0].version}")
32+
# make the modifications
33+
modified_spec = UpdateSpecificationsRequestObject(
34+
id=cast(str, original_spec1.id),
35+
product_id=cast(str, original_spec1.product_id),
36+
spec_id=cast(str, original_spec1.spec_id),
37+
type=SpecificationType.FUNCTIONAL,
38+
keywords=["work", "reviewed"],
39+
block="modifiedBlock",
40+
version=cast(int, original_spec1.version),
41+
workspace=cast(str, original_spec1.workspace),
42+
)
43+
update_response = client.update_specs(
44+
specs=UpdateSpecificationsRequest(specs=[modified_spec])
45+
)
46+
if update_response and update_response.updated_specs:
47+
print(f"New spec1 version: {update_response.updated_specs[0].version}")
4648

4749
# query again to see new version
4850
response = client.query_specs(

examples/test_plan/test_plan_templates.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
test_program="TP-INT-002",
3030
estimated_duration_in_seconds=86400,
3131
system_filter="os:linux AND arch:x64",
32-
dut_Filter="modelName = 'cRIO-9045' AND serialNumber = '01E82ED0'",
32+
dut_filter="modelName = 'cRIO-9045' AND serialNumber = '01E82ED0'",
3333
execution_actions=[
3434
ManualExecution(action="boot", type="MANUAL"),
3535
JobExecution(

examples/test_plan/test_plans.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
dut_serial_number="serial_number_123",
3636
test_program="TP-Integration-001",
3737
system_filter="os:linux AND arch:x64",
38-
dut_Filter="modelName = 'cRIO-9045' AND serialNumber = '01E82ED0'",
38+
dut_filter="modelName = 'cRIO-9045' AND serialNumber = '01E82ED0'",
3939
workspace="your_workspace_id",
4040
file_ids_from_template=["file1", "file2"],
4141
dashboard=Dashboard(
@@ -69,7 +69,7 @@
6969

7070
# Query test plan using id.
7171
query_test_plans_request = QueryTestPlansRequest(
72-
skip=0, take=1, descending=False, returnCount=False
72+
take=1, descending=False, return_count=False
7373
)
7474
client.query_test_plans(query_request=query_test_plans_request)
7575

examples/testmonitor/steps.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from typing import cast
2+
13
from nisystemlink.clients.testmonitor import TestMonitorClient
24
from nisystemlink.clients.testmonitor.models import (
35
CreateResultRequest,
@@ -44,7 +46,7 @@ def create_test_result():
4446
create_response = create_test_result()
4547

4648
# Create the step requests
47-
result_id = create_response.results[0].result_id
49+
result_id = cast(str, create_response.results[0].id)
4850
step_requests = [
4951
CreateStepRequest(
5052
step_id="step1",
@@ -89,7 +91,7 @@ def create_test_result():
8991
steps=[
9092
UpdateStepRequest(
9193
step_id=step.step_id,
92-
result_id=step.result_id,
94+
result_id=cast(str, step.result_id),
9395
data=StepData(
9496
text="My output string",
9597
parameters=[
@@ -116,7 +118,9 @@ def create_test_result():
116118
# delete all steps at once
117119
delete_response = client.delete_steps(
118120
steps=[
119-
StepIdResultIdPair(step_id=step.step_id, result_id=step.result_id)
121+
StepIdResultIdPair(
122+
step_id=cast(str, step.step_id), result_id=cast(str, step.result_id)
123+
)
120124
for step in queried_steps
121125
]
122126
)

mypy.ini

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ warn_unused_configs=True
55
plugins = pydantic.mypy
66
ignore_missing_imports=True
77

8+
[pydantic-mypy]
9+
init_typed=True
10+
warn_required_dynamic_aliases=True
11+
warn_untyped_fields=True
12+
813
[mypy-nisystemlink.*]
914
disallow_untyped_calls=True
1015
disallow_untyped_defs=True

0 commit comments

Comments
 (0)