diff --git a/supervision/detection/core.py b/supervision/detection/core.py index ca4ded1ff..ebe338fa0 100644 --- a/supervision/detection/core.py +++ b/supervision/detection/core.py @@ -712,7 +712,7 @@ def from_azure_analyze_image( """ if "error" in azure_result: raise ValueError( - f'Azure API returned an error {azure_result["error"]["message"]}' + f"Azure API returned an error {azure_result['error']['message']}" ) xyxy, confidences, class_ids = [], [], [] @@ -1306,9 +1306,9 @@ def with_nms( if len(self) == 0: return self - assert ( - self.confidence is not None - ), "Detections confidence must be given for NMS to be executed." + assert self.confidence is not None, ( + "Detections confidence must be given for NMS to be executed." + ) if class_agnostic: predictions = np.hstack((self.xyxy, self.confidence.reshape(-1, 1))) @@ -1362,9 +1362,9 @@ def with_nmm( if len(self) == 0: return self - assert ( - self.confidence is not None - ), "Detections confidence must be given for NMM to be executed." + assert self.confidence is not None, ( + "Detections confidence must be given for NMM to be executed." + ) if class_agnostic: predictions = np.hstack((self.xyxy, self.confidence.reshape(-1, 1))) diff --git a/supervision/detection/lmm.py b/supervision/detection/lmm.py index 7879902f3..28b21506a 100644 --- a/supervision/detection/lmm.py +++ b/supervision/detection/lmm.py @@ -161,18 +161,18 @@ def from_florence_2( return xyxy, labels, None, None if task in ["", ""]: - assert isinstance( - result, str - ), f"Expected string as result, got {type(result)}" + assert isinstance(result, str), ( + f"Expected string as result, got {type(result)}" + ) if result == "No object detected.": return np.empty((0, 4), dtype=np.float32), np.array([]), None, None pattern = re.compile(r"") match = pattern.search(result) - assert ( - match is not None - ), f"Expected string to end in location tags, but got {result}" + assert match is not None, ( + f"Expected string to end in location tags, but got {result}" + ) w, h = resolution_wh xyxy = np.array([match.groups()], dtype=np.float32) diff --git a/supervision/detection/overlap_filter.py b/supervision/detection/overlap_filter.py index 4c59295f6..133e2f6d1 100644 --- a/supervision/detection/overlap_filter.py +++ b/supervision/detection/overlap_filter.py @@ -226,8 +226,7 @@ def box_non_max_merge( for merge_group in merge_groups: if len(merge_group) == 0: raise ValueError( - f"Empty group detected when non-max-merging " - f"detections: {merge_groups}" + f"Empty group detected when non-max-merging detections: {merge_groups}" ) return merge_groups diff --git a/supervision/metrics/mean_average_recall.py b/supervision/metrics/mean_average_recall.py index 9c3a40718..464c203a4 100644 --- a/supervision/metrics/mean_average_recall.py +++ b/supervision/metrics/mean_average_recall.py @@ -670,8 +670,7 @@ def plot(self): ax.set_ylim(0, 1) ax.set_ylabel("Value", fontweight="bold") title = ( - f"Mean Average Recall, by Object Size" - f"\n(target: {self.metric_target.value})" + f"Mean Average Recall, by Object Size\n(target: {self.metric_target.value})" ) ax.set_title(title, fontweight="bold") diff --git a/supervision/validators/__init__.py b/supervision/validators/__init__.py index 44cfcb988..29ac0da9b 100644 --- a/supervision/validators/__init__.py +++ b/supervision/validators/__init__.py @@ -54,7 +54,7 @@ def validate_confidence(confidence: Any, n: int) -> None: def validate_keypoint_confidence(confidence: Any, n: int, m: int) -> None: - expected_shape = f"({n,m})" + expected_shape = f"({n, m})" actual_shape = str(getattr(confidence, "shape", None)) if confidence is not None: diff --git a/test/detection/test_csv.py b/test/detection/test_csv.py index e14144249..0c51a0e3c 100644 --- a/test/detection/test_csv.py +++ b/test/detection/test_csv.py @@ -408,8 +408,8 @@ def assert_csv_equal(file_name, expected_rows): with open(file_name, mode="r", newline="") as file: reader = csv.reader(file) for i, row in enumerate(reader): - assert ( - [str(item) for item in expected_rows[i]] == row - ), f"Row in CSV didn't match expected output: {row} != {expected_rows[i]}" + assert [str(item) for item in expected_rows[i]] == row, ( + f"Row in CSV didn't match expected output: {row} != {expected_rows[i]}" + ) os.remove(file_name) diff --git a/test/detection/test_json.py b/test/detection/test_json.py index d5f249249..b6c8524df 100644 --- a/test/detection/test_json.py +++ b/test/detection/test_json.py @@ -242,8 +242,8 @@ def test_json_sink( def assert_json_equal(file_name, expected_rows): with open(file_name, "r") as file: data = json.load(file) - assert ( - data == expected_rows - ), f"Data in JSON file didn't match expected output: {data} != {expected_rows}" + assert data == expected_rows, ( + f"Data in JSON file didn't match expected output: {data} != {expected_rows}" + ) os.remove(file_name) diff --git a/test/detection/test_line_counter.py b/test/detection/test_line_counter.py index a140add55..0119cf86e 100644 --- a/test/detection/test_line_counter.py +++ b/test/detection/test_line_counter.py @@ -250,12 +250,12 @@ def test_line_zone_one_detection_default_anchors( crossed_in_list.append(crossed_in[0]) crossed_out_list.append(crossed_out[0]) - assert ( - crossed_in_list == expected_crossed_in - ), f"expected {expected_crossed_in}, got {crossed_in_list}" - assert ( - crossed_out_list == expected_crossed_out - ), f"expected {expected_crossed_out}, got {crossed_out_list}" + assert crossed_in_list == expected_crossed_in, ( + f"expected {expected_crossed_in}, got {crossed_in_list}" + ) + assert crossed_out_list == expected_crossed_out, ( + f"expected {expected_crossed_out}, got {crossed_out_list}" + ) @pytest.mark.parametrize( @@ -415,12 +415,12 @@ def test_line_zone_one_detection( crossed_in_list.append(crossed_in[0]) crossed_out_list.append(crossed_out[0]) - assert ( - crossed_in_list == expected_crossed_in - ), f"expected {expected_crossed_in}, got {crossed_in_list}" - assert ( - crossed_out_list == expected_crossed_out - ), f"expected {expected_crossed_out}, got {crossed_out_list}" + assert crossed_in_list == expected_crossed_in, ( + f"expected {expected_crossed_in}, got {crossed_in_list}" + ) + assert crossed_out_list == expected_crossed_out, ( + f"expected {expected_crossed_out}, got {crossed_out_list}" + ) @pytest.mark.parametrize( @@ -600,12 +600,12 @@ def test_line_zone_one_detection_long_horizon( crossed_in_list.append(crossed_in[0]) crossed_out_list.append(crossed_out[0]) - assert ( - crossed_in_list == expected_crossed_in - ), f"expected {expected_crossed_in}, got {crossed_in_list}" - assert ( - crossed_out_list == expected_crossed_out - ), f"expected {expected_crossed_out}, got {crossed_out_list}" + assert crossed_in_list == expected_crossed_in, ( + f"expected {expected_crossed_in}, got {crossed_in_list}" + ) + assert crossed_out_list == expected_crossed_out, ( + f"expected {expected_crossed_out}, got {crossed_out_list}" + ) @pytest.mark.parametrize( diff --git a/test/detection/test_utils.py b/test/detection/test_utils.py index d93c72c83..1d75e5fbb 100644 --- a/test/detection/test_utils.py +++ b/test/detection/test_utils.py @@ -388,13 +388,13 @@ def test_process_roboflow_result( ) for key in result[5]: if isinstance(result[5][key], np.ndarray): - assert np.array_equal( - result[5][key], expected_result[5][key] - ), f"Mismatch in arrays for key {key}" + assert np.array_equal(result[5][key], expected_result[5][key]), ( + f"Mismatch in arrays for key {key}" + ) else: - assert ( - result[5][key] == expected_result[5][key] - ), f"Mismatch in non-array data for key {key}" + assert result[5][key] == expected_result[5][key], ( + f"Mismatch in non-array data for key {key}" + ) @pytest.mark.parametrize( @@ -1041,13 +1041,13 @@ def test_merge_data( for key in result: if isinstance(result[key], np.ndarray): - assert np.array_equal( - result[key], expected_result[key] - ), f"Mismatch in arrays for key {key}" + assert np.array_equal(result[key], expected_result[key]), ( + f"Mismatch in arrays for key {key}" + ) else: - assert ( - result[key] == expected_result[key] - ), f"Mismatch in non-array data for key {key}" + assert result[key] == expected_result[key], ( + f"Mismatch in non-array data for key {key}" + ) @pytest.mark.parametrize( @@ -1214,13 +1214,13 @@ def test_get_data_item( result = get_data_item(data=data, index=index) for key in result: if isinstance(result[key], np.ndarray): - assert np.array_equal( - result[key], expected_result[key] - ), f"Mismatch in arrays for key {key}" + assert np.array_equal(result[key], expected_result[key]), ( + f"Mismatch in arrays for key {key}" + ) else: - assert ( - result[key] == expected_result[key] - ), f"Mismatch in non-array data for key {key}" + assert result[key] == expected_result[key], ( + f"Mismatch in non-array data for key {key}" + ) @pytest.mark.parametrize( diff --git a/test/detection/tools/test_inference_slicer.py b/test/detection/tools/test_inference_slicer.py index 1e03e158b..e484f5134 100644 --- a/test/detection/tools/test_inference_slicer.py +++ b/test/detection/tools/test_inference_slicer.py @@ -180,6 +180,6 @@ def test_generate_offset( ) # Verify that the generated offsets match the expected offsets - assert np.array_equal( - offsets, expected_offsets - ), f"Expected {expected_offsets}, got {offsets}" + assert np.array_equal(offsets, expected_offsets), ( + f"Expected {expected_offsets}, got {offsets}" + ) diff --git a/test/utils/test_conversion.py b/test/utils/test_conversion.py index 6ff0c630b..65cbd8a1c 100644 --- a/test/utils/test_conversion.py +++ b/test/utils/test_conversion.py @@ -22,15 +22,15 @@ def my_custom_processing_function( param_a: int, param_b: str, ) -> np.ndarray: - assert np.allclose( - image, empty_cv2_image - ), "Expected conversion to OpenCV image to happen" - assert ( - param_a == param_a_value - ), f"Parameter a expected to be {param_a_value} in target function" - assert ( - param_b == param_b_value - ), f"Parameter b expected to be {param_b_value} in target function" + assert np.allclose(image, empty_cv2_image), ( + "Expected conversion to OpenCV image to happen" + ) + assert param_a == param_a_value, ( + f"Parameter a expected to be {param_a_value} in target function" + ) + assert param_b == param_b_value, ( + f"Parameter b expected to be {param_b_value} in target function" + ) return image # when @@ -61,15 +61,15 @@ def my_custom_processing_function( param_a: int, param_b: str, ) -> np.ndarray: - assert np.allclose( - image, empty_cv2_image - ), "Expected conversion to OpenCV image to happen" - assert ( - param_a == param_a_value - ), f"Parameter a expected to be {param_a_value} in target function" - assert ( - param_b == param_b_value - ), f"Parameter b expected to be {param_b_value} in target function" + assert np.allclose(image, empty_cv2_image), ( + "Expected conversion to OpenCV image to happen" + ) + assert param_a == param_a_value, ( + f"Parameter a expected to be {param_a_value} in target function" + ) + assert param_b == param_b_value, ( + f"Parameter b expected to be {param_b_value} in target function" + ) return image # when @@ -91,9 +91,9 @@ def test_cv2_to_pillow( # then difference = ImageChops.difference(result, empty_pillow_image) - assert ( - difference.getbbox() is None - ), "Conversion to PIL.Image expected not to change the content of image" + assert difference.getbbox() is None, ( + "Conversion to PIL.Image expected not to change the content of image" + ) def test_pillow_to_cv2( @@ -103,9 +103,9 @@ def test_pillow_to_cv2( result = pillow_to_cv2(image=empty_pillow_image) # then - assert np.allclose( - result, empty_cv2_image - ), "Conversion to OpenCV image expected not to change the content of image" + assert np.allclose(result, empty_cv2_image), ( + "Conversion to OpenCV image expected not to change the content of image" + ) def test_images_to_cv2_when_empty_input_provided() -> None: @@ -128,9 +128,9 @@ def test_images_to_cv2_when_only_cv2_images_provided( # then assert len(result) == 5, "Expected the same number of output element as input ones" for result_element in result: - assert ( - result_element is empty_cv2_image - ), "Expected CV images not to be touched by conversion" + assert result_element is empty_cv2_image, ( + "Expected CV images not to be touched by conversion" + ) def test_images_to_cv2_when_only_pillow_images_provided( @@ -146,9 +146,9 @@ def test_images_to_cv2_when_only_pillow_images_provided( # then assert len(result) == 5, "Expected the same number of output element as input ones" for result_element in result: - assert np.allclose( - result_element, empty_cv2_image - ), "Output images expected to be equal to empty OpenCV image" + assert np.allclose(result_element, empty_cv2_image), ( + "Output images expected to be equal to empty OpenCV image" + ) def test_images_to_cv2_when_mixed_input_provided( @@ -163,9 +163,9 @@ def test_images_to_cv2_when_mixed_input_provided( # then assert len(result) == 2, "Expected the same number of output element as input ones" - assert np.allclose( - result[0], empty_cv2_image - ), "PIL image should be converted to OpenCV one, equal to example empty image" - assert ( - result[1] is empty_cv2_image - ), "Expected CV images not to be touched by conversion" + assert np.allclose(result[0], empty_cv2_image), ( + "PIL image should be converted to OpenCV one, equal to example empty image" + ) + assert result[1] is empty_cv2_image, ( + "Expected CV images not to be touched by conversion" + ) diff --git a/test/utils/test_image.py b/test/utils/test_image.py index 487434aed..80caf9894 100644 --- a/test/utils/test_image.py +++ b/test/utils/test_image.py @@ -21,9 +21,9 @@ def test_resize_image_for_opencv_image() -> None: ) # then - assert np.allclose( - result, expected_result - ), "Expected output shape to be (w, h): (1024, 768)" + assert np.allclose(result, expected_result), ( + "Expected output shape to be (w, h): (1024, 768)" + ) def test_resize_image_for_pillow_image() -> None: @@ -41,9 +41,9 @@ def test_resize_image_for_pillow_image() -> None: # then assert result.size == (1024, 768), "Expected output shape to be (w, h): (1024, 768)" difference = ImageChops.difference(result, expected_result) - assert ( - difference.getbbox() is None - ), "Expected no difference in resized image content as the image is all zeros" + assert difference.getbbox() is None, ( + "Expected no difference in resized image content as the image is all zeros" + ) def test_letterbox_image_for_opencv_image() -> None: @@ -95,9 +95,9 @@ def test_letterbox_image_for_pillow_image() -> None: 1024, ), "Expected output shape to be (w, h): (1024, 1024)" difference = ImageChops.difference(result, expected_result) - assert ( - difference.getbbox() is None - ), "Expected padding to be added top and bottom with padding added top and bottom" + assert difference.getbbox() is None, ( + "Expected padding to be added top and bottom with padding added top and bottom" + ) def test_create_tiles_with_one_image(