def test_unit(self): for i, value in enumerate([ 'm', 'm', 'm', 'm', 'sm', 'sm', 'sm', 'sm', 'sm', 'sm', 'sm', 'sm', 'sm', 'sm', 'sm' ]): report = Metar.Report(REPORTS[i]) self.assertEqual(report.get_visibility_distance_unit(), value)
def test_distance(self): for i, value in enumerate([ 10000, 9999, 8000, 9000, 10, 4, 0, -8, -10, 5, -5, 0.5, 2.25, -0.75, -2.25 ]): report = Metar.Report(REPORTS[i]) self.assertEqual(report.get_visibility_distance(), value)
def test_converted_distance(self): for i, value in enumerate([ 10000, 9999, 8000, 9000, 18520, 7408, 0, 14816, 18520, 9260, 9260, 926, 4167, 1389, 4167 ]): report = Metar.Report(REPORTS[i]) self.assertEqual(report.get_visibility_distance_m(), value)
def test_distance_str(self): for i, value in enumerate([ 'CAVOK', '9999 m', '8000 m', '9000 m', '10 sm', '4 sm', '0 sm', '< 8 sm', '< 10 sm', '5 sm', '< 5 sm', '1/2 sm', '2 1/4 sm', '< 3/4 sm', '< 2 1/4 sm' ]): report = Metar.Report(REPORTS[i]) self.assertEqual(report.get_visibility_distance_str(), value)
def test_iso(self): for i, value in enumerate([ YEAR_MONTH + '02T08:25:00+00:00', YEAR_MONTH + '02T09:45:00+00:00', YEAR_MONTH + '13T12:56:00+00:00', ]): report = Metar.Report(REPORTS[i]) self.assertEqual(report.get_reported(), value)
def test_date(self): for i, value in enumerate([ YEAR_MONTH + '02', YEAR_MONTH + '02', YEAR_MONTH + '13', ]): report = Metar.Report(REPORTS[i]) self.assertEqual(report.get_date(), value)
def test_converted_wind_gust(self): for i, value in enumerate([None, 10.8, None, None, None, 18]): report = Metar.Report(REPORTS[i]) if report.get_wind_gust_ms(): self.assertEqual(round(report.get_wind_gust_ms(), 2), value) else: self.assertEqual(report.get_wind_gust_ms(), value)
def test_converted_wind_speed(self): for i, value in enumerate([11.32, 5.14, 3.09, 4, 1, 9]): report = Metar.Report(REPORTS[i]) # Make sure returned value is a number that can be rounded if report.get_wind_speed_ms(): self.assertEqual(round(report.get_wind_speed_ms(), 2), value) else: self.assertEqual(report.get_wind_speed_ms(), value)
def test_converted(self): for i, value in enumerate([100200, 101440.57, 102200, 98975.47]): report = Metar.Report(REPORTS[i]) if report.get_altimeter_pressure_pa(): self.assertEqual(round(report.get_altimeter_pressure_pa(), 2), value) else: self.assertEqual(report.get_altimeter_pressure_pa(), value)
def test_speed_unit(self): for i, value in enumerate(['kt', 'kt', 'kt', 'mps', 'mps', 'mps']): report = Metar.Report(REPORTS[i]) self.assertEqual(report.get_wind_speed_unit(), value)
def test_time(self): for i, value in enumerate(['08:25', '09:45', '12:56']): report = Metar.Report(REPORTS[i]) self.assertEqual(report.get_time(), value)
def test_value(self): for i, value in enumerate([1002, 30.04, 1022, 29.31]): report = Metar.Report(REPORTS[i]) self.assertEqual(report.get_altimeter_pressure(), value)
def test_unit(self): for i, value in enumerate(['hPa', 'inHg', 'hPa', 'inHg']): report = Metar.Report(REPORTS[i]) self.assertEqual(report.get_altimeter_pressure_unit(), value)
def test_temperature(self): for i, value in enumerate([17, 2, 18, -4, -9, -16]): report = Metar.Report(REPORTS[i]) self.assertEqual(report.get_temperature(), value)
def test_ident(self): for i, ident in enumerate(['EHAM', 'K2W6', 'KIAB', 'PHOG']): report = Metar.Report(REPORTS[i]) self.assertEqual(report.get_ident(), ident)
def test_speed(self): for i, value in enumerate([22, 10, 6, 4, 1, 9]): report = Metar.Report(REPORTS[i]) self.assertEqual(report.get_wind_speed(), value)
def test_direction(self): for i, value in enumerate([210, 250, 80, 80, 'VRB', 'VRB']): report = Metar.Report(REPORTS[i]) self.assertEqual(report.get_wind_direction(), value)
from metar_parser import Metar reports = [ "EHAM 020825Z 21022KT 190V250 9999 FEW008 SCT018 BKN022 17/15 Q1002 NOSIG", "EGPK 020920Z 25010G21KT 8000 -RA FEW014 SCT020 BKN042 09/08 Q0991", "PAUN 131256Z AUTO 08006KT 10SM SCT021 M04/M05 A2931 RMK AO2 SNE15 SLP927 P0000 T10391050 FZRANO", ] report = Metar.Report(reports[0]) if report.is_parsed: print(report.json(pretty=True)) print('--------') report = Metar.Report(reports[1]) if report.is_parsed: visibility = report.visibility() print(report.get_raw()) print('Visibility: {} {}'.format(visibility['distance'], visibility['distance_unit'])) print('--------') report = Metar.Report(reports[2]) if report.is_parsed: temps = report.temperatures() print(report.get_raw()) print('Temperature: {}°C'.format(temps['temperature'])) print('Dew point: {}°C'.format(temps['dew_point']))
def test_report_modifier(self): for i, ident in enumerate([None, 'AUTO', 'COR', 'COR']): report = Metar.Report(REPORTS[i]) self.assertEqual(report.get_report_modifier(), ident)
def test_wind_gust(self): for i, value in enumerate([None, 21, None, None, None, 18]): report = Metar.Report(REPORTS[i]) self.assertEqual(report.get_wind_gust(), value)
def test_dew_point(self): for i, value in enumerate([15, -5, -4, -5, -13, -18]): report = Metar.Report(REPORTS[i]) self.assertEqual(report.get_dew_point(), value)
def test_wind_variable_directions(self): for i, value in enumerate([[190, 250], None, None, None, None, None]): report = Metar.Report(REPORTS[i]) self.assertEqual(report.get_wind_variable_directions(), value)