Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions examples/build_ai_evaluation/tests/test_evaluation.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,10 @@ def test_task_schemas_and_parsers_enforce_the_answer_contract() -> None:
f"{task.value}: the schema permits {value!r} but the parser does not accept it"
)
for value in rejected_values:
with pytest.raises(ValueError):
expected_error = (
"hand count" if task is EvaluationTask.HAND_COUNT else "active manipulation"
)
with pytest.raises(ValueError, match=expected_error):
parser(json.dumps({property_name: value}))


Expand Down Expand Up @@ -581,7 +584,7 @@ def test_run_metadata_names_the_file_and_the_bad_field(
metadata_path.parent.mkdir(parents=True, exist_ok=True)
metadata_path.write_text(run_json_text)

with pytest.raises(ValueError) as error:
with pytest.raises(ValueError, match=r"run\.json") as error:
_prepare_output_directory(configuration)

message = str(error.value)
Expand Down
4 changes: 2 additions & 2 deletions examples/egosuite_evaluation/tests/test_evaluation.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ def test_saved_label_report_rejects_unsupported_envelope_before_frames(
report_path = tmp_path / "labels.json"
report_path.write_text(json.dumps({**envelope, "frames": [None]}))

with pytest.raises(ValueError) as error:
with pytest.raises(ValueError, match=rf"field '{field_name}' has value") as error:
load_projected_hand_label_report(report_path)

message = str(error.value)
Expand Down Expand Up @@ -1016,7 +1016,7 @@ def test_run_metadata_names_the_file_and_the_bad_field(
metadata_path.parent.mkdir(parents=True, exist_ok=True)
metadata_path.write_text(run_json_text)

with pytest.raises(ValueError) as error:
with pytest.raises(ValueError, match=r"run\.json") as error:
_prepare_output_directory(configuration)

message = str(error.value)
Expand Down
8 changes: 8 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,14 @@ select = [
"ANN",
"PTH",
"PT018",
"PT010",
"PT011",
"PT012",
"PT014",
"PT016",
"PT028",
"PT030",
"PT031",
"RET",
"SIM",
"TID",
Expand Down
2 changes: 1 addition & 1 deletion tests/test_build_ai_vlm_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,7 @@ def test_model_answers_reject_ambiguous_or_out_of_contract_json(
task: str, response_text: str
) -> None:
checks = hflow.build_ai_vlm_checks
with pytest.raises(ValueError) as captured_error:
with pytest.raises(ValueError, match=task.replace("-", " ")) as captured_error:
checks.parse_task_response(checks.EvaluationTask(task), response_text)
assert captured_error.value.__cause__ is None
assert captured_error.value.__suppress_context__
Expand Down
22 changes: 10 additions & 12 deletions tests/test_episode.py
Original file line number Diff line number Diff line change
Expand Up @@ -500,14 +500,13 @@ def fail_rename(self: Path, target: Path) -> Path:

monkeypatch.setattr(Path, "rename", fail_rename)

with (
Episode(canonical_mcap, workdir=workdir) as ep,
pytest.raises(PermissionError, match="simulated permission denied"),
):
with Episode(canonical_mcap, workdir=workdir) as ep:
if method == "frames":
ep.frames(fps=2.0)
with pytest.raises(PermissionError, match="simulated permission denied"):
ep.frames(fps=2.0)
else:
ep.frames_at_indices(frame_indices=[0, 2])
with pytest.raises(PermissionError, match="simulated permission denied"):
ep.frames_at_indices(frame_indices=[0, 2])

assert not [d for d in workdir.iterdir() if d.is_dir() and d.name.endswith(".tmp")]

Expand Down Expand Up @@ -543,14 +542,13 @@ def failing_run(*args: Any, **kwargs: Any) -> Any:
else "ffmpeg extracted 0 of 2 selected frames"
)

with (
Episode(canonical_mcap, workdir=workdir) as ep,
pytest.raises(RuntimeError, match=expected_error),
):
with Episode(canonical_mcap, workdir=workdir) as ep:
if method == "frames":
ep.frames(fps=2.0)
with pytest.raises(RuntimeError, match=expected_error):
ep.frames(fps=2.0)
else:
ep.frames_at_indices(frame_indices=[0, 2])
with pytest.raises(RuntimeError, match=expected_error):
ep.frames_at_indices(frame_indices=[0, 2])

assert not [d for d in workdir.iterdir() if d.is_dir()]

Expand Down
2 changes: 1 addition & 1 deletion tests/test_episode_to_arrow.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def test_to_arrow_rejects_payload_field_that_shadows_log_time() -> None:
log_times=[1_000_000_000, 2_000_000_000],
)

with pytest.raises(ValueError) as excinfo:
with pytest.raises(ValueError, match="reserved Arrow column") as excinfo:
channel.to_arrow()
message = str(excinfo.value)
assert "log_time_ns" in message
Expand Down
2 changes: 1 addition & 1 deletion tests/test_lerobot_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ def write_changed_schema(table: pa.Table, where: Path) -> None:
destination = tmp_path / "out"
destination.mkdir()
(destination / "sentinel.txt").write_text("previous export")
with pytest.raises(ValueError) as error:
with pytest.raises(ValueError, match="schema differs from source") as error:
export.export(destination, manifest=manifest, camera_keys=CAMS)
message = str(error.value)
assert "data/chunk-000/file-001.parquet" in message
Expand Down
14 changes: 7 additions & 7 deletions tests/test_manifest_deduplication.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,18 +177,18 @@ def test_reserved_metadata_names_cannot_overwrite_source_provenance(tmp_path: Pa


@pytest.mark.parametrize(
"identities, conflicts",
"identities, conflicts, expected_error",
[
((), ()),
(("digest", "DIGEST"), ()),
(("digest",), ("label", "LABEL")),
(("retained_sample_id",), ()),
((), (), "identity_columns must be nonempty"),
(("digest", "DIGEST"), (), "identity_columns must contain distinct"),
(("digest",), ("label", "LABEL"), "conflict_columns must contain distinct"),
(("retained_sample_id",), (), "column names are reserved"),
],
)
def test_invalid_settings_reject_ambiguous_or_reserved_columns(
identities: tuple[str, ...], conflicts: tuple[str, ...]
identities: tuple[str, ...], conflicts: tuple[str, ...], expected_error: str
) -> None:
with pytest.raises(ValueError):
with pytest.raises(ValueError, match=expected_error):
ManifestDeduplicationSettings("sample_id", identities, conflicts)


Expand Down
16 changes: 8 additions & 8 deletions tests/test_manifest_splits.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,19 +165,19 @@ def test_invalid_identities_never_publish_a_split(


@pytest.mark.parametrize(
"name, fraction",
"name, fraction, expected_error",
[
("../escape", 0.5),
("assignments", 0.5),
("train", float("nan")),
("train", True),
("train", 0),
("../escape", 0.5, "partition name must match"),
("assignments", 0.5, "partition name 'assignments' is reserved"),
("train", float("nan"), "partition fraction must be finite"),
("train", True, "partition fraction must be finite"),
("train", 0, "partition fraction must be finite"),
],
)
def test_partition_values_reject_unsafe_names_and_invalid_fractions(
name: str, fraction: float
name: str, fraction: float, expected_error: str
) -> None:
with pytest.raises(ValueError):
with pytest.raises(ValueError, match=expected_error):
ManifestPartition(name, fraction)


Expand Down
6 changes: 5 additions & 1 deletion tests/test_prefetch.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,12 +170,16 @@ def prepare(item: int, directory: Path) -> int:

async def scenario() -> list[int]:
received: list[int] = []
with pytest.raises(ValueError, match="window 2 is unreadable"):

async def consume() -> None:
async with prefetch(
range(5), prepare, working_directory=tmp_path, lookahead=2
) as prepared_items:
async for prepared in prepared_items:
received.append(prepared.item)

with pytest.raises(ValueError, match="window 2 is unreadable"):
await consume()
return received

assert asyncio.run(scenario()) == [0, 1]
Expand Down
2 changes: 1 addition & 1 deletion tests/test_processing_regressions.py
Original file line number Diff line number Diff line change
Expand Up @@ -941,7 +941,7 @@ def two_missing(
) -> hflow.CheckResult:
return hflow.CheckResult(measurements={"n": len(topics) + threshold})

with pytest.raises(ValueError) as raised:
with pytest.raises(ValueError, match="required parameter") as raised:
app.check(version="1")(cast(hflow.steps.CheckFunction, two_missing))
message = str(raised.value)
assert "threshold=..." in message
Expand Down
10 changes: 4 additions & 6 deletions tests/test_runtime_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,7 @@ def test_ingest_refuses_a_batch_count_the_run_could_not_honour(stub_server: str)
def test_ingest_rejects_invalid_uri_before_making_http_requests(stub_server: str, uri: str) -> None:
client = AirflowClient(stub_server, "airflow", "right-password")

with pytest.raises(ValueError):
with pytest.raises(ValueError, match=r"non-empty string|separator|relative to the data root"):
client.ingest("pipeline_ingest", [uri])

assert _StubAirflowHandler.requests_seen == []
Expand Down Expand Up @@ -1020,12 +1020,10 @@ def test_wait_until_healthy_times_out_with_last_status(stub_server: str) -> None
_StubAirflowHandler.healthy = False
client = AirflowClient(stub_server, "airflow", "right-password")
instantly_advancing_clock = InstantlyAdvancingClock()
with (
pytest.MonkeyPatch.context() as monkeypatch,
pytest.raises(TimeoutError, match="scheduler=unhealthy"),
):
with pytest.MonkeyPatch.context() as monkeypatch:
monkeypatch.setattr("hflow.runtime._client.time", instantly_advancing_clock)
client.wait_until_healthy(timeout_s=0.3, poll_interval_s=10.0)
with pytest.raises(TimeoutError, match="scheduler=unhealthy"):
client.wait_until_healthy(timeout_s=0.3, poll_interval_s=10.0)
assert instantly_advancing_clock.current_time_s == pytest.approx(0.3)


Expand Down
2 changes: 1 addition & 1 deletion tests/test_source_sampling.py
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ def test_oversized_windows_are_rejected_before_output_creation(
],
)
def test_sampling_settings_refuse_invalid_limits(field_name: str, value: object) -> None:
with pytest.raises(ValueError):
with pytest.raises(ValueError, match=field_name):
replace(SourceFrameSampling(), **{field_name: value})


Expand Down
18 changes: 14 additions & 4 deletions tests/test_source_windows.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,21 @@ def test_plans_refuse_partial_coverage_when_limits_cannot_be_satisfied() -> None

@pytest.mark.parametrize("duration_millis", [True, 1.5, "100", 0, -1])
def test_invalid_durations_are_not_silently_coerced(duration_millis: object) -> None:
with pytest.raises(ValueError):
with pytest.raises(ValueError, match="duration_millis must be"):
plan_source_windows(duration_millis, maximum_window_millis=100) # ty: ignore[invalid-argument-type]


@pytest.mark.parametrize("bounds", [(-1, 1), (0, 0), (2, 1), (False, 1)])
def test_source_windows_require_a_nonempty_forward_interval(bounds: tuple[int, int]) -> None:
with pytest.raises(ValueError):
@pytest.mark.parametrize(
("bounds", "expected_error"),
[
((-1, 1), "start_millis must be >= 0"),
((0, 0), "end_millis must be > 0"),
((2, 1), "end_millis must be greater than start_millis"),
((False, 1), "start_millis must be an int"),
],
)
def test_source_windows_require_a_nonempty_forward_interval(
bounds: tuple[int, int], expected_error: str
) -> None:
with pytest.raises(ValueError, match=expected_error):
SourceWindow(*bounds)
32 changes: 17 additions & 15 deletions tests/test_video_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,25 +217,27 @@ def test_invalid_sources_and_incomplete_excerpts_publish_nothing(


@pytest.mark.parametrize(
"config",
"config, expected_error",
[
{"duration_s": 0},
{"source_start_s": -1},
{"image_hz": 0},
{"image_height": True},
{"start_time_ns": -1},
{"start_time_ns": True},
({"duration_s": 0}, "duration_s must be positive"),
({"source_start_s": -1}, "source_start_s nonnegative"),
({"image_hz": 0}, "image_hz must be positive"),
({"image_height": True}, "image_height must be an int"),
({"start_time_ns": -1}, "start_time_ns must be in"),
({"start_time_ns": True}, "start_time_ns must be an int"),
# Inside the field's range but the final frame's timestamp overflows.
{"start_time_ns": (1 << 64) - 1},
{"camera_name": ""},
{"metadata": (("task", "one"), ("task", "two"))},
{"maximum_encoded_bytes": 0},
{"maximum_encoded_bytes": True},
{"maximum_encoded_bytes": 1.5},
({"start_time_ns": (1 << 64) - 1}, "excerpt exceeds the MCAP timestamp range"),
({"camera_name": ""}, "camera_name must be nonempty"),
({"metadata": (("task", "one"), ("task", "two"))}, "metadata contains duplicate key"),
({"maximum_encoded_bytes": 0}, "maximum_encoded_bytes must be > 0"),
({"maximum_encoded_bytes": True}, "maximum_encoded_bytes must be an int"),
({"maximum_encoded_bytes": 1.5}, "maximum_encoded_bytes must be an int"),
],
)
def test_invalid_import_configuration_is_rejected(config: dict[str, object]) -> None:
with pytest.raises(ValueError):
def test_invalid_import_configuration_is_rejected(
config: dict[str, object], expected_error: str
) -> None:
with pytest.raises(ValueError, match=expected_error):
replace(VideoImportConfig(duration_s=1), **config)


Expand Down
4 changes: 3 additions & 1 deletion tests/test_video_streaming.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,9 @@ def test_streaming_fps_preserves_exact_median_and_errors(timestamps: list[int])
try:
expected = video.estimate_fps_from_log_times(timestamps, topic="/camera")
except ValueError as error:
with pytest.raises(ValueError) as streaming_error:
with pytest.raises(
ValueError, match=r"camera topic '/camera'.*frame rate"
) as streaming_error:
video.estimate_fps_from_streaming_log_times(iter(timestamps), topic="/camera")
assert str(streaming_error.value) == str(error)
else:
Expand Down
Loading