Skip to content

Commit

Permalink
Add datatype checking on realtime and test
Browse files Browse the repository at this point in the history
  • Loading branch information
jrleeman committed Aug 3, 2018
1 parent 266e724 commit a5dcdb4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
7 changes: 5 additions & 2 deletions siphon/simplewebservice/ndbc.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,11 @@ def realtime_observations(cls, buoy, data_type='txt'):
'dart': endpoint._parse_dart,
'supl': endpoint._parse_supl,
'rain': endpoint._parse_rain}
endpoint = cls()

if data_type not in parsers:
raise KeyError('Data type must be txt, drift, cwind, spec, ocean, srad, dart,'
'supl, or rain for parsed realtime data.')

raw_data = endpoint.raw_buoy_data(buoy, data_type=data_type)
return parsers[data_type](raw_data)

Expand All @@ -76,7 +80,6 @@ def _parse_met(content):
:class:`pandas.DataFrame` containing the data
"""
widths = [4, 2, 2, 2, 2, 3, 4, 4, 5, 5, 5, 3, 6, 5, 5, 5, 4, 4, 5]
col_names = ['year', 'month', 'day', 'hour', 'minute',
'wind_direction', 'wind_speed', 'wind_gust',
'wave_height', 'dominant_wave_period', 'average_wave_period',
Expand Down
7 changes: 7 additions & 0 deletions siphon/tests/test_ndbc.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import numpy as np
from numpy.testing import assert_almost_equal, assert_equal
import pytest

from siphon.simplewebservice.ndbc import NDBC
from siphon.testing import get_recorder
Expand Down Expand Up @@ -281,3 +282,9 @@ def test_ndbc_buoy_data_types():
'swr2': 'spectral wave data (r2)',
'supl': 'supplemental measurements data'}
assert(resp == truth)


def test_ndbc_realtime_keyerror():
"""Ensure an error is raised for invalid parsed data type requests."""
with pytest.raises(KeyError):
NDBC.realtime_observations('41002', data_type='dartt')

0 comments on commit a5dcdb4

Please sign in to comment.