fix(pre_commit): 🎨 auto format pre-commit hooks

This commit is contained in:
pre-commit-ci[bot]
2024-01-31 16:41:57 +00:00
parent 12568336ba
commit fd00bd4ba2
4 changed files with 69 additions and 33 deletions
+47 -18
View File
@@ -1,9 +1,12 @@
import os
import csv
import pytest
import os
import numpy as np
from supervision.detection.core import Detections
import pytest
import supervision as sv
from supervision.detection.core import Detections
@pytest.fixture(scope="module")
def detection_instances():
@@ -13,31 +16,42 @@ def detection_instances():
confidence=np.array([0.7, 0.8]),
class_id=np.array([0, 0]),
tracker_id=np.array([0, 1]),
data={'class_name': np.array(['person', 'person'])}
data={"class_name": np.array(["person", "person"])},
)
second_detections = Detections(
xyxy=np.array([[15, 25, 35, 45], [55, 65, 75, 85]]),
confidence=np.array([0.6, 0.9]),
class_id=np.array([1, 1]),
tracker_id=np.array([2, 3]),
data={'class_name': np.array(['car', 'car'])}
data={"class_name": np.array(["car", "car"])},
)
custom_data = {'frame_number': 42}
second_custom_data = {'frame_number': 43}
custom_data = {"frame_number": 42}
second_custom_data = {"frame_number": 43}
return detections, custom_data, second_detections, second_custom_data
def test_csv_sink(detection_instances):
detections, custom_data, second_detections, second_custom_data = detection_instances
csv_filename = "test_detections.csv"
expected_rows = [
["x_min", "y_min", "x_max", "y_max", "class_id", "confidence", "tracker_id", "class_name", "frame_number"],
[
"x_min",
"y_min",
"x_max",
"y_max",
"class_id",
"confidence",
"tracker_id",
"class_name",
"frame_number",
],
[10, 20, 30, 40, 0, 0.7, 0, "person", 42],
[50, 60, 70, 80, 0, 0.8, 1, "person", 42],
[15, 25, 35, 45, 1, 0.6, 2, "car", 43],
[55, 65, 75, 85, 1, 0.9, 3, "car", 43]
[55, 65, 75, 85, 1, 0.9, 3, "car", 43],
]
# Using the CSVSink class to write the detection data to a CSV file
@@ -46,23 +60,36 @@ def test_csv_sink(detection_instances):
sink.append(second_detections, second_custom_data)
# Read back the CSV file and verify its contents
with open(csv_filename, mode='r', newline='') as file:
with open(csv_filename, 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]}"
# Clean up by removing the test CSV file
os.remove(csv_filename)
def test_csv_sink_manual(detection_instances):
detections, custom_data, second_detections, second_custom_data = detection_instances
csv_filename = "test_detections.csv"
expected_rows = [
["x_min", "y_min", "x_max", "y_max", "class_id", "confidence", "tracker_id", "class_name", "frame_number"],
[
"x_min",
"y_min",
"x_max",
"y_max",
"class_id",
"confidence",
"tracker_id",
"class_name",
"frame_number",
],
[10, 20, 30, 40, 0, 0.7, 0, "person", 42],
[50, 60, 70, 80, 0, 0.8, 1, "person", 42],
[15, 25, 35, 45, 1, 0.6, 2, "car", 43],
[55, 65, 75, 85, 1, 0.9, 3, "car", 43]
[55, 65, 75, 85, 1, 0.9, 3, "car", 43],
]
# Using the CSVSink class to write the detection data to a CSV file
@@ -73,10 +100,12 @@ def test_csv_sink_manual(detection_instances):
sink.close()
# Read back the CSV file and verify its contents
with open(csv_filename, mode='r', newline='') as file:
with open(csv_filename, 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]}"
# Clean up by removing the test CSV file
os.remove(csv_filename)