feat(ruff): add pytest linting rule (#2053)

* feat(ruff): add pytest linting rule
* --unsafe-fixes
* fix(pre_commit): 🎨 auto format pre-commit hooks


---------

Co-authored-by: jiri BOROVEC <jirka@Jiris-MacBook-Pro-J4N257Y6Q2.local>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com>
This commit is contained in:
Jirka Borovec 2026-01-13 19:34:22 +01:00 committed by GitHub
parent f1e0c9cdd7
commit 09de0f4f06
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
35 changed files with 195 additions and 166 deletions

View File

@ -151,6 +151,7 @@ lint.select = [
"E", # pycodestyle errors - https://docs.astral.sh/ruff/rules/#error-e
"F", # Pyflakes - https://docs.astral.sh/ruff/rules/#pyflakes-f
"I", # isort - https://docs.astral.sh/ruff/rules/#isort-i
"PT", # pytest - https://docs.astral.sh/ruff/rules/#flake8-pytest-style-pt
"Q", # flake8-quotes - https://docs.astral.sh/ruff/rules/#flake8-quotes-q
"RUF", # Ruff-specific rules - https://docs.astral.sh/ruff/rules/#ruff-specific-rules-ruf
"S", # bandit - https://docs.astral.sh/ruff/rules/#flake8-bandit-s
@ -163,7 +164,8 @@ lint.per-file-ignores."supervision/**" = [
"S101", # TODO: Replace asserts with proper error handling
]
lint.per-file-ignores."test/**" = [
"S101", # Use of `assert` detected
"PT011", # TODO: `pytest.raises(Exception)` is too broad, set the `match` parameter or use a more specific exception
"S101", # Use of `assert` detected
]
lint.unfixable = [ ]
# Allow unused variables when underscore-prefixed.

View File

@ -575,7 +575,7 @@ def from_florence_2(
labels = np.array([result_string])
return xyxy, labels, None, None
assert False, f"Unimplemented task: {task}"
raise RuntimeError(f"Unimplemented task: {task}")
def from_google_gemini_2_0(

View File

@ -11,7 +11,7 @@ from test.test_utils import mock_detections
@pytest.mark.parametrize(
"detections, detection_idx, color_lookup, expected_result, exception",
("detections", "detection_idx", "color_lookup", "expected_result", "exception"),
[
(
mock_detections(
@ -111,7 +111,7 @@ def test_resolve_color_idx(
@pytest.mark.parametrize(
"text, max_line_length, expected_result, exception",
("text", "max_line_length", "expected_result", "exception"),
[
(None, None, [""], DoesNotRaise()), # text is None
("", None, [""], DoesNotRaise()), # empty string

View File

@ -9,7 +9,7 @@ from supervision.classification.core import Classifications
@pytest.mark.parametrize(
"class_id, confidence, k, expected_result, exception",
("class_id", "confidence", "k", "expected_result", "exception"),
[
(
np.array([0, 1, 2, 3, 4]),

View File

@ -39,7 +39,7 @@ def mock_coco_annotation(
@pytest.mark.parametrize(
"coco_categories, expected_result, exception",
("coco_categories", "expected_result", "exception"),
[
([], [], DoesNotRaise()), # empty coco categories
(
@ -87,7 +87,7 @@ def test_coco_categories_to_classes(
@pytest.mark.parametrize(
"classes, exception",
("classes", "exception"),
[
([], DoesNotRaise()), # empty classes
(["baseball cap"], DoesNotRaise()), # single class
@ -104,7 +104,7 @@ def test_classes_to_coco_categories_and_back_to_classes(
@pytest.mark.parametrize(
"coco_annotations, expected_result, exception",
("coco_annotations", "expected_result", "exception"),
[
([], {}, DoesNotRaise()), # empty coco annotations
(
@ -163,8 +163,14 @@ def test_group_coco_annotations_by_image_id(
@pytest.mark.parametrize(
"image_annotations, resolution_wh, with_masks, use_iscrowd, "
"expected_result, exception",
(
"image_annotations",
"resolution_wh",
"with_masks",
"use_iscrowd",
"expected_result",
"exception",
),
[
(
[],
@ -601,7 +607,7 @@ def test_coco_annotations_to_detections(
@pytest.mark.parametrize(
"coco_categories, target_classes, expected_result, exception",
("coco_categories", "target_classes", "expected_result", "exception"),
[
([], [], {}, DoesNotRaise()), # empty coco categories
(
@ -660,7 +666,7 @@ def test_build_coco_class_index_mapping(
@pytest.mark.parametrize(
"detections, image_id, annotation_id, expected_result, exception",
("detections", "image_id", "annotation_id", "expected_result", "exception"),
[
(
Detections(

View File

@ -31,7 +31,7 @@ def are_xml_elements_equal(elem1, elem2):
@pytest.mark.parametrize(
"xyxy, name, polygon, expected_result, exception",
("xyxy", "name", "polygon", "expected_result", "exception"),
[
(
np.array([0, 0, 10, 10]),
@ -71,7 +71,7 @@ def test_object_to_pascal_voc(
@pytest.mark.parametrize(
"polygon_element, expected_result, exception",
("polygon_element", "expected_result", "exception"),
[
(
ElementTree.fromstring(
@ -116,7 +116,14 @@ NO_DETECTIONS = """<annotation></annotation>"""
@pytest.mark.parametrize(
"xml_string, classes, resolution_wh, force_masks, expected_result, exception",
(
"xml_string",
"classes",
"resolution_wh",
"force_masks",
"expected_result",
"exception",
),
[
(
ONE_CLASS_ONE_BBOX,

View File

@ -31,7 +31,7 @@ def _arrays_almost_equal(
@pytest.mark.parametrize(
"lines, expected_result, exception",
("lines", "expected_result", "exception"),
[
([], False, DoesNotRaise()), # empty yolo annotation file
(
@ -44,7 +44,6 @@ def _arrays_almost_equal(
False,
DoesNotRaise(),
), # yolo annotation file with two lines with box
(["0 0.5 0.5 0.2 0.2"], False, DoesNotRaise()),
(
["0 0.4 0.4 0.6 0.4 0.6 0.6 0.4 0.6"],
True,
@ -66,7 +65,7 @@ def test_with_mask(
@pytest.mark.parametrize(
"lines, resolution_wh, with_masks, expected_result, exception",
("lines", "resolution_wh", "with_masks", "expected_result", "exception"),
[
(
[],
@ -190,7 +189,7 @@ def test_yolo_annotations_to_detections(
@pytest.mark.parametrize(
"image_name, expected_result, exception",
("image_name", "expected_result", "exception"),
[
("image.png", "image.txt", DoesNotRaise()), # simple png image
("image.jpeg", "image.txt", DoesNotRaise()), # simple jpeg image
@ -211,7 +210,7 @@ def test_image_name_to_annotation_name(
@pytest.mark.parametrize(
"xyxy, class_id, image_shape, polygon, expected_result, exception",
("xyxy", "class_id", "image_shape", "polygon", "expected_result", "exception"),
[
(
np.array([100, 100, 200, 200], dtype=np.float32),

View File

@ -9,7 +9,7 @@ from test.test_utils import mock_detections
@pytest.mark.parametrize(
"dataset_list, expected_result, exception",
("dataset_list", "expected_result", "exception"),
[
(
[],

View File

@ -22,7 +22,7 @@ T = TypeVar("T")
@pytest.mark.parametrize(
"data, train_ratio, random_state, shuffle, expected_result, exception",
("data", "train_ratio", "random_state", "shuffle", "expected_result", "exception"),
[
([], 0.5, None, False, ([], []), DoesNotRaise()), # empty data
(
@ -94,7 +94,7 @@ def test_train_test_split(
@pytest.mark.parametrize(
"class_lists, expected_result, exception",
("class_lists", "expected_result", "exception"),
[
([], [], DoesNotRaise()), # empty class lists
(
@ -128,7 +128,7 @@ def test_merge_class_maps(
@pytest.mark.parametrize(
"source_classes, target_classes, expected_result, exception",
("source_classes", "target_classes", "expected_result", "exception"),
[
([], [], {}, DoesNotRaise()), # empty class lists
([], ["dog", "person"], {}, DoesNotRaise()), # empty source class list
@ -178,7 +178,7 @@ def test_build_class_index_mapping(
@pytest.mark.parametrize(
"source_to_target_mapping, detections, expected_result, exception",
("source_to_target_mapping", "detections", "expected_result", "exception"),
[
(
{},
@ -238,7 +238,7 @@ def test_map_detections_class_id(
@pytest.mark.parametrize(
"mask, expected_rle, exception",
("mask", "expected_rle", "exception"),
[
(
np.zeros((3, 3)).astype(bool),
@ -297,7 +297,7 @@ def test_mask_to_rle(
@pytest.mark.parametrize(
"rle, resolution_wh, expected_mask, exception",
("rle", "resolution_wh", "expected_mask", "exception"),
[
(
np.array([9]),

View File

@ -130,7 +130,7 @@ TEST_DET_DIFFERENT_METADATA = Detections(
@pytest.mark.parametrize(
"detections, index, expected_result, exception",
("detections", "index", "expected_result", "exception"),
[
(
DETECTIONS,
@ -244,7 +244,7 @@ def test_getitem(
@pytest.mark.parametrize(
"detections_list, expected_result, exception",
("detections_list", "expected_result", "exception"),
[
([], Detections.empty(), DoesNotRaise()), # empty detections list
(
@ -516,7 +516,7 @@ def test_merge(
@pytest.mark.parametrize(
"detections, anchor, expected_result, exception",
("detections", "anchor", "expected_result", "exception"),
[
(
Detections.empty(),
@ -598,7 +598,7 @@ def test_get_anchor_coordinates(
@pytest.mark.parametrize(
"detections_a, detections_b, expected_result",
("detections_a", "detections_b", "expected_result"),
[
(
Detections.empty(),
@ -649,7 +649,7 @@ def test_equal(
@pytest.mark.parametrize(
"detection_1, detection_2, expected_result, exception",
("detection_1", "detection_2", "expected_result", "exception"),
[
(
mock_detections(

View File

@ -9,9 +9,14 @@ from test.test_utils import mock_detections
@pytest.mark.parametrize(
"detections, custom_data, "
"second_detections, second_custom_data, "
"file_name, expected_result",
(
"detections",
"custom_data",
"second_detections",
"second_custom_data",
"file_name",
"expected_result",
),
[
(
mock_detections(
@ -206,9 +211,14 @@ def test_csv_sink(
@pytest.mark.parametrize(
"detections, custom_data, "
"second_detections, second_custom_data, "
"file_name, expected_result",
(
"detections",
"custom_data",
"second_detections",
"second_custom_data",
"file_name",
"expected_result",
),
[
(
mock_detections(

View File

@ -9,9 +9,14 @@ from test.test_utils import mock_detections
@pytest.mark.parametrize(
"detections, custom_data, "
"second_detections, second_custom_data, "
"file_name, expected_result",
(
"detections",
"custom_data",
"second_detections",
"second_custom_data",
"file_name",
"expected_result",
),
[
(
mock_detections(

View File

@ -10,7 +10,7 @@ from test.test_utils import mock_detections
@pytest.mark.parametrize(
"vector, expected_result, exception",
("vector", "expected_result", "exception"),
[
(
Vector(start=Point(x=0.0, y=0.0), end=Point(x=0.0, y=0.0)),
@ -75,7 +75,7 @@ def test_calculate_region_of_interest_limits(
@pytest.mark.parametrize(
"vector, xyxy_sequence, expected_crossed_in, expected_crossed_out",
("vector", "xyxy_sequence", "expected_crossed_in", "expected_crossed_out"),
[
( # Vertical line, simple crossing
Vector(Point(0, 0), Point(0, 10)),
@ -260,8 +260,13 @@ def test_line_zone_one_detection_default_anchors(
@pytest.mark.parametrize(
"vector, xyxy_sequence, triggering_anchors, expected_crossed_in, "
"expected_crossed_out",
(
"vector",
"xyxy_sequence",
"triggering_anchors",
"expected_crossed_in",
"expected_crossed_out",
),
[
( # Scrape line, left side, corner anchors
Vector(Point(0, 0), Point(10, 0)),
@ -425,8 +430,14 @@ def test_line_zone_one_detection(
@pytest.mark.parametrize(
"vector, xyxy_sequence, anchors, expected_crossed_in, "
"expected_crossed_out, exception",
(
"vector",
"xyxy_sequence",
"anchors",
"expected_crossed_in",
"expected_crossed_out",
"exception",
),
[
( # One stays, one crosses
Vector(Point(0, 0), Point(10, 0)),
@ -494,8 +505,14 @@ def test_line_zone_multiple_detections(
@pytest.mark.parametrize(
"vector, xyxy_sequence, triggering_anchors, minimum_crossing_threshold, "
"expected_crossed_in, expected_crossed_out",
(
"vector",
"xyxy_sequence",
"triggering_anchors",
"minimum_crossing_threshold",
"expected_crossed_in",
"expected_crossed_out",
),
[
( # Detection lingers around line, all crosses counted
Vector(Point(0, 0), Point(10, 0)),
@ -610,9 +627,17 @@ def test_line_zone_one_detection_long_horizon(
@pytest.mark.parametrize(
"vector, xyxy_sequence, anchors, minimum_crossing_threshold, "
"expected_crossed_in, expected_crossed_out, expected_count_in, "
"expected_count_out, exception",
(
"vector",
"xyxy_sequence",
"anchors",
"minimum_crossing_threshold",
"expected_crossed_in",
"expected_crossed_out",
"expected_count_in",
"expected_count_out",
"exception",
),
[
( # One stays, one crosses, one disappears before crossing
Vector(Point(0, 0), Point(10, 0)),

View File

@ -22,7 +22,7 @@ ANNOTATED_SCENE_0_5_OPACITY = sv.draw_filled_polygon(
@pytest.mark.parametrize(
"scene, polygon_zone_annotator, expected_results",
("scene", "polygon_zone_annotator", "expected_results"),
[
(
SCENE,

View File

@ -29,7 +29,7 @@ POLYGON = np.array([[100, 100], [200, 100], [200, 200], [100, 200]])
@pytest.mark.parametrize(
"detections, polygon_zone, expected_results, exception",
("detections", "polygon_zone", "expected_results", "exception"),
[
(
DETECTIONS,
@ -90,7 +90,7 @@ def test_polygon_zone_trigger(
@pytest.mark.parametrize(
"polygon, triggering_anchors, exception",
("polygon", "triggering_anchors", "exception"),
[
(POLYGON, [sv.Position.CENTER], DoesNotRaise()),
(

View File

@ -20,7 +20,7 @@ from supervision.detection.vlm import (
@pytest.mark.parametrize(
"exception, result, resolution_wh, classes, expected_results",
("exception", "result", "resolution_wh", "classes", "expected_results"),
[
(
does_not_raise(),
@ -202,7 +202,7 @@ def test_from_paligemma(
@pytest.mark.parametrize(
"exception, result, input_wh, resolution_wh, classes, expected_results",
("exception", "result", "input_wh", "resolution_wh", "classes", "expected_results"),
[
(
does_not_raise(),
@ -405,7 +405,7 @@ def test_from_qwen_2_5_vl(
@pytest.mark.parametrize(
"exception, result, resolution_wh, classes, expected_results",
("exception", "result", "resolution_wh", "classes", "expected_results"),
[
(
does_not_raise(),
@ -544,7 +544,7 @@ def test_from_google_gemini(
@pytest.mark.parametrize(
"exception, result, resolution_wh, expected_results",
("exception", "result", "resolution_wh", "expected_results"),
[
(
does_not_raise(),
@ -644,7 +644,7 @@ def test_from_moondream(
@pytest.mark.parametrize(
"florence_result, resolution_wh, expected_results, exception",
("florence_result", "resolution_wh", "expected_results", "exception"),
[
( # Object detection: empty
{"<OD>": {"bboxes": [], "labels": []}},
@ -792,38 +792,6 @@ def test_from_moondream(
),
DoesNotRaise(),
),
( # Referring Expression Segmentation
{
"<REFERRING_EXPRESSION_SEGMENTATION>": {
"polygons": [[[1, 1, 2, 1, 2, 2, 1, 2]]],
"labels": [""],
}
},
(10, 10),
(
np.array([[1.0, 1.0, 2.0, 2.0]], dtype=np.float32),
None,
np.array(
[
[
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 1, 1, 0, 0, 0, 0, 0, 0, 0],
[0, 1, 1, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
]
],
dtype=bool,
),
None,
),
DoesNotRaise(),
),
( # OCR: unsupported
{"<OCR>": "A"},
(10, 10),
@ -928,7 +896,7 @@ def test_florence_2(
@pytest.mark.parametrize(
"exception, result, resolution_wh, classes, expected_results",
("exception", "result", "resolution_wh", "classes", "expected_results"),
[
(
does_not_raise(),
@ -1165,7 +1133,7 @@ def test_from_google_gemini_2_5(
@pytest.mark.parametrize(
"exception, result, resolution_wh, classes, expected_detections",
("exception", "result", "resolution_wh", "classes", "expected_detections"),
[
(
pytest.raises(ValueError),

View File

@ -18,7 +18,7 @@ def mock_callback():
@pytest.mark.parametrize(
"resolution_wh, slice_wh, overlap_wh, expected_offsets",
("resolution_wh", "slice_wh", "overlap_wh", "expected_offsets"),
[
# Case 1: Square image, square slices, no overlap
(

View File

@ -14,7 +14,7 @@ from supervision.detection.utils.boxes import (
@pytest.mark.parametrize(
"xyxy, resolution_wh, expected_result",
("xyxy", "resolution_wh", "expected_result"),
[
(
np.empty(shape=(0, 4)),
@ -58,7 +58,7 @@ def test_clip_boxes(
@pytest.mark.parametrize(
"xyxy, offset, expected_result, exception",
("xyxy", "offset", "expected_result", "exception"),
[
(
np.empty(shape=(0, 4)),
@ -104,7 +104,7 @@ def test_move_boxes(
@pytest.mark.parametrize(
"xyxy, factor, expected_result, exception",
("xyxy", "factor", "expected_result", "exception"),
[
(
np.empty(shape=(0, 4)),
@ -150,7 +150,7 @@ def test_scale_boxes(
@pytest.mark.parametrize(
"xyxy, resolution_wh, normalization_factor, expected_result, exception",
("xyxy", "resolution_wh", "normalization_factor", "expected_result", "exception"),
[
(
np.empty(shape=(0, 4)),

View File

@ -13,7 +13,7 @@ from supervision.detection.utils.converters import (
@pytest.mark.parametrize(
"xywh, expected_result",
("xywh", "expected_result"),
[
(np.array([[10, 20, 30, 40]]), np.array([[10, 20, 40, 60]])), # standard case
(np.array([[0, 0, 0, 0]]), np.array([[0, 0, 0, 0]])), # zero size bounding box
@ -36,7 +36,7 @@ def test_xywh_to_xyxy(xywh: np.ndarray, expected_result: np.ndarray) -> None:
@pytest.mark.parametrize(
"xyxy, expected_result",
("xyxy", "expected_result"),
[
(np.array([[10, 20, 40, 60]]), np.array([[10, 20, 30, 40]])), # standard case
(np.array([[0, 0, 0, 0]]), np.array([[0, 0, 0, 0]])), # zero size bounding box
@ -59,7 +59,7 @@ def test_xyxy_to_xywh(xyxy: np.ndarray, expected_result: np.ndarray) -> None:
@pytest.mark.parametrize(
"xyxy, expected_result",
("xyxy", "expected_result"),
[
# Empty and zero cases
(np.array([]).reshape(0, 4), np.array([]).reshape(0, 4)), # empty array
@ -110,7 +110,7 @@ def test_xyxy_to_xcycarh(xyxy: np.ndarray, expected_result: np.ndarray) -> None:
@pytest.mark.parametrize(
"xcycwh, expected_result",
("xcycwh", "expected_result"),
[
(np.array([[50, 50, 20, 30]]), np.array([[40, 35, 60, 65]])), # standard case
(np.array([[0, 0, 0, 0]]), np.array([[0, 0, 0, 0]])), # zero size bounding box
@ -133,7 +133,7 @@ def test_xcycwh_to_xyxy(xcycwh: np.ndarray, expected_result: np.ndarray) -> None
@pytest.mark.parametrize(
"boxes,resolution_wh,expected",
("boxes", "resolution_wh", "expected"),
[
# 0) Empty input
(

View File

@ -19,7 +19,7 @@ TEST_MASK[:, 300:351, 200:251] = True
@pytest.mark.parametrize(
"roboflow_result, expected_result, exception",
("roboflow_result", "expected_result", "exception"),
[
(
{"predictions": [], "image": {"width": 1000, "height": 1000}},
@ -251,7 +251,7 @@ def test_process_roboflow_result(
@pytest.mark.parametrize(
"data_list, expected_result, exception",
("data_list", "expected_result", "exception"),
[
(
[],
@ -445,7 +445,7 @@ def test_merge_data(
with exception:
result = merge_data(data_list=data_list)
if expected_result is None:
assert False, f"Expected an error, but got result {result}"
pytest.fail(f"Expected an error, but got result {result}")
for key in result:
if isinstance(result[key], np.ndarray):
@ -459,7 +459,7 @@ def test_merge_data(
@pytest.mark.parametrize(
"data, index, expected_result, exception",
("data", "index", "expected_result", "exception"),
[
({}, 0, {}, DoesNotRaise()), # empty data dict
(
@ -632,7 +632,7 @@ def test_get_data_item(
@pytest.mark.parametrize(
"metadata_list, expected_result, exception",
("metadata_list", "expected_result", "exception"),
[
# Identical metadata with a single key
([{"key1": "value1"}, {"key1": "value1"}], {"key1": "value1"}, DoesNotRaise()),

View File

@ -18,7 +18,7 @@ from test.test_utils import random_boxes
@pytest.mark.parametrize(
"predictions, iou_threshold, expected_result, exception",
("predictions", "iou_threshold", "expected_result", "exception"),
[
(
np.empty(shape=(0, 5), dtype=float),
@ -145,7 +145,7 @@ def test_group_overlapping_boxes(
@pytest.mark.parametrize(
"predictions, iou_threshold, expected_result, exception",
("predictions", "iou_threshold", "expected_result", "exception"),
[
(
np.empty(shape=(0, 5)),
@ -250,7 +250,7 @@ def test_box_non_max_suppression(
@pytest.mark.parametrize(
"predictions, masks, iou_threshold, expected_result, exception",
("predictions", "masks", "iou_threshold", "expected_result", "exception"),
[
(
np.empty((0, 6)),
@ -456,7 +456,7 @@ def test_mask_non_max_suppression(
@pytest.mark.parametrize(
"predictions, masks, iou_threshold, expected_result, exception",
("predictions", "masks", "iou_threshold", "expected_result", "exception"),
[
(
np.empty((0, 6)),
@ -638,7 +638,7 @@ def test_mask_non_max_merge(
@pytest.mark.parametrize(
"box_true, box_detection, overlap_metric, expected_overlap, exception",
("box_true", "box_detection", "overlap_metric", "expected_overlap", "exception"),
[
(
[100.0, 100.0, 200.0, 200.0],
@ -689,13 +689,6 @@ def test_mask_non_max_merge(
1.0,
DoesNotRaise(),
), # identical boxes, both boxes are arrays, IOU as uppercase string
(
[0.0, 0.0, 10.0, 10.0],
[0.0, 0.0, 10.0, 10.0],
"IOU",
1.0,
DoesNotRaise(),
), # identical boxes, both boxes are arrays, IOS as uppercase string
(
[0.0, 0.0, 10.0, 10.0],
[20.0, 20.0, 30.0, 30.0],
@ -813,7 +806,13 @@ def test_box_iou(
@pytest.mark.parametrize(
"boxes_true, boxes_detection, overlap_metric, expected_overlap, exception",
(
"boxes_true",
"boxes_detection",
"overlap_metric",
"expected_overlap",
"exception",
),
[
# both inputs empty
(
@ -1086,7 +1085,7 @@ def test_box_iou_batch(
@pytest.mark.parametrize(
"num_true, num_det",
("num_true", "num_det"),
[
(5, 5),
(5, 10),

View File

@ -16,7 +16,7 @@ from supervision.detection.utils.masks import (
@pytest.mark.parametrize(
"masks, offset, resolution_wh, expected_result, exception",
("masks", "offset", "resolution_wh", "expected_result", "exception"),
[
(
np.array(
@ -278,7 +278,7 @@ def test_move_masks(
@pytest.mark.parametrize(
"masks, expected_result, exception",
("masks", "expected_result", "exception"),
[
(
np.array(
@ -369,7 +369,7 @@ def test_calculate_masks_centroids(
@pytest.mark.parametrize(
"mask, expected_result, exception",
("mask", "expected_result", "exception"),
[
(
np.array([[0, 0, 0, 0], [0, 1, 1, 0], [0, 1, 0, 0], [0, 1, 1, 0]]).astype(
@ -424,7 +424,7 @@ def test_contains_holes(
@pytest.mark.parametrize(
"mask, connectivity, expected_result, exception",
("mask", "connectivity", "expected_result", "exception"),
[
(
np.array([[0, 0, 0, 0], [0, 1, 1, 0], [0, 1, 0, 0], [0, 1, 1, 0]]).astype(
@ -504,7 +504,15 @@ def test_contains_multiple_segments(
@pytest.mark.parametrize(
"mask, connectivity, mode, absolute_distance, relative_distance, expected_result, exception", # noqa: E501
(
"mask",
"connectivity",
"mode",
"absolute_distance",
"relative_distance",
"expected_result",
"exception",
),
[
# single component, unchanged
(

View File

@ -9,7 +9,7 @@ from supervision.detection.utils.polygons import filter_polygons_by_area
@pytest.mark.parametrize(
"polygons, min_area, max_area, expected_result, exception",
("polygons", "min_area", "max_area", "expected_result", "exception"),
[
(
[np.array([[0, 0], [0, 10], [10, 10], [10, 0]])],

View File

@ -4,7 +4,7 @@ from supervision.detection.utils.vlms import edit_distance, fuzzy_match_index
@pytest.mark.parametrize(
"string_1, string_2, case_sensitive, expected_result",
("string_1", "string_2", "case_sensitive", "expected_result"),
[
# identical strings, various cases
("hello", "hello", True, 0),
@ -68,7 +68,7 @@ def test_edit_distance(string_1, string_2, case_sensitive, expected_result):
@pytest.mark.parametrize(
"candidates, query, threshold, case_sensitive, expected_result",
("candidates", "query", "threshold", "case_sensitive", "expected_result"),
[
# exact match at index 0
(["cat", "dog", "rat"], "cat", 0, True, 0),

View File

@ -8,7 +8,7 @@ from supervision.draw.color import Color
@pytest.mark.parametrize(
"color_hex, expected_result, exception",
("color_hex", "expected_result", "exception"),
[
("fff", Color.WHITE, DoesNotRaise()),
("#fff", Color.WHITE, DoesNotRaise()),
@ -34,7 +34,7 @@ def test_color_from_hex(
@pytest.mark.parametrize(
"color, expected_result, exception",
("color", "expected_result", "exception"),
[
(Color.WHITE, "#ffffff", DoesNotRaise()),
(Color.BLACK, "#000000", DoesNotRaise()),

View File

@ -4,7 +4,7 @@ from supervision.geometry.core import Point, Vector
@pytest.mark.parametrize(
"vector, point, expected_result",
("vector", "point", "expected_result"),
[
(Vector(start=Point(x=0, y=0), end=Point(x=5, y=5)), Point(x=-1, y=1), 10.0),
(Vector(start=Point(x=0, y=0), end=Point(x=5, y=5)), Point(x=6, y=6), 0.0),
@ -34,7 +34,7 @@ def test_vector_cross_product(
@pytest.mark.parametrize(
"vector, expected_result",
("vector", "expected_result"),
[
(Vector(start=Point(x=0, y=0), end=Point(x=0, y=0)), 0.0),
(Vector(start=Point(x=1, y=0), end=Point(x=0, y=0)), 1.0),

View File

@ -35,7 +35,7 @@ def generate_test_polygon(n: int) -> np.ndarray:
@pytest.mark.parametrize(
"polygon, expected_result",
("polygon", "expected_result"),
[
(generate_test_polygon(10), Point(x=5.0, y=12.0)),
(generate_test_polygon(50), Point(x=25.0, y=61.0)),

View File

@ -22,7 +22,7 @@ KEY_POINTS = mock_key_points(
@pytest.mark.parametrize(
"key_points, index, expected_result, exception",
("key_points", "index", "expected_result", "exception"),
[
(
KeyPoints.empty(),

View File

@ -123,7 +123,7 @@ BAD_CONF_MATRIX = worsen_ideal_conf_matrix(
@pytest.mark.parametrize(
"detections, with_confidence, expected_result, exception",
("detections", "with_confidence", "expected_result", "exception"),
[
(
Detections.empty(),
@ -187,8 +187,15 @@ def test_detections_to_tensor(
@pytest.mark.parametrize(
"predictions, targets, classes, conf_threshold, iou_threshold, expected_result,"
" exception",
(
"predictions",
"targets",
"classes",
"conf_threshold",
"iou_threshold",
"expected_result",
"exception",
),
[
(
DETECTION_TENSORS,
@ -359,8 +366,15 @@ def test_from_tensors(
@pytest.mark.parametrize(
"predictions, targets, num_classes, conf_threshold, iou_threshold, expected_result,"
" exception",
(
"predictions",
"targets",
"num_classes",
"conf_threshold",
"iou_threshold",
"expected_result",
"exception",
),
[
(
DETECTION_TENSORS[0],
@ -396,7 +410,7 @@ def test_evaluate_detection_batch(
@pytest.mark.parametrize(
"matches, expected_result, exception",
("matches", "expected_result", "exception"),
[
(
IDEAL_MATCHES,
@ -417,7 +431,7 @@ def test_drop_extra_matches(
@pytest.mark.parametrize(
"recall, precision, expected_result, exception",
("recall", "precision", "expected_result", "exception"),
[
(
np.array([1.0]),

View File

@ -11,7 +11,7 @@ class TestMeanAveragePrecisionArea:
"""Test area calculation in MeanAveragePrecision."""
@pytest.mark.parametrize(
"xyxy, expected_areas, expected_size_maps",
("xyxy", "expected_areas", "expected_size_maps"),
[
(
np.array(

View File

@ -5,7 +5,7 @@ import supervision as sv
@pytest.mark.parametrize(
"detections, expected_results",
("detections", "expected_results"),
[
(
[

View File

@ -43,7 +43,7 @@ def setup_and_teardown_files():
@pytest.mark.parametrize(
"file_name, skip_empty, expected_result, exception",
("file_name", "skip_empty", "expected_result", "exception"),
[
("file_1.txt", False, ["Line 1", "Line 2", "Line 3"], DoesNotRaise()),
("file_2.txt", True, ["Line 2", "Line 4"], DoesNotRaise()),

View File

@ -103,7 +103,7 @@ def test_letterbox_image_for_pillow_image() -> None:
@pytest.mark.parametrize(
"image, xyxy, expected_size",
("image", "xyxy", "expected_size"),
[
# NumPy RGB
(
@ -143,7 +143,7 @@ def test_crop_image(image, xyxy, expected_size):
@pytest.mark.parametrize(
"image, expected",
("image", "expected"),
[
# NumPy RGB
(np.zeros((4, 6, 3), dtype=np.uint8), (6, 4)),

View File

@ -74,7 +74,7 @@ class MockDataclass:
@pytest.mark.parametrize(
"input_instance, include_properties, expected, exception",
("input_instance", "include_properties", "expected", "exception"),
[
(
MockClass,
@ -184,20 +184,6 @@ class MockDataclass:
},
DoesNotRaise(),
),
(
Detections.empty(),
False,
{
"xyxy",
"class_id",
"confidence",
"mask",
"tracker_id",
"data",
"metadata",
},
DoesNotRaise(),
),
],
)
def test_get_instance_variables(

View File

@ -4,7 +4,7 @@ from supervision.utils.iterables import create_batches, fill
@pytest.mark.parametrize(
"sequence, batch_size, expected",
("sequence", "batch_size", "expected"),
[
# Empty sequence, non-zero batch size. Expect empty list.
([], 4, []),
@ -24,7 +24,7 @@ def test_create_batches(sequence, batch_size, expected) -> None:
@pytest.mark.parametrize(
"sequence, desired_size, content, expected",
("sequence", "desired_size", "content", "expected"),
[
# Empty sequence, desired size 0. Expect empty list.
([], 0, 1, []),