Skip to content

Commit 5e07bed

Browse files
committed
update tests
1 parent d7cef11 commit 5e07bed

File tree

19 files changed

+99
-76
lines changed

19 files changed

+99
-76
lines changed

python/lib/sift_client/.ruff.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ ignore = ["W191", "D206", "D300", # https://docs.astral.sh/ruff/formatter/#confl
4949
"D105", # Missing docstring in magic method
5050
"D205", # 1 blank line required between summary line and description
5151
"D100", # Missing docstring in public module
52+
"C408", # Allow dict()
5253
]
5354

5455

python/lib/sift_client/_internal/gen_pyi.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,9 @@ def generate_stubs_for_module(path_arg: str | pathlib.Path) -> dict[pathlib.Path
143143
raw_doc = inspect.getdoc(cls) or ""
144144
if raw_doc:
145145
doc = (
146-
' """\n' + "\n".join(f" {l.strip()}" for l in raw_doc.splitlines()) + '\n """'
146+
' """\n'
147+
+ "\n".join(f" {l.strip()}" for l in raw_doc.splitlines())
148+
+ '\n """'
147149
)
148150
else:
149151
doc = " ..."

python/lib/sift_client/_tests/integrated/calculated_channels.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
CalculatedChannelUpdate,
1010
ChannelReference,
1111
)
12+
from sift_client.sift_types.calculated_channel import CalculatedChannelCreate
1213

