diff --git a/siphon/simplewebservice/ndbc.py b/siphon/simplewebservice/ndbc.py index 5123180e5..df043724e 100644 --- a/siphon/simplewebservice/ndbc.py +++ b/siphon/simplewebservice/ndbc.py @@ -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) @@ -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', diff --git a/siphon/tests/test_ndbc.py b/siphon/tests/test_ndbc.py index fb3f5b5ff..f53c5ebe8 100644 --- a/siphon/tests/test_ndbc.py +++ b/siphon/tests/test_ndbc.py @@ -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 @@ -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') \ No newline at end of file