Skip to content

Commit

Permalink
Run autopep8 on tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jdeniau committed Jul 15, 2022
1 parent d4b3cdf commit e71ddf4
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 15 deletions.
18 changes: 9 additions & 9 deletions tests/geo_ressources.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@
LONDON = (51.509865, -0.118092)

EXPECTED_LYON_PARIS = {Unit.KILOMETERS: 392.2172595594006,
Unit.METERS: 392217.2595594006,
Unit.MILES: 243.71250609539814,
Unit.NAUTICAL_MILES: 211.78037755311516,
Unit.FEET: 1286802.0326751503,
Unit.INCHES: 15441624.392102592,
Unit.RADIANS: 0.061562818679421795,
Unit.DEGREES: 3.5272896852600164}
Unit.METERS: 392217.2595594006,
Unit.MILES: 243.71250609539814,
Unit.NAUTICAL_MILES: 211.78037755311516,
Unit.FEET: 1286802.0326751503,
Unit.INCHES: 15441624.392102592,
Unit.RADIANS: 0.061562818679421795,
Unit.DEGREES: 3.5272896852600164}
EXPECTED_LYON_NEW_YORK = {Unit.KILOMETERS: 6163.43638211,
Unit.METERS: 61634363.8211 }
Unit.METERS: 61634363.8211}
EXPECTED_PARIS_NEW_YORK = {Unit.KILOMETERS: 5853.32898662,
Unit.METERS: 58533289.8662 }
Unit.METERS: 58533289.8662}
EXPECTED_LONDON_PARIS = {Unit.KILOMETERS: 343.37455271}
EXPECTED_LONDON_NEW_YORK = {Unit.KILOMETERS: 5586.48447423}
2 changes: 2 additions & 0 deletions tests/test_haversine.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from tests.geo_ressources import LYON, PARIS, NEW_YORK, LONDON, EXPECTED_LYON_PARIS


def haversine_test_factory(unit):
def test():
expected = EXPECTED_LYON_PARIS[unit]
Expand Down Expand Up @@ -81,6 +82,7 @@ def test_out_of_bounds(oob_from, oob_to):
with pytest.raises(ValueError):
haversine(oob_from, oob_to, normalize=False)


@pytest.mark.parametrize(
"in_bounds_from,in_bounds_to", [
((-90, 0), (0, 0)),
Expand Down
10 changes: 7 additions & 3 deletions tests/test_haversine_vector.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from tests.geo_ressources import EXPECTED_LONDON_PARIS, EXPECTED_LYON_NEW_YORK, EXPECTED_LYON_PARIS, EXPECTED_LONDON_NEW_YORK, LYON, PARIS, NEW_YORK, LONDON


@pytest.mark.parametrize(
'unit', [Unit.KILOMETERS, Unit.METERS, Unit.INCHES]
)
Expand All @@ -12,7 +13,8 @@ def test_lyon_paris(unit):
expected_lyon_paris = EXPECTED_LYON_PARIS[unit]
assert haversine_vector(LYON, PARIS, unit=unit) == expected_lyon_paris
assert isinstance(unit.value, str)
assert haversine_vector(LYON, PARIS, unit=unit.value) == expected_lyon_paris
assert haversine_vector(
LYON, PARIS, unit=unit.value) == expected_lyon_paris

return test_lyon_paris(unit)

Expand All @@ -38,7 +40,8 @@ def test_normalization(oob_from, oob_to, proper_from, proper_to):
"""
normalized_during, normalized_already = (
haversine_vector([oob_from], [oob_to], Unit.DEGREES, normalize=True),
haversine_vector([proper_from], [proper_to], Unit.DEGREES, normalize=True),
haversine_vector([proper_from], [proper_to],
Unit.DEGREES, normalize=True),
)
assert normalized_during == pytest.approx(normalized_already, abs=1e-10)

Expand Down Expand Up @@ -68,11 +71,12 @@ def test_haversine_vector_comb():
[EXPECTED_LYON_NEW_YORK[unit], EXPECTED_LONDON_NEW_YORK[unit]]
]

assert_allclose( # See https://numpy.org/doc/stable/reference/generated/numpy.testing.assert_allclose.html#numpy.testing.assert_allclose
assert_allclose( # See https://numpy.org/doc/stable/reference/generated/numpy.testing.assert_allclose.html#numpy.testing.assert_allclose
haversine_vector([LYON, LONDON], [PARIS, NEW_YORK], unit, comb=True),
expected
)


def test_units_enum():
from haversine.haversine import _CONVERSIONS
assert all(unit in _CONVERSIONS for unit in Unit)
10 changes: 7 additions & 3 deletions tests/test_inverse_haversine.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from tests.geo_ressources import LYON, PARIS, NEW_YORK, LONDON


@pytest.mark.parametrize(
"point, dir, dist, result",
[
Expand All @@ -18,7 +19,8 @@
],
)
def test_inverse_kilometers(point, dir, dist, result):
assert isclose(inverse_haversine(point, dist, dir), result, rtol=1e-5).all()
assert isclose(inverse_haversine(point, dist, dir),
result, rtol=1e-5).all()


@pytest.mark.parametrize(
Expand All @@ -36,8 +38,10 @@ def test_back_and_forth(point, direction, distance, unit):


def test_inverse_miles():
assert isclose(inverse_haversine(PARIS, 50, Direction.NORTH, unit=Unit.MILES), (49.5803579218996, 2.3508), rtol=1e-5).all()
assert isclose(inverse_haversine(PARIS, 50, Direction.NORTH,
unit=Unit.MILES), (49.5803579218996, 2.3508), rtol=1e-5).all()


def test_nautical_inverse_miles():
assert isclose(inverse_haversine(PARIS, 10, Direction.SOUTH, unit=Unit.NAUTICAL_MILES), (48.69014586638915, 2.3508), rtol=1e-5).all()
assert isclose(inverse_haversine(PARIS, 10, Direction.SOUTH,
unit=Unit.NAUTICAL_MILES), (48.69014586638915, 2.3508), rtol=1e-5).all()

0 comments on commit e71ddf4

Please sign in to comment.