Skip to content

Commit

Permalink
geopy.exc: extend more specific built-in exceptions where appropriate (
Browse files Browse the repository at this point in the history
  • Loading branch information
KostyaEsmukov committed Apr 10, 2021
1 parent 40ff460 commit 527a173
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
12 changes: 6 additions & 6 deletions geopy/exc.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class GeopyError(Exception):
"""


class ConfigurationError(GeopyError):
class ConfigurationError(GeopyError, ValueError):
"""
When instantiating a geocoder, the arguments given were invalid. See
the documentation of each geocoder's ``__init__`` for more details.
Expand All @@ -27,7 +27,7 @@ class GeocoderServiceError(GeopyError):
"""


class GeocoderQueryError(GeocoderServiceError):
class GeocoderQueryError(GeocoderServiceError, ValueError):
"""
Either geopy detected input that would cause a request to fail,
or a request was made and the remote geocoding service responded
Expand All @@ -42,7 +42,7 @@ class GeocoderQuotaExceeded(GeocoderServiceError):
"""


class GeocoderRateLimited(GeocoderQuotaExceeded):
class GeocoderRateLimited(GeocoderQuotaExceeded, IOError):
"""
The remote geocoding service has rate-limited the request.
Retrying later might help.
Expand Down Expand Up @@ -74,7 +74,7 @@ class GeocoderInsufficientPrivileges(GeocoderServiceError):
"""


class GeocoderTimedOut(GeocoderServiceError):
class GeocoderTimedOut(GeocoderServiceError, TimeoutError):
"""
The call to the geocoding service was aborted because no response
has been received within the ``timeout`` argument of either
Expand All @@ -84,7 +84,7 @@ class GeocoderTimedOut(GeocoderServiceError):
"""


class GeocoderUnavailable(GeocoderServiceError):
class GeocoderUnavailable(GeocoderServiceError, IOError):
"""
Either it was not possible to establish a connection to the remote
geocoding service, or the service responded with a code indicating
Expand All @@ -99,7 +99,7 @@ class GeocoderParseError(GeocoderServiceError):
"""


class GeocoderNotFound(GeopyError):
class GeocoderNotFound(GeopyError, ValueError):
"""
Caller requested the geocoder matching a string, e.g.,
``"google"`` > ``GoogleV3``, but no geocoder could be found.
Expand Down
20 changes: 20 additions & 0 deletions test/test_exc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import inspect

import pytest

import geopy.exc

error_classes = sorted(
[
v
for v in (getattr(geopy.exc, name) for name in dir(geopy.exc))
if inspect.isclass(v) and issubclass(v, geopy.exc.GeopyError)
],
key=lambda cls: cls.__name__,
)


@pytest.mark.parametrize("error_cls", error_classes)
def test_init(error_cls):
with pytest.raises(error_cls):
raise error_cls("dummy")

0 comments on commit 527a173

Please sign in to comment.