1314
"""
1415
Comprehensive test script for calculated channels with extensive update field exercises.
@@ -55,18 +56,17 @@ async def main():
5556

5657
created_channels = []
5758
for i in range(num_channels):
58-
calculated_channel = client.calculated_channels.create(
59-
name=f"test_channel_{unique_name_suffix}_{i}",
60-
description=f"Test calculated channel {i} - initial description",
61-
expression="$1 / $2", # $1 = mainmotor.velocity, $2 = voltage
62-
channel_references=[
63-
ChannelReference(channel_reference="$1", channel_identifier="mainmotor.velocity"),
64-
ChannelReference(channel_reference="$2", channel_identifier="voltage"),
65-
],
66-
units="velocity/voltage",
67-
asset_ids=[asset_id],
68-
user_notes=f"Created for testing update fields - channel {i}",
69-
)
59+
new_chan = CalculatedChannelCreate(name=f"test_channel_{unique_name_suffix}_{i}",
60+
description=f"Test calculated channel {i} - initial description",
61+
expression="$1 / $2", # $1 = mainmotor.velocity, $2 = voltage
62+
expression_channel_references=[
63+
ChannelReference(channel_reference="$1", channel_identifier="mainmotor.velocity"),
64+
ChannelReference(channel_reference="$2", channel_identifier="voltage"),
65+
],
66+
units="velocity/voltage",
67+
asset_ids=[asset_id],
68+
user_notes=f"Created for testing update fields - channel {i}",)
69+
calculated_channel = client.calculated_channels.create(new_chan)
7070
created_channels.append(calculated_channel)
7171
print(
7272
f"Created calculated channel: {calculated_channel.name} (ID: {calculated_channel.id_})"
@@ -236,7 +236,7 @@ async def main():
236236
assert updated_channel_7.tag_ids == [], f"Tag IDs update failed: {updated_channel_7.tag_ids}"
237237

238238
versions = client.calculated_channels.list_versions(
239-
calculated_channel_id=channel_1.id_,
239+
calculated_channel=channel_1.id_,
240240
limit=10,
241241
)
242242
print(f"Found {len(versions)} versions for {created_channels[0].name}")

python/lib/sift_client/_tests/integrated/channels.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ async def main():
4141
# List channels for this asset (find a run w/ data)
4242
channels = []
4343
for run in runs:
44-
asset_channels = asset.channels(run_id=run.id_, limit=10)
44+
asset_channels = asset.channels(run=run.id_, limit=10)
4545
other_channels = []
4646
for c in asset_channels:
4747
if c.name in {"voltage", "gpio", "temperature", "mainmotor.velocity"}:
@@ -68,7 +68,7 @@ async def main():
6868
print("Getting data for multiple channels:")
6969
perf_start = time.perf_counter()
7070
channel_data = client.channels.get_data(
71-
run_id="1d5f5c93-eaaa-48f2-94ff-7ec4337faec7", channels=channels, limit=100
71+
run="1d5f5c93-eaaa-48f2-94ff-7ec4337faec7", channels=channels, limit=100
7272
)
7373
first_time = time.perf_counter() - perf_start
7474
start_time = None

python/lib/sift_client/_tests/integrated/ingestion.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,19 @@ async def main():
3535
asset = "ian-test-asset"
3636

3737
# TODO:Get user id from current user
38-
previously_created_runs = client.runs.list(
39-
name_regex="test-run-.*", created_by_user_id="1eba461b-fa36-4e98-8fe8-ff32d3e43a6e"
38+
previously_created_runs = client.runs.list_(
39+
name_regex="test-run-.*", created_by="1eba461b-fa36-4e98-8fe8-ff32d3e43a6e"
4040
)
4141
if previously_created_runs:
4242
print(f" Deleting previously created runs: {previously_created_runs}")
4343
for run in previously_created_runs:
4444
print(f" Deleting run: {run.name}")
4545
client.runs.archive(run=run)
4646

47-
run = client.runs.create(
47+
run = client.runs.create(dict(
4848
name=f"test-run-{datetime.now(tz=timezone.utc).timestamp()}",
49-
description="A test run created via the API",
50-
tags=["api-created", "test"],
49+
description="A test run created via the API",
50+
tags=["api-created", "test"],)
5151
)
5252

5353
regular_flow = Flow(

python/lib/sift_client/_tests/integrated/runs.py

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
import os
1212
from datetime import datetime, timedelta, timezone
1313

14+
import dotenv
15+
1416
from sift_client import SiftClient
1517

1618

@@ -52,7 +54,7 @@ async def main():
5254

5355
# Example 1: List all runs
5456
print("\n1. Listing all runs...")
55-
runs = client.runs.list(limit=5)
57+
runs = client.runs.list_(limit=5)
5658
print(f" Found {len(runs)} runs:")
5759
for run in runs:
5860
print(f" - {run.name} (ID: {run.id_}), Organization ID: {run.organization_id}")
@@ -61,7 +63,7 @@ async def main():
6163
print("\n2. Testing different filter options...")
6264

6365
# Get a sample run for testing filters
64-
sample_runs = client.runs.list(limit=3)
66+
sample_runs = client.runs.list_(limit=3)
6567
if not sample_runs:
6668
print(" No runs available for filter testing")
6769
return
@@ -71,38 +73,38 @@ async def main():
7173
# 2a: Filter by exact name
7274
print("\n 2a. Filter by exact name...")
7375
run_name = sample_run.name
74-
runs = client.runs.list(name=run_name, limit=5)
76+
runs = client.runs.list_(name=run_name, limit=5)
7577
print(f" Found {len(runs)} runs with exact name '{run_name}':")
7678
for run in runs:
7779
print(f" - {run.name} (ID: {run.id_})")
7880

7981
# 2b: Filter by name containing text
8082
print("\n 2b. Filter by name containing text...")
81-
runs = client.runs.list(name_contains="test", limit=5)
83+
runs = client.runs.list_(name_contains="test", limit=5)
8284
print(f" Found {len(runs)} runs with 'test' in name:")
8385
for run in runs:
8486
print(f" - {run.name}")
8587

8688
# 2c: Filter by name using regex
8789
print("\n 2c. Filter by name using regex...")
88-
runs = client.runs.list(name_regex=".*test.*", limit=5)
90+
runs = client.runs.list_(name_regex=".*test.*", limit=5)
8991
print(f" Found {len(runs)} runs with 'test' in name (regex):")
9092
for run in runs:
9193
print(f" - {run.name}")
9294

9395
# 2d: Filter by exact description
94-
print("\n 2d. Filter by exact description...")
96+
print("\n 2d. Filter by description contains...")
9597
if sample_run.description:
96-
runs = client.runs.list(description=sample_run.description, limit=5)
97-
print(f" Found {len(runs)} runs with exact description '{sample_run.description}':")
98+
runs = client.runs.list_(description_contains=sample_run.description, limit=5)
99+
print(f" Found {len(runs)} runs with description contains '{sample_run.description}':")
98100
for run in runs:
99101
print(f" - {run.name}: {run.description}")
100102
else:
101103
print(" No description available for testing")
102104

103105
# 2e: Filter by description containing text
104106
print("\n 2e. Filter by description containing text...")
105-
runs = client.runs.list(description_contains="test", limit=5)
107+
runs = client.runs.list_(description_contains="test", limit=5)
106108
print(f" Found {len(runs)} runs with 'test' in description:")
107109
for run in runs:
108110
print(f" - {run.name}: {run.description}")
@@ -112,8 +114,8 @@ async def main():
112114
# Calculate duration for sample run if it has start and stop times
113115
if sample_run.start_time and sample_run.stop_time:
114116
duration_seconds = int((sample_run.stop_time - sample_run.start_time).total_seconds())
115-
runs = client.runs.list(duration_seconds=duration_seconds, limit=5)
116-
print(f" Found {len(runs)} runs with duration {duration_seconds} seconds:")
117+
runs = client.runs.list_(duration_greater_than=timedelta(seconds=duration_seconds), limit=5)
118+
print(f" Found {len(runs)} runs with duration greater than {duration_seconds} seconds:")
117119
for run in runs:
118120
if run.start_time and run.stop_time:
119121
run_duration = int((run.stop_time - run.start_time).total_seconds())
@@ -124,18 +126,16 @@ async def main():
124126
# 2g: Filter by client key
125127
print("\n 2g. Filter by client key...")
126128
if sample_run.client_key:
127-
runs = client.runs.list(client_key=sample_run.client_key, limit=5)
128-
print(f" Found {len(runs)} runs with client key '{sample_run.client_key}':")
129-
for run in runs:
130-
print(f" - {run.name} (client_key: {run.client_key})")
129+
run = client.runs.get(client_key=sample_run.client_key)
130+
print(f" Found run with client key '{run.name}'")
131131
else:
132132
print(" No client key available for testing")
133133

134134
# 2h: Filter by asset ID
135135
print("\n 2h. Filter by asset ID...")
136136
if sample_run.asset_ids:
137137
asset_id = sample_run.asset_ids[0]
138-
runs = client.runs.list(asset_id=asset_id, limit=5)
138+
runs = client.runs.list_(assets=[asset_id], limit=5)
139139
print(f" Found {len(runs)} runs associated with asset {asset_id}:")
140140
for run in runs:
141141
print(f" - {run.name} (asset_ids: {list(run.asset_ids)})")
@@ -144,42 +144,42 @@ async def main():
144144

145145
# 2i: Filter by asset name
146146
print("\n 2i. Filter by asset name...")
147-
runs = client.runs.list(asset_name="NostromoLV426", limit=5)
147+
runs = client.runs.list_(assets=[client.assets.find(name="NostromoLV426")], limit=5)
148148
print(f" Found {len(runs)} runs associated with asset 'NostromoLV426':")
149149
for run in runs:
150150
print(f" - {run.name}")
151151

152152
# 2j: Filter by created by user ID
153153
print("\n 2j. Filter by created by user ID...")
154-
created_by_user_id = sample_run.created_by_user_id
155-
runs = client.runs.list(created_by_user_id=created_by_user_id, limit=5)
156-
print(f" Found {len(runs)} runs created by user {created_by_user_id}:")
154+
created_by = sample_run.created_by_user_id
155+
runs = client.runs.list_(created_by=created_by, limit=5)
156+
print(f" Found {len(runs)} runs created by user {created_by}:")
157157
for run in runs:
158-
print(f" - {run.name} (created by: {run.created_by_user_id})")
158+
print(f" - {run.name} (created by: {run.created_by})")
159159

160160
# 2l: Test ordering options
161161
print("\n 2l. Testing ordering options...")
162162

163163
# Order by name ascending
164-
runs = client.runs.list(order_by="name", limit=3)
164+
runs = client.runs.list_(order_by="name", limit=3)
165165
print(" First 3 runs ordered by name (ascending):")
166166
for run in runs:
167167
print(f" - {run.name}")
168168

169169
# Order by name descending
170-
runs = client.runs.list(order_by="name desc", limit=3)
170+
runs = client.runs.list_(order_by="name desc", limit=3)
171171
print(" First 3 runs ordered by name (descending):")
172172
for run in runs:
173173
print(f" - {run.name}")
174174

175175
# Order by creation date (newest first - default)
176-
runs = client.runs.list(order_by="created_date desc", limit=3)
176+
runs = client.runs.list_(order_by="created_date desc", limit=3)
177177
print(" First 3 runs ordered by creation date (newest first):")
178178
for run in runs:
179179
print(f" - {run.name} (created: {run.created_date})")
180180

181181
# Order by creation date (oldest first)
182-
runs = client.runs.list(order_by="created_date", limit=3)
182+
runs = client.runs.list_(order_by="created_date", limit=3)
183183
print(" First 3 runs ordered by creation date (oldest first):")
184184
for run in runs:
185185
print(f" - {run.name} (created: {run.created_date})")
@@ -206,22 +206,22 @@ async def main():
206206
start_time = datetime.now(timezone.utc)
207207
stop_time = start_time + timedelta(minutes=2)
208208

209-
previously_created_runs = client.runs.list(name_regex="Example Test Run.*")
209+
previously_created_runs = client.runs.list_(name_regex="Example Test Run.*")
210210
if previously_created_runs:
211211
print(f" Deleting previously created runs: {previously_created_runs}")
212212
for run in previously_created_runs:
213213
print(f" Deleting run: {run.name}")
214214
client.runs.archive(run=run)
215215

216-
new_run = client.runs.create(
216+
new_run = client.runs.create(dict(
217217
name=f"Example Test Run {datetime.now(tz=timezone.utc).strftime('%Y-%m-%d %H:%M:%S')}",
218218
description="A test run created via the API",
219219
tags=["api-created", "test"],
220220
start_time=start_time,
221221
stop_time=stop_time,
222222
# Use a unique client key for each run
223223
client_key=f"example-run-key-{datetime.now(tz=timezone.utc).timestamp()}",
224-
metadata=metadata,
224+
metadata=metadata,)
225225
)
226226
print(f" Created run: {new_run.name} (ID: {new_run.id_})")
227227
print(f" Client key: {new_run.client_key}")
@@ -257,7 +257,7 @@ async def main():
257257

258258
# Example 6: Associate assets with a run
259259
print("\n6. Associating assets with a run...")
260-
ongoing_runs = client.runs.list(
260+
ongoing_runs = client.runs.list_(
261261
name_regex="Example Test Run.*", include_archived=True, is_stopped=False
262262
)
263263
if ongoing_runs:
@@ -283,4 +283,5 @@ async def main():
283283

284284

285285
if __name__ == "__main__":
286+
dotenv.load_dotenv()
286287
asyncio.run(main())

python/lib/sift_client/examples/generic_workflow_example.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ async def main():
4848
else:
4949
# Create a calculated channel that divides mainmotor.velocity by voltage
5050
print("\nCreating calculated channel...")
51-
calculated_channel = client.calculated_channels.create(
51+
calculated_channel = client.calculated_channels.create(dict(
5252
name="velocity_per_voltage",
5353
description="Ratio of mainmotor velocity to voltage",
5454
expression="$1 / $2", # $1 = mainmotor.velocity, $2 = voltage
@@ -58,7 +58,7 @@ async def main():
5858
],
5959
units="velocity/voltage",
6060
asset_ids=[asset_id],
61-
user_notes="Created to monitor velocity-to-voltage ratio",
61+
user_notes="Created to monitor velocity-to-voltage ratio",)
6262
)
6363
print(
6464
f"Created calculated channel: {calculated_channel.name} (ID: {calculated_channel.calculated_channel_id})"

python/lib/sift_client/resources/assets.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ async def get(
4848
Returns:
4949
The Asset.
5050
"""
51+
asset: Asset | None
5152
if asset_id is not None:
5253
asset = await self._low_level_client.get_asset(asset_id)
5354
elif name is not None:
@@ -78,6 +79,7 @@ async def list_(
7879
modified_by: Any | str | None = None,
7980
# tags
8081
tags: list[Any] | list[str] | None = None,
82+
_tag_ids: list[str] | None = None,
8183
# metadata
8284
metadata: list[Any] | None = None,
8385
# common filters
@@ -101,6 +103,7 @@ async def list_(
101103
created_by: Filter assets created by this User or user ID.
102104
modified_by: Filter assets last modified by this User or user ID.
103105
tags: Filter assets with any of these Tags or tag names.
106+
_tag_ids: Filter assets with any of these Tag IDs.
104107
metadata: Filter assets by metadata criteria.
105108
description_contains: Partial description of the asset.
106109
include_archived: If True, include archived assets in results.
@@ -132,6 +135,8 @@ async def list_(
132135
]
133136
if asset_ids:
134137
filter_parts.append(cel.in_("asset_id", asset_ids))
138+
if _tag_ids:
139+
filter_parts.append(cel.in_("tag_id", _tag_ids))
135140
filter_query = cel.and_(*filter_parts)
136141

137142
assets = await self._low_level_client.list_all_assets(
@@ -169,7 +174,7 @@ async def update(self, asset: str | Asset, update: AssetUpdate | dict) -> Asset:
169174
The updated Asset.
170175
171176
"""
172-
asset_id = asset.id_ or "" if isinstance(asset, Asset) else asset
177+
asset_id = asset._id_or_error if isinstance(asset, Asset) else asset
173178
if isinstance(update, dict):
174179
update = AssetUpdate.model_validate(update)
175180
update.resource_id = asset_id
@@ -186,9 +191,9 @@ async def archive(self, asset: str | Asset, *, archive_runs: bool = False) -> As
186191
Returns:
187192
The archived Asset.
188193
"""
189-
asset_id = asset.id_ or "" if isinstance(asset, Asset) else asset
194+
asset_id = asset._id_or_error if isinstance(asset, Asset) else asset
190195

191-
await self._low_level_client.delete_asset(asset_id or "", archive_runs=archive_runs)
196+
await self._low_level_client.delete_asset(asset_id, archive_runs=archive_runs)
192197

193198
return await self.get(asset_id=asset_id)
194199

python/lib/sift_client/resources/calculated_channels.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,10 +152,10 @@ async def list_(
152152
if client_keys:
153153
filter_parts.append(cel.in_("client_key", client_keys))
154154
if asset:
155-
asset_id = asset.id_ if isinstance(asset, Asset) else asset
155+
asset_id = asset._id_or_error if isinstance(asset, Asset) else asset
156156
filter_parts.append(cel.equals("asset_id", asset_id))
157157
if run:
158-
run_id = run.id_ if isinstance(run, Run) else run
158+
run_id = run._id_or_error if isinstance(run, Run) else run
159159
filter_parts.append(cel.equals("run_id", run_id))
160160
if version:
161161
filter_parts.append(cel.equals("version", version))

0 commit comments

Comments
 (0)