Skip to content

Commit

Permalink
Add pytest approx to float comparisons in tests where not currently u…
Browse files Browse the repository at this point in the history
…sed and it makes sense to do so.
  • Loading branch information
jatkinson1000 committed Oct 29, 2024
1 parent 0222059 commit e9025fe
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion archeryutils/tests/test_length.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def test_pluralised_unit_alises_available(self):
)
def test_conversion_to_metres(self, value, unit, result):
"""Test conversion from other units to metres."""
assert length.to_metres(value, unit) == result
assert length.to_metres(value, unit) == pytest.approx(result)

@pytest.mark.parametrize(
"value,unit,result",
Expand Down
8 changes: 4 additions & 4 deletions archeryutils/tests/test_targets.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def test_yard_to_m_conversion(self) -> None:
"""Check Target() returns correct distance in metres when yards provided."""
target = Target("5_zone", 122, (50, "yards"))
assert target.native_distance == (50, "yard")
assert target.distance == 50.0 * 0.9144
assert target.distance == pytest.approx(50.0 * 0.9144)

def test_invalid_diameter_unit(self) -> None:
"""Check Target() raises error when called with unsupported diameter units."""
Expand All @@ -112,7 +112,7 @@ def test_invalid_diameter_unit(self) -> None:
def test_default_diameter_unit(self) -> None:
"""Check that Target() is using centimetres by default for diameter."""
target = Target("10_zone_5_ring_compound", 80, 50)
assert target.diameter == 80 * 0.01
assert target.diameter == pytest.approx(80 * 0.01)

def test_diameter_metres_not_converted(self) -> None:
"""Check that Target() is storing diameter in metres."""
Expand All @@ -123,7 +123,7 @@ def test_diameter_inches_supported(self) -> None:
"""Check that Target() converts diameters in inches correctly."""
target = Target("Worcester", (16, "inches"), (20, "yards"), indoor=True)
assert target.native_diameter == (16, "inch")
assert target.diameter == 16 * 0.0254
assert target.diameter == pytest.approx(16 * 0.0254)

def test_diameter_distance_units_coerced_to_definitive_names(self) -> None:
"""Check that Target coerces aliased distance units into standard names."""
Expand Down Expand Up @@ -349,7 +349,7 @@ class TestCustomScoringTarget:
def test_constructor(self) -> None:
"""Check initialisation of Target with a custom scoring system and spec."""
target = Target.from_face_spec({0.1: 3, 0.5: 1}, 80, (50, "yard"))
assert target.distance == 50.0 * 0.9144
assert target.distance == pytest.approx(50.0 * 0.9144)
assert target.diameter == 0.8
assert target.scoring_system == "Custom"
assert target.face_spec == {0.1: 3, 0.5: 1}
Expand Down

0 comments on commit e9025fe

Please sign in to comment.