Skip to content

Commit

Permalink
Merge pull request #26 from adamabernathy/master
Browse files Browse the repository at this point in the history
Handles empty API responses safely. Closes #25
  • Loading branch information
adamabernathy authored Dec 18, 2017
2 parents fd1b006 + 3663725 commit ab02b5a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
2 changes: 2 additions & 0 deletions MesoPy.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ def _checkresponse(response):
if response['SUMMARY']['RESPONSE_CODE'] == 1:
return response
elif response['SUMMARY']['RESPONSE_CODE'] == 2:
if response['SUMMARY']['NUMBER_OF_OBJECTS'] == 0:
return None
raise MesoPyError(results_error)
elif response['SUMMARY']['RESPONSE_CODE'] == 200:
raise MesoPyError(auth_error)
Expand Down
21 changes: 11 additions & 10 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
from distutils.core import setup

setup(
name='MesoPy',
py_modules=['MesoPy'],
version='2.0.2',
description='A pure python wrapper for the MesoWest API',
author='Josh Clark',
author_email='[email protected]',
url='https://github.com/mesowx/MesoPy',
download_url='https://github.com/mesowx/MesoPy/tarball/2.0.2',
keywords=['weather API climate MesoWest meteorology'],
classifiers=[], requires=[]
name='MesoPy',
py_modules=['MesoPy'],
version='2.0.3',
description='A Python wrapper for the MesoWest environmental data',
author='Mesowest/SynopticLabs',
author_email='[email protected]',
url='https://github.com/mesowx/MesoPy',
download_url='https://github.com/mesowx/MesoPy/tarball/2.0.2',
keywords=['weather API climate MesoWest meteorology'],
classifiers=[],
requires=[],
)
5 changes: 5 additions & 0 deletions tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ def testlateststrlist():
print(latest)
eq_(len(latest['STATION']), 3)

def testnostationsfound():
result = m.precip(stid='CDDT2', start='201712131200', end='201712141200')
print(result)
eq_(result, None)

# Error Handling
@raises(MesoPyError)
def testbadurlstring():
Expand Down

0 comments on commit ab02b5a

Please sign in to comment.