Skip to content

Commit d9a793c

Browse files
authored
test(lint): enable ruff PT018 and split composite assertions (#793)
1 parent 635d5eb commit d9a793c

20 files changed

Lines changed: 103 additions & 54 deletions

‎packages/hflow-server/tests/test_server_config.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ def test_config_reports_local_mode_and_capabilities(
3434
payload = api.get("/api/v1/config").json()
3535
assert payload["mode"] == "local"
3636
assert payload["read_only"] is False # the default server accepts writes
37-
assert isinstance(payload["hflow_version"], str) and payload["hflow_version"]
37+
assert isinstance(payload["hflow_version"], str)
38+
assert payload["hflow_version"]
3839
assert payload["hflow_server_version"] == "0.1.0"
3940
assert payload["data_root"] == str(populated_workspace.data_root)
4041
assert payload["capabilities"] == {

‎packages/hflow-server/tests/ui_test_fixtures.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,8 @@ def joint_check_row(max_velocity: float) -> CheckRunRow:
136136
check_rows=[joint_check_row(2.0), contact_sheet_row],
137137
orchestrator_run_id=LATEST_ORCHESTRATOR_RUN_ID,
138138
)
139-
assert first_append.written and second_append.written
139+
assert first_append.written
140+
assert second_append.written
140141
assert first_append.episode_id == second_append.episode_id
141142
time.sleep(0.01)
142143

‎pyproject.toml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ select = [
133133
"UP",
134134
"ANN",
135135
"PTH",
136+
"PT018",
136137
"RET",
137138
"SIM",
138139
"TID",

‎tests/reuse_test_helpers.py‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ def corrupt_zstd_chunk_payload(episode_path: Path) -> None:
8686

8787
data = bytearray(episode_path.read_bytes())
8888
summary = make_reader(io.BytesIO(bytes(data))).get_summary()
89-
assert summary is not None and summary.chunk_indexes
89+
assert summary is not None
90+
assert summary.chunk_indexes
9091
chunk_start = summary.chunk_indexes[0].chunk_start_offset
9192
compression_length = struct.unpack_from("<I", data, chunk_start + 37)[0]
9293
compression_start = chunk_start + 41
@@ -108,7 +109,8 @@ def corrupt_first_chunk_crc(episode_path: Path) -> None:
108109

109110
data = bytearray(episode_path.read_bytes())
110111
summary = make_reader(io.BytesIO(bytes(data))).get_summary()
111-
assert summary is not None and summary.chunk_indexes
112+
assert summary is not None
113+
assert summary.chunk_indexes
112114
crc_offset = summary.chunk_indexes[0].chunk_start_offset + 33
113115
data[crc_offset] ^= 0x01
114116
episode_path.write_bytes(bytes(data))

‎tests/test_async_processing.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,8 @@ async def media_measurement(episode: hflow.Episode) -> hflow.CheckResult:
109109
release_media.set()
110110
with pytest.raises(asyncio.CancelledError):
111111
await processing_task
112-
assert media_finished.is_set() and check_finished.is_set()
112+
assert media_finished.is_set()
113+
assert check_finished.is_set()
113114

114115
asyncio.run(scenario())
115116

‎tests/test_build_ai_sampled_checks.py‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@ def test_sampled_hand_visibility_folds_no_hand_frames_into_intervals(
8080
assert run.result is not None
8181
assert len(served) == 4
8282
stamps = [observation.timestamp_ns for observation in run.result.observations]
83-
assert len(stamps) == 4 and stamps == sorted(stamps)
83+
assert len(stamps) == 4
84+
assert stamps == sorted(stamps)
8485
assert [observation.values["prediction"] for observation in run.result.observations] == [
8586
2,
8687
0,
@@ -235,7 +236,8 @@ def hosted_response(method: str, url: str, **_request: object) -> StubHostedResp
235236

236237
run = report.check("build_ai_hand_visibility")
237238
assert run.status is hflow.CheckStatus.ERROR
238-
assert run.error is not None and "HTTP 429" in run.error
239+
assert run.error is not None
240+
assert "HTTP 429" in run.error
239241
assert attempts == 3
240242
# No Retry-After: exponential from one second.
241243
assert sleeps == [1.0, 2.0]

‎tests/test_camera_frame_stats_benchmark.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77

88
def _load_benchmark() -> ModuleType:
99
spec = importlib.util.spec_from_file_location("camera_frame_stats_benchmark", BENCHMARK_PATH)
10-
assert spec is not None and spec.loader is not None
10+
assert spec is not None
11+
assert spec.loader is not None
1112
module = importlib.util.module_from_spec(spec)
1213
spec.loader.exec_module(module)
1314
return module

‎tests/test_catalog_curation.py‎

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ def test_append_is_idempotent_for_the_same_content_versions_and_outcome(tmp_path
6161
episode_metadata={"task": "fold_napkin"},
6262
check_rows=[example_check_row()],
6363
)
64-
assert first.written and not second.written
64+
assert first.written
65+
assert not second.written
6566
assert first.episode_id == second.episode_id == content_episode_id(canonical)
6667
parquet_files = list((tmp_path / "catalog" / "measurements").glob("*.parquet"))
6768
assert len(parquet_files) == 1
@@ -339,7 +340,8 @@ def test_the_orchestrator_run_id_is_recorded_without_entering_the_fingerprint(
339340
orchestrator_run_id="scheduled__2026-08-24T00:00:00+00:00",
340341
)
341342

342-
assert first.written and not replayed_under_another_run.written
343+
assert first.written
344+
assert not replayed_under_another_run.written
343345
assert first.run_fingerprint == replayed_under_another_run.run_fingerprint
344346
assert len(list((tmp_path / "catalog" / "episodes").glob("*.parquet"))) == 1
345347

@@ -381,7 +383,8 @@ def test_episode_time_bounds_are_recorded_as_the_episode_axis(tmp_path: Path) ->
381383
episode_metadata={},
382384
check_rows=[example_check_row()],
383385
)
384-
assert with_bounds.written and not replayed_without_bounds.written
386+
assert with_bounds.written
387+
assert not replayed_without_bounds.written
385388
assert with_bounds.run_fingerprint == replayed_without_bounds.run_fingerprint
386389

387390
with open_catalog_connection(tmp_path / "catalog") as connection:
@@ -736,7 +739,8 @@ def test_successful_retry_after_error_appends_repaired_outcome(tmp_path: Path) -
736739
check_rows=[successful_row],
737740
)
738741

739-
assert first.written and second.written
742+
assert first.written
743+
assert second.written
740744
assert first.run_fingerprint != second.run_fingerprint
741745
with open_catalog_connection(tmp_path / "catalog") as connection:
742746
assert connection.execute(
@@ -830,7 +834,8 @@ async def late_check(ep: hflow.Episode) -> hflow.CheckResult:
830834
for task_name, spec in episode_specs.items():
831835
source = synthesize_episode(sources_dir / f"{task_name}.mcap", spec)
832836
report = asyncio.run(app.test(source, verbose=False, record=True))
833-
assert report.catalog_entry is not None and report.catalog_entry.written
837+
assert report.catalog_entry is not None
838+
assert report.catalog_entry.written
834839

835840
rerun_report = asyncio.run(
836841
app.test(sources_dir / "fold_napkin.mcap", verbose=False, record=True)
@@ -2261,10 +2266,11 @@ def test_episodes_view_reserved_columns_match_queryable_episode_columns(
22612266
for key in view_columns_by_lookup_key.keys() - reserved_columns_by_lookup_key.keys()
22622267
)
22632268

2264-
assert not reserved_not_in_view and not view_not_reserved, (
2265-
"episodes view reserved-column drift: "
2266-
f"reserved_not_in_view={reserved_not_in_view}, "
2267-
f"view_not_reserved={view_not_reserved}"
2269+
assert not reserved_not_in_view, (
2270+
f"episodes view reserved-column drift: reserved_not_in_view={reserved_not_in_view}"
2271+
)
2272+
assert not view_not_reserved, (
2273+
f"episodes view reserved-column drift: view_not_reserved={view_not_reserved}"
22682274
)
22692275

22702276

@@ -2660,7 +2666,8 @@ def test_measurements_latest_ranks_by_the_owning_episodes_recorded_at(tmp_path:
26602666
episode_metadata={},
26612667
check_rows=[example_check_row(version="v2", value=2.0)],
26622668
)
2663-
assert older.written and newer.written
2669+
assert older.written
2670+
assert newer.written
26642671
assert older.run_fingerprint != newer.run_fingerprint
26652672

26662673
# Simulate a repair pass that won `episodes` for the NEWER run but

‎tests/test_checks.py‎

Lines changed: 35 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -350,12 +350,12 @@ def test_idle_fraction_is_time_weighted_and_bounded(jittery_episode: hflow.Episo
350350
idle = asyncio.run(idle_fraction(jittery_episode, velocity_epsilon=1e9, min_interval_s=0.5))
351351
moving_fraction = moving.measurements["/joint_states/idle_fraction"]
352352
idle_fraction_value = idle.measurements["/joint_states/idle_fraction"]
353-
assert isinstance(moving_fraction, float) and isinstance(idle_fraction_value, float)
353+
assert isinstance(moving_fraction, float)
354+
assert isinstance(idle_fraction_value, float)
354355
assert moving_fraction < 0.05
355356
assert idle_fraction_value == pytest.approx(1.0)
356-
assert idle.intervals and all(
357-
interval.label == "idle:/joint_states" for interval in idle.intervals
358-
)
357+
assert idle.intervals
358+
assert all(interval.label == "idle:/joint_states" for interval in idle.intervals)
359359
assert moving.verdict is None # evidence, not verdicts
360360

361361

@@ -366,7 +366,8 @@ def test_episode_duration_matches_the_synthesized_span(jittery_episode: hflow.Ep
366366
# The 4 s spec spans ~4 s of log time (one sample period short per stream).
367367
assert duration_s == pytest.approx(4.0, abs=0.1)
368368
message_count_total = result.measurements["message_count_total"]
369-
assert isinstance(message_count_total, int) and message_count_total > 0
369+
assert isinstance(message_count_total, int)
370+
assert message_count_total > 0
370371

371372

372373
@pytest.fixture
@@ -756,7 +757,8 @@ def test_camera_frame_stats_sees_the_injected_black_segment(tmp_path: Path) -> N
756757
# Which binary measured this: a pinned-build bump moves readings without
757758
# moving the check's version, so the instrument names itself in the row.
758759
instrument = result.measurements["camera_instrument"]
759-
assert isinstance(instrument, str) and "ffmpeg version" in instrument
760+
assert isinstance(instrument, str)
761+
assert "ffmpeg version" in instrument
760762

761763

762764
def test_camera_frame_stats_handles_duplicate_and_stationary_timestamps_without_zero_division(
@@ -864,7 +866,8 @@ def test_media_digest_matches_the_same_footage_under_different_telemetry(
864866

865867
assert first_media == second_media, "same footage must digest the same"
866868
assert first_content != second_content, "differing telemetry must change content_digest"
867-
assert isinstance(media_bytes, int) and media_bytes > 0
869+
assert isinstance(media_bytes, int)
870+
assert media_bytes > 0
868871

869872

870873
def test_media_digest_separates_different_footage(tmp_path: Path) -> None:
@@ -899,7 +902,8 @@ def test_keyframe_interval_reports_the_encoders_gop(tmp_path: Path) -> None:
899902
result = asyncio.run(keyframe_interval(episode))
900903

901904
keyframe_count = result.measurements[f"{camera_topic}/keyframe_count"]
902-
assert isinstance(keyframe_count, int) and keyframe_count >= 2
905+
assert isinstance(keyframe_count, int)
906+
assert keyframe_count >= 2
903907
assert result.measurements[f"{camera_topic}/first_frame_is_keyframe"] == 1
904908
max_gap_s = result.measurements[f"{camera_topic}/max_keyframe_gap_s"]
905909
assert isinstance(max_gap_s, float)
@@ -1151,14 +1155,16 @@ def test_camera_signal_quality_measures_range_exposure_and_stillness(tmp_path: P
11511155
luma_min = result.measurements[f"{camera_topic}/luma_min"]
11521156
luma_max = result.measurements[f"{camera_topic}/luma_max"]
11531157
assert full_range in (0, 1)
1154-
assert isinstance(luma_min, float) and isinstance(luma_max, float)
1158+
assert isinstance(luma_min, float)
1159+
assert isinstance(luma_max, float)
11551160
assert 0.0 <= luma_min <= luma_max <= 255.0
11561161
# The verdict must be consistent with its own evidence.
11571162
assert bool(full_range) == (luma_min < 16.0 or luma_max > 235.0)
11581163

11591164
# The test pattern moves, so stillness is well above zero.
11601165
frame_difference_mean = result.measurements[f"{camera_topic}/frame_difference_mean"]
1161-
assert isinstance(frame_difference_mean, float) and frame_difference_mean > 0.0
1166+
assert isinstance(frame_difference_mean, float)
1167+
assert frame_difference_mean > 0.0
11621168

11631169
# A clean synthetic encode carries no impulse noise.
11641170
assert result.measurements[f"{camera_topic}/temporal_outlier_max"] == pytest.approx(
@@ -1190,15 +1196,18 @@ def test_camera_signal_quality_sees_a_blacked_out_segment(tmp_path: Path) -> Non
11901196
# builds' black frames sit under, so the share is stable across them.
11911197
black_share_max = result.measurements[f"{camera_topic}/black_pixel_share_max"]
11921198
black_share_mean = result.measurements[f"{camera_topic}/black_pixel_share_mean"]
1193-
assert isinstance(black_share_max, float) and black_share_max > 90.0
1199+
assert isinstance(black_share_max, float)
1200+
assert black_share_max > 90.0
11941201
# 2 s of 4 s blacked out; decode boundaries make the exact count fuzzy.
1195-
assert isinstance(black_share_mean, float) and 25.0 < black_share_mean < 75.0
1202+
assert isinstance(black_share_mean, float)
1203+
assert 25.0 < black_share_mean < 75.0
11961204

11971205
# Half the clip near-black must drag the low percentile far below the high
11981206
# one, whatever scale the decoder put them on.
11991207
luma_p10_mean = result.measurements[f"{camera_topic}/luma_p10_mean"]
12001208
luma_p90_mean = result.measurements[f"{camera_topic}/luma_p90_mean"]
1201-
assert isinstance(luma_p10_mean, float) and isinstance(luma_p90_mean, float)
1209+
assert isinstance(luma_p10_mean, float)
1210+
assert isinstance(luma_p90_mean, float)
12021211
assert luma_p10_mean < luma_p90_mean / 2.0
12031212

12041213

@@ -1251,7 +1260,9 @@ def test_trajectory_metrics_finds_the_injected_hold(held_joints_episode: Path) -
12511260
assert result.measurements["/joint_states/scale_source"] == "raw"
12521261
peak = result.measurements["/joint_states/peak_velocity"]
12531262
mean = result.measurements["/joint_states/mean_velocity"]
1254-
assert isinstance(peak, float) and isinstance(mean, float) and peak >= mean > 0.0
1263+
assert isinstance(peak, float)
1264+
assert isinstance(mean, float)
1265+
assert peak >= mean > 0.0
12551266
assert result.verdict is None
12561267

12571268

@@ -1276,7 +1287,8 @@ def test_trajectory_metrics_dimension_scales_are_recorded_and_validated(
12761287
assert scaled.measurements["/joint_states/scale_source"] == "user"
12771288
raw_peak = raw.measurements["/joint_states/peak_velocity"]
12781289
scaled_peak = scaled.measurements["/joint_states/peak_velocity"]
1279-
assert isinstance(raw_peak, float) and isinstance(scaled_peak, float)
1290+
assert isinstance(raw_peak, float)
1291+
assert isinstance(scaled_peak, float)
12801292
# Halving every dimension halves the magnitude over all of them.
12811293
assert scaled_peak == pytest.approx(raw_peak / 2.0)
12821294

@@ -1319,7 +1331,8 @@ def test_trajectory_segments_flags_the_injected_jump_as_a_change(tmp_path: Path)
13191331
max_change = asyncio.run(trajectory_metrics(episode)).measurements[
13201332
"/joint_states/max_trajectory_change"
13211333
]
1322-
assert isinstance(threshold, float) and isinstance(max_change, float)
1334+
assert isinstance(threshold, float)
1335+
assert isinstance(max_change, float)
13231336
assert max_change > threshold
13241337

13251338

@@ -1484,9 +1497,11 @@ def test_trajectory_metrics_emits_final_pose_speed_for_low_frequency_stream(
14841497
result = asyncio.run(trajectory_metrics(episode))
14851498

14861499
speed = result.measurements.get("/joint_states/final_pose_speed")
1487-
assert isinstance(speed, float) and speed > 0
1500+
assert isinstance(speed, float)
1501+
assert speed > 0
14881502
ratio = result.measurements.get("/joint_states/final_pose_unsettled_ratio")
1489-
assert isinstance(ratio, float) and ratio > 0
1503+
assert isinstance(ratio, float)
1504+
assert ratio > 0
14901505

14911506

14921507
def test_trajectory_metrics_time_weights_final_pose_speed_identically_to_mean_velocity(
@@ -1571,7 +1586,8 @@ def test_trajectory_metrics_omits_final_pose_speed_when_final_window_is_unmeasur
15711586
assert "/joint_states/final_pose_speed" not in result.measurements
15721587
assert "/joint_states/final_pose_unsettled_ratio" not in result.measurements
15731588
mean = result.measurements.get("/joint_states/mean_velocity")
1574-
assert isinstance(mean, float) and mean > 0
1589+
assert isinstance(mean, float)
1590+
assert mean > 0
15751591

15761592

15771593
@pytest.fixture(scope="module")

‎tests/test_end_to_end.py‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,8 @@ def test_canonical_episode_accessors(
435435
assert joints.shape[1] == 7
436436

437437
mp4 = episode.video("overhead_cam")
438-
assert mp4.is_file() and mp4.stat().st_size > 0
438+
assert mp4.is_file()
439+
assert mp4.stat().st_size > 0
439440

440441
cached_channels = dict(episode._channel_data_by_id)
441442
frames = episode.frames("overhead_cam", fps=2.0)
@@ -885,7 +886,8 @@ async def still_runs(ep: hflow.Episode) -> hflow.CheckResult:
885886
assert not report.quarantined
886887
by_name = {run.check.name: run for run in report.checks}
887888
assert by_name["exploding"].status == "error"
888-
assert by_name["exploding"].error is not None and "boom" in by_name["exploding"].error
889+
assert by_name["exploding"].error is not None
890+
assert "boom" in by_name["exploding"].error
889891
assert by_name["still_runs"].status == "measured"
890892
(record,) = caplog.records
891893
assert record.name == "hflow.app"

0 commit comments

Comments
 (0)