4
4
from pathlib import Path
5
5
6
6
import pytest
7
+ from pytest import approx
7
8
8
9
from sb_vision import Cartesian , FileCamera , Spherical , Vision
9
10
37
38
]
38
39
39
40
40
- def assertWithinTolerance (val , expected , tolerance , error_msg = "" ):
41
- """Assert that the value is within a certain tolerance value."""
42
- assert (expected - tolerance ) < val < (expected + tolerance ), error_msg
43
-
44
-
45
41
@pytest .mark .parametrize (
46
42
"photo, expected_cartesian, expected_spherical" ,
47
43
TEST_IMAGES ,
@@ -57,16 +53,10 @@ def test_image_coordinates(photo, expected_cartesian, expected_spherical):
57
53
58
54
tolerance = dist * DIST_PERCENT_TOLERANCE
59
55
60
- assertWithinTolerance (x , expected_cartesian .x , tolerance ,
61
- "Wrong x-coordinate" )
62
- assertWithinTolerance (y , expected_cartesian .y , tolerance ,
63
- "Wrong y-coordinate" )
64
- assertWithinTolerance (z , expected_cartesian .z , tolerance ,
65
- "Wrong z-coordinate" )
56
+ assert x == approx (expected_cartesian .x , abs = tolerance ), "Wrong x-coordinate"
57
+ assert y == approx (expected_cartesian .y , abs = tolerance ), "Wrong y-coordinate"
58
+ assert z == approx (expected_cartesian .z , abs = tolerance ), "Wrong z-coordinate"
66
59
67
- assertWithinTolerance (rot_x , expected_spherical .rot_x , ROTATION_TOLERANCE ,
68
- "Wrong x rotation" )
69
- assertWithinTolerance (rot_y , expected_spherical .rot_y , ROTATION_TOLERANCE ,
70
- "Wrong y rotation" )
71
- assertWithinTolerance (dist , expected_spherical .dist , tolerance ,
72
- "Wrong distance" )
60
+ assert rot_x == approx (expected_spherical .rot_x , abs = tolerance ), "Wrong x-coordinate"
61
+ assert rot_y == approx (expected_spherical .rot_y , abs = tolerance ), "Wrong y-coordinate"
62
+ assert dist == approx (expected_spherical .dist , abs = tolerance ), "Wrong distance"
0 commit comments