Skip to content

Commit

Permalink
Distance class: remove abc (closes #435)
Browse files Browse the repository at this point in the history
Fixes undocumented backwards-incompatible change in geopy 2
  • Loading branch information
KostyaEsmukov committed Aug 21, 2020
1 parent 2073170 commit ea9492c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 16 deletions.
6 changes: 2 additions & 4 deletions geopy/distance.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@
would result in a ``ValueError`` exception.
"""
import abc
from math import asin, atan2, cos, sin, sqrt

from geographiclib.geodesic import Geodesic
Expand Down Expand Up @@ -187,7 +186,7 @@ def _ensure_same_altitude(a, b):
# it won't give much error.


class Distance(abc.ABC):
class Distance:

def __init__(self, *args, **kwargs):
kilometers = kwargs.pop('kilometers', 0)
Expand Down Expand Up @@ -236,9 +235,8 @@ def __nonzero__(self):

__bool__ = __nonzero__

@abc.abstractmethod
def measure(self, a, b):
raise NotImplementedError()
raise NotImplementedError("Distance is an abstract class")

def __repr__(self): # pragma: no cover
return 'Distance(%s)' % self.kilometers
Expand Down
22 changes: 10 additions & 12 deletions test/test_distance.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,11 @@ def test_should_warn_for_mixed_up_lat_lon(self):
self.cls((lon, lat), (lon - 10, lat))
self.assertEqual(1, len(w))

def test_should_get_consistent_results_for_distance_calculations(self):
distance1, distance2 = [self.cls((0, 0), (0, 1))
for _ in range(2)]
self.assertEqual(distance1.kilometers, distance2.kilometers)


class CommonMathematicalOperatorCases:

Expand Down Expand Up @@ -164,11 +169,6 @@ def test_should_be_true_in_boolean_context_when_nonzero_length(self):
def test_should_be_false_in_boolean_context_when_zero_length(self):
self.assertFalse(self.cls(0))

def test_should_get_consistent_results_for_distance_calculations(self):
distance1, distance2 = [self.cls((0, 0), (0, 1))
for _ in range(2)]
self.assertEqual(distance1.kilometers, distance2.kilometers)


class CommonConversionCases:

Expand Down Expand Up @@ -259,13 +259,11 @@ class CommonDistanceCases(CommonDistanceComputationCases,
pass


class TestWhenInstantiatingBaseDistanceClass(unittest.TestCase):
def test_should_not_be_able_to_instantiate(self):
with self.assertRaises(TypeError):
Distance((0, 0), (0, 180))


class TestDefaultDistanceClass(unittest.TestCase):
class TestDefaultDistanceClass(CommonMathematicalOperatorCases,
CommonConversionCases,
CommonComparisonCases,
unittest.TestCase):
cls = Distance

def test_default_distance(self):
self.assertEqual(distance(132).km, 132)
Expand Down

0 comments on commit ea9492c

Please sign in to comment.