def test_observations_parser_handles_ignored_values(data_dir): p = WindObservationsParser(path=data_dir / 'observations_recent_FF_akt.zip') p.ignored_values = {'wind_direction': ['80']} records = list(p.parse()) assert records[0]['wind_direction'] is None assert records[0]['wind_speed'] == 1.6
def test_observations_parser_handles_location_changes(data_dir): p = WindObservationsParser( path=data_dir / 'observations_recent_FF_location_change_akt.zip') records = list(p.parse()) assert is_subset( {'lat': 48.8275, 'lon': 12.5597, 'height': 350.5}, records[0]) assert is_subset( {'lat': 50.0, 'lon': 13.0, 'height': 345.0}, records[-1])
def test_observations_parser_skips_rows_if_before_cutoff(data_dir): p = WindObservationsParser( path=data_dir / 'observations_recent_FF_akt.zip') with settings( MIN_DATE=datetime.datetime(2019, 1, 1, tzinfo=tzutc()), ): records = list(p.parse()) assert len(records) == 5 assert records[0]['timestamp'] == datetime.datetime( 2019, 4, 20, 21, tzinfo=tzutc()) with settings( MAX_DATE=datetime.datetime(2019, 1, 1, tzinfo=tzutc()), ): records = list(p.parse()) assert len(records) == 5 assert records[-1]['timestamp'] == datetime.datetime( 2018, 9, 15, 4, tzinfo=tzutc())
def test_observations_parser_parses_metadata(data_dir): p = WindObservationsParser( path=data_dir / 'observations_recent_FF_akt.zip') metadata = { 'observation_type': 'historical', 'source': ( 'Observations:Recent:produkt_ff_stunde_20180915_20200317_04911.txt' ), 'lat': 48.8275, 'lon': 12.5597, 'height': 350.5, 'dwd_station_id': '04911', 'wmo_station_id': '10788', 'station_name': 'Straubing', } for record in p.parse(): assert is_subset(metadata, record)
def test_observations_parser_handles_missing_values(data_dir): p = WindObservationsParser(path=data_dir / 'observations_recent_FF_akt.zip') records = list(p.parse()) assert records[5]['wind_direction'] == 90 assert records[5]['wind_speed'] is None