Skip to content

Commit

Permalink
Geonames test: skip test on empty result instead of failing
Browse files Browse the repository at this point in the history
The service started to return empty results lately when running
Travis pipelines. Perhaps the requests rate is too high? Skip such
tests instead of failing the pipelines.
  • Loading branch information
KostyaEsmukov committed Jul 5, 2018
1 parent eb8eeb5 commit 0654fa9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
4 changes: 3 additions & 1 deletion test/geocoders/geonames.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,14 @@ def test_unicode_name(self):
self.geocode_run(
{"query": "Mount Everest, Nepal"},
{"latitude": 27.987, "longitude": 86.925},
skiptest_on_failure=True, # sometimes the result is empty
)

def test_query_urlencoding(self):
location = self.geocode_run(
{"query": u("Ry\u016b\u014d")},
{"latitude": 35.65, "longitude": 138.5}
{"latitude": 35.65, "longitude": 138.5},
skiptest_on_failure=True, # sometimes the result is empty
)
self.assertIn(u("Ry\u016b\u014d"), location.address)

Expand Down
24 changes: 16 additions & 8 deletions test/geocoders/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,30 +63,38 @@ def tearDown(self):
except AttributeError:
pass

def geocode_run(self, payload, expected, expect_failure=False):
def geocode_run(self, payload, expected, expect_failure=False,
skiptest_on_failure=False):
"""
Calls geocoder.geocode(**payload), then checks against `expected`.
"""
result = self._make_request(self.geocoder.geocode, **payload)
if result is None:
if not expect_failure:
self.fail('No result found')
else:
cls = type(self)
if expect_failure:
return
elif skiptest_on_failure:
self.skipTest('%s: Skipping test due to empty result' % cls.__name__)
else:
self.fail('%s: No result found' % cls.__name__)
self._verify_request(result, exactly_one=payload.get('exactly_one', True),
**expected)
return result

def reverse_run(self, payload, expected, expect_failure=False):
def reverse_run(self, payload, expected, expect_failure=False,
skiptest_on_failure=False):
"""
Calls geocoder.reverse(**payload), then checks against `expected`.
"""
result = self._make_request(self.geocoder.reverse, **payload)
if result is None:
if not expect_failure:
self.fail('No result found')
else:
cls = type(self)
if expect_failure:
return
elif skiptest_on_failure:
self.skipTest('%s: Skipping test due to empty result' % cls.__name__)
else:
self.fail('%s: No result found' % cls.__name__)
self._verify_request(result, exactly_one=payload.get('exactly_one', True),
**expected)
return result
Expand Down

0 comments on commit 0654fa9

Please sign in to comment.