Skip to content

Commit 0434ae2

Browse files
committed
fix: import future.annotations for Py <= 3.12
1 parent 794364e commit 0434ae2

6 files changed

Lines changed: 38 additions & 47 deletions

File tree

.envrc.recommended

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33
watch_file pixi.toml
44
watch_file pixi.lock
5-
eval "$(pixi shell-hook)"
5+
eval "$(pixi shell-hook -e py312)"

tests/conftest.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
PerceMon Python bindings.
66
"""
77

8+
from __future__ import annotations
9+
810
import percemon
911
import pytest
1012

tests/test_datastream.py

Lines changed: 26 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
- euclidean_distance() computation
1111
"""
1212

13+
from __future__ import annotations
14+
1315
import percemon
1416
import pytest
1517

@@ -19,12 +21,12 @@ class TestRefPointTypeEnum:
1921

2022
def test_ref_point_type_enum(self) -> None:
2123
"""Test RefPointType enum values."""
22-
assert hasattr(percemon, 'RefPointType')
23-
assert hasattr(percemon.RefPointType, 'LeftMargin')
24-
assert hasattr(percemon.RefPointType, 'RightMargin')
25-
assert hasattr(percemon.RefPointType, 'TopMargin')
26-
assert hasattr(percemon.RefPointType, 'BottomMargin')
27-
assert hasattr(percemon.RefPointType, 'Center')
24+
assert hasattr(percemon, "RefPointType")
25+
assert hasattr(percemon.RefPointType, "LeftMargin")
26+
assert hasattr(percemon.RefPointType, "RightMargin")
27+
assert hasattr(percemon.RefPointType, "TopMargin")
28+
assert hasattr(percemon.RefPointType, "BottomMargin")
29+
assert hasattr(percemon.RefPointType, "Center")
2830

2931

3032
class TestBoundingBox:
@@ -33,10 +35,10 @@ class TestBoundingBox:
3335
def test_bounding_box_construction(self) -> None:
3436
"""Test BoundingBox default construction."""
3537
bbox = percemon.BoundingBox()
36-
assert hasattr(bbox, 'xmin')
37-
assert hasattr(bbox, 'xmax')
38-
assert hasattr(bbox, 'ymin')
39-
assert hasattr(bbox, 'ymax')
38+
assert hasattr(bbox, "xmin")
39+
assert hasattr(bbox, "xmax")
40+
assert hasattr(bbox, "ymin")
41+
assert hasattr(bbox, "ymax")
4042

4143
def test_bounding_box_with_values(self) -> None:
4244
"""Test BoundingBox construction with values."""
@@ -95,9 +97,9 @@ class TestObject:
9597
def test_object_construction(self) -> None:
9698
"""Test Object default construction."""
9799
obj = percemon.Object()
98-
assert hasattr(obj, 'object_class')
99-
assert hasattr(obj, 'probability')
100-
assert hasattr(obj, 'bbox')
100+
assert hasattr(obj, "object_class")
101+
assert hasattr(obj, "probability")
102+
assert hasattr(obj, "bbox")
101103

102104
def test_object_with_values(self, sample_object) -> None:
103105
"""Test Object with assigned values."""
@@ -147,11 +149,11 @@ class TestFrame:
147149
def test_frame_construction(self) -> None:
148150
"""Test Frame default construction."""
149151
frame = percemon.Frame()
150-
assert hasattr(frame, 'timestamp')
151-
assert hasattr(frame, 'frame_num')
152-
assert hasattr(frame, 'size_x')
153-
assert hasattr(frame, 'size_y')
154-
assert hasattr(frame, 'objects')
152+
assert hasattr(frame, "timestamp")
153+
assert hasattr(frame, "frame_num")
154+
assert hasattr(frame, "size_x")
155+
assert hasattr(frame, "size_y")
156+
assert hasattr(frame, "objects")
155157

156158
def test_frame_properties(self, empty_frame) -> None:
157159
"""Test Frame property assignment."""
@@ -267,8 +269,7 @@ class TestEuclideanDistance:
267269
def test_euclidean_distance_same_point(self, sample_bounding_box) -> None:
268270
"""Test euclidean_distance between same points."""
269271
dist = percemon.euclidean_distance(
270-
sample_bounding_box, percemon.RefPointType.Center,
271-
sample_bounding_box, percemon.RefPointType.Center
272+
sample_bounding_box, percemon.RefPointType.Center, sample_bounding_box, percemon.RefPointType.Center
272273
)
273274
assert dist == pytest.approx(0.0)
274275

@@ -277,10 +278,7 @@ def test_euclidean_distance_different_centers(self) -> None:
277278
bbox1 = percemon.BoundingBox(0.0, 100.0, 0.0, 100.0)
278279
bbox2 = percemon.BoundingBox(100.0, 200.0, 0.0, 100.0)
279280

280-
dist = percemon.euclidean_distance(
281-
bbox1, percemon.RefPointType.Center,
282-
bbox2, percemon.RefPointType.Center
283-
)
281+
dist = percemon.euclidean_distance(bbox1, percemon.RefPointType.Center, bbox2, percemon.RefPointType.Center)
284282
# Centers are at (50, 50) and (150, 50), distance = 100
285283
assert dist == pytest.approx(100.0)
286284

@@ -289,10 +287,7 @@ def test_euclidean_distance_vertical(self) -> None:
289287
bbox1 = percemon.BoundingBox(0.0, 100.0, 0.0, 100.0)
290288
bbox2 = percemon.BoundingBox(0.0, 100.0, 100.0, 200.0)
291289

292-
dist = percemon.euclidean_distance(
293-
bbox1, percemon.RefPointType.Center,
294-
bbox2, percemon.RefPointType.Center
295-
)
290+
dist = percemon.euclidean_distance(bbox1, percemon.RefPointType.Center, bbox2, percemon.RefPointType.Center)
296291
# Centers are at (50, 50) and (50, 150), distance = 100
297292
assert dist == pytest.approx(100.0)
298293

@@ -301,10 +296,7 @@ def test_euclidean_distance_diagonal(self) -> None:
301296
bbox1 = percemon.BoundingBox(0.0, 100.0, 0.0, 100.0)
302297
bbox2 = percemon.BoundingBox(100.0, 200.0, 100.0, 200.0)
303298

304-
dist = percemon.euclidean_distance(
305-
bbox1, percemon.RefPointType.Center,
306-
bbox2, percemon.RefPointType.Center
307-
)
299+
dist = percemon.euclidean_distance(bbox1, percemon.RefPointType.Center, bbox2, percemon.RefPointType.Center)
308300
# Centers are at (50, 50) and (150, 150)
309301
# distance = sqrt((100)^2 + (100)^2) = sqrt(20000) ≈ 141.42
310302
assert dist == pytest.approx(141.42, rel=1e-2)
@@ -314,10 +306,7 @@ def test_euclidean_distance_between_edges(self) -> None:
314306
bbox1 = percemon.BoundingBox(0.0, 100.0, 0.0, 100.0)
315307
bbox2 = percemon.BoundingBox(100.0, 200.0, 0.0, 100.0)
316308

317-
dist = percemon.euclidean_distance(
318-
bbox1, percemon.RefPointType.RightMargin,
319-
bbox2, percemon.RefPointType.LeftMargin
320-
)
309+
dist = percemon.euclidean_distance(bbox1, percemon.RefPointType.RightMargin, bbox2, percemon.RefPointType.LeftMargin)
321310
# Right margin of bbox1 at (100, 50)
322311
# Left margin of bbox2 at (100, 50)
323312
# distance = 0
@@ -371,9 +360,6 @@ def test_compute_distance_between_frame_objects(self) -> None:
371360
frame.objects["obj2"] = obj2
372361

373362
# Compute distance
374-
dist = percemon.euclidean_distance(
375-
obj1_bbox, percemon.RefPointType.Center,
376-
obj2_bbox, percemon.RefPointType.Center
377-
)
363+
dist = percemon.euclidean_distance(obj1_bbox, percemon.RefPointType.Center, obj2_bbox, percemon.RefPointType.Center)
378364
# Centers at (50, 50) and (350, 50), distance = 300
379365
assert dist == pytest.approx(300.0)

tests/test_monitoring.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
- UNBOUNDED constant
1010
"""
1111

12+
from __future__ import annotations
13+
1214
import percemon
1315

1416

tests/test_online_monitor.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
- Frame-by-frame evaluation workflows
1010
"""
1111

12+
from __future__ import annotations
13+
1214
import percemon
1315

1416

@@ -65,8 +67,8 @@ def test_requirements_accessor(self) -> None:
6567
monitor = percemon.OnlineMonitor(formula)
6668
reqs = monitor.requirements()
6769
assert isinstance(reqs, percemon.MonitoringRequirements)
68-
assert hasattr(reqs, 'history')
69-
assert hasattr(reqs, 'horizon')
70+
assert hasattr(reqs, "history")
71+
assert hasattr(reqs, "horizon")
7072

7173
def test_requirements_past_time(self) -> None:
7274
"""Test requirements for past-time formula."""
@@ -303,10 +305,7 @@ def test_monitoring_with_perception_helpers(self) -> None:
303305
car = percemon.ObjectVar("car")
304306

305307
# Formula: exists car with class 1 and high confidence
306-
formula = percemon.exists(
307-
[car],
308-
percemon.is_class(car, 1) & percemon.high_confidence(car, 0.8)
309-
)
308+
formula = percemon.exists([car], percemon.is_class(car, 1) & percemon.high_confidence(car, 0.8))
310309

311310
monitor = percemon.OnlineMonitor(formula, fps=30.0)
312311

tests/test_stql.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
- Perception helpers
1212
"""
1313

14+
from __future__ import annotations
15+
1416
import percemon
1517

1618

0 commit comments

Comments
 (0)