コード例 #1
0
 def test_taf_line(self):
     """
     Tests converting TAF line data into into a single spoken string
     """
     units = structs.Units(**static.NA_UNITS)
     line = {
         'altimeter': core.make_number('2992'),
         'clouds': [core.make_cloud('BKN015CB')],
         'end_time': core.make_timestamp('1206'),
         'icing': ['611005'],
         'other': ['+RA'],
         'start_time': core.make_timestamp('1202'),
         'turbulance': ['540553'],
         'type': 'FROM',
         'visibility': core.make_number('3'),
         'wind_direction': core.make_number('360'),
         'wind_gust': core.make_number('20'),
         'wind_shear': 'WS020/07040KT',
         'wind_speed': core.make_number('12'),
     }
     line.update({
         k: None
         for k in ('flight_rules', 'probability', 'raw', 'sanitized')
     })
     line = structs.TafLineData(**line)
     spoken = (
         'From 2 to 6 zulu, Winds three six zero at 12kt gusting to 20kt. '
         'Wind shear 2000inHg from zero seven zero at 40kt. Visibility three miles. '
         'Altimeter two nine point nine two. Heavy Rain. '
         'Broken layer at 1500ft (Cumulonimbus). '
         'Occasional moderate turbulence in clouds from 5500ft to 8500ft. '
         'Light icing from 10000ft to 15000ft')
     ret = speech.taf_line(line, units)
     self.assertIsInstance(ret, str)
     self.assertEqual(ret, spoken)
コード例 #2
0
 def test_get_wind(self):
     """
     Tests that the wind item gets removed and split into its components
     """
     # Both us knots as the default unit, so just test North American default
     for wx, unit, *wind, varv in ((['1'
                                     ], 'kt', (None, ), (None, ), (None, ),
                                    []), (['12345(E)', 'G50',
                                           '1'], 'kt', ('123', 123),
                                          ('45', 45), ('50', 50), []),
                                   (['O1234G56', '1'], 'kt', ('012', 12),
                                    ('34', 34), ('56', 56), []),
                                   (['36010KTS', 'G20', '300V060',
                                     '1'], 'kt', ('360', 360), ('10', 10),
                                    ('20', 20), [
                                        ('300', 300), ('060', 60)
                                    ]), (['VRB10MPS', '1'], 'm/s',
                                         ('VRB', ), ('10', 10), (None, ),
                                         []), (['VRB20G30KMH',
                                                '1'], 'km/h', ('VRB', ),
                                               ('20', 20), ('30', 30), [])):
         units = structs.Units(**static.NA_UNITS)
         wx, *winds, var = core.get_wind(wx, units)
         self.assertEqual(wx, ['1'])
         for i in range(len(wind)):
             self.assert_number(winds[i], *wind[i])
         if varv:
             self.assertIsInstance(varv, list)
             for i in range(2):
                 self.assert_number(var[i], *varv[i])
         self.assertEqual(units.wind_speed, unit)
コード例 #3
0
 def test_taf(self):
     """
     Tests end-to-end TAF translation
     """
     units = structs.Units(**static.NA_UNITS)
     line_data = {
         'altimeter': core.make_number('2992'),
         'clouds': [core.make_cloud('BKN015CB')],
         'icing': ['611005'],
         'other': ['+RA'],
         'turbulance': ['540553'],
         'visibility': core.make_number('3'),
         'wind_direction': core.make_number('360'),
         'wind_gust': core.make_number('20'),
         'wind_shear': 'WS020/07040KT',
         'wind_speed': core.make_number('12')
     }
     line_data.update({
         k: ''
         for k in ('raw', 'end_time', 'start_time', 'probability', 'type',
                   'flight_rules', 'sanitized')
     })
     data = {'max_temp': 'TX20/1518Z', 'min_temp': 'TN00/00', 'remarks': ''}
     data.update({
         k: ''
         for k in ('raw', 'station', 'time', 'start_time', 'end_time')
     })
     data = structs.TafData(forecast=[structs.TafLineData(**line_data)],
                            **data)
     # noinspection PyArgumentList
     line_trans = structs.TafLineTrans(
         altimeter='29.92 inHg (1013 hPa)',
         clouds='Broken layer at 1500ft (Cumulonimbus) - Reported AGL',
         icing='Light icing from 10000ft to 15000ft',
         other='Heavy Rain',
         turbulance=
         'Occasional moderate turbulence in clouds from 5500ft to 8500ft',
         visibility='3sm (4.8km)',
         wind_shear='Wind shear 2000ft from 070 at 40kt',
         wind='N-360 at 12kt gusting to 20kt')
     trans = structs.TafTrans(
         forecast=[line_trans],
         max_temp='Maximum temperature of 20°C (68°F) at 15-18:00Z',
         min_temp='Minimum temperature of 0°C (32°F) at 00:00Z',
         remarks={})
     translated = translate.taf(data, units)
     self.assertIsInstance(translated, structs.TafTrans)
     for line in translated.forecast:
         self.assertIsInstance(line, structs.TafLineTrans)
     self.assertEqual(translated, trans)
コード例 #4
0
 def test_taf(self):
     """
     Tests converting a TafData report into a single spoken string
     """
     units = structs.Units(**static.NA_UNITS)
     # noinspection PyUnresolvedReferences
     empty_line = {
         k: None
         for k in structs.TafLineData.__dataclass_fields__.keys()
     }
     forecast = [
         structs.TafLineData(**{
             **empty_line,
             **line
         }) for line in (
             {
                 'type': 'FROM',
                 'start_time': core.make_timestamp('0410Z'),
                 'end_time': core.make_timestamp('0414Z'),
                 'visibility': core.make_number('3'),
                 'wind_direction': core.make_number('360'),
                 'wind_gust': core.make_number('20'),
                 'wind_speed': core.make_number('12'),
             },
             {
                 'type': 'PROB',
                 'probability': core.make_number('45'),
                 'start_time': core.make_timestamp('0412Z'),
                 'end_time': core.make_timestamp('0414Z'),
                 'visibility': core.make_number('M1/4'),
             },
         )
     ]
     # noinspection PyArgumentList
     taf = structs.TafData(raw=None,
                           remarks=None,
                           station=None,
                           time=None,
                           forecast=forecast,
                           start_time=core.make_timestamp('0410Z'),
                           end_time=core.make_timestamp('0414Z'))
     ret = speech.taf(taf, units)
     spoken = (
         "Starting on .* 4th - From 10 to 14 zulu, "
         "Winds three six zero at 12kt gusting to 20kt. Visibility three miles. "
         r"From 12 to 14 zulu, there's a 45% chance for Visibility "
         "less than one quarter of a mile")
     self.assertIsInstance(ret, str)
     assert re.match(spoken, ret)
コード例 #5
0
 def test_get_altimeter(self):
     """
     Tests that the correct alimeter item gets removed from the end of the wx list
     """
     # North American default
     units = structs.Units(**static.NA_UNITS)
     for wx, alt in (
         (['1', '2'], (None, )),
         (['1', '2', 'A2992'], ('2992', 29.92)),
         (['1', '2', '2992'], ('2992', 29.92)),
         (['1', '2', 'A2992', 'Q1000'], ('2992', 29.92)),
         (['1', '2', 'Q1000', 'A2992'], ('2992', 29.92)),
         (['1', '2', 'Q1000'], ('1000', 1000)),
     ):
         self.assertEqual(units.altimeter, 'inHg')
         retwx, ret_alt = core.get_altimeter(wx, units)
         self.assertEqual(retwx, ['1', '2'])
         self.assert_number(ret_alt, *alt)
     # The last one should have changed the unit
     self.assertEqual(units.altimeter, 'hPa')
     # International
     units = structs.Units(**static.IN_UNITS)
     for wx, alt in (
         (['1', '2'], (None, )),
         (['1', '2', 'Q.1000'], ('1000', 1000)),
         (['1', '2', 'Q1000/10'], ('1000', 1000)),
         (['1', '2', 'A2992', 'Q1000'], ('1000', 1000)),
         (['1', '2', 'Q1000', 'A2992'], ('1000', 1000)),
         (['1', '2', 'A2992'], ('2992', 29.92)),
     ):
         self.assertEqual(units.altimeter, 'hPa')
         retwx, ret_alt = core.get_altimeter(wx, units, 'IN')
         self.assertEqual(retwx, ['1', '2'])
         self.assert_number(ret_alt, *alt)
     # The last one should have changed the unit
     self.assertEqual(units.altimeter, 'inHg')
コード例 #6
0
def test_shared():
    units = structs.Units(**static.NA_UNITS)
    data = structs.SharedData(altimeter=core.make_number('2992'),
                              clouds=[core.make_cloud('OVC060')],
                              flight_rules='',
                              other=['RA'],
                              sanitized='',
                              visibility=core.make_number('10'),
                              wind_direction=core.make_number('0'),
                              wind_gust=core.make_number('0'),
                              wind_speed=core.make_number('0'))
    # noinspection PyTypeChecker
    trans = translate.shared(data, units)
    assert isinstance(trans, dict)
    for key in ('altimeter', 'clouds', 'other', 'visibility'):
        assert key in trans
        assert trans[key]
コード例 #7
0
 def test_metar(self):
     """
     Tests end-to-end METAR translation
     """
     units = structs.Units(**static.NA_UNITS)
     data = {
         'altimeter':
         core.make_number('2992'),
         'clouds': [core.make_cloud('BKN015CB')],
         'dewpoint':
         core.make_number('M01'),
         'other': ['+RA'],
         'temperature':
         core.make_number('03'),
         'visibility':
         core.make_number('3'),
         'wind_direction':
         core.make_number('360'),
         'wind_gust':
         core.make_number('20'),
         'wind_speed':
         core.make_number('12'),
         'wind_variable_direction':
         [core.make_number('340'),
          core.make_number('020')]
     }
     data.update({
         k: ''
         for k in ('raw', 'remarks', 'station', 'time', 'flight_rules',
                   'remarks_info', 'runway_visibility', 'sanitized')
     })
     data = structs.MetarData(**data)
     # noinspection PyArgumentList
     trans = structs.MetarTrans(
         altimeter='29.92 inHg (1013 hPa)',
         clouds='Broken layer at 1500ft (Cumulonimbus) - Reported AGL',
         dewpoint='-1°C (30°F)',
         other='Heavy Rain',
         remarks={},
         temperature='3°C (37°F)',
         visibility='3sm (4.8km)',
         wind='N-360 (variable 340 to 020) at 12kt gusting to 20kt')
     translated = translate.metar(data, units)
     self.assertIsInstance(translated, structs.MetarTrans)
     self.assertEqual(translated, trans)
コード例 #8
0
 def test_metar(self):
     """
     Tests converting METAR data into into a single spoken string
     """
     units = structs.Units(**static.NA_UNITS)
     data = {
         'altimeter':
         core.make_number('2992'),
         'clouds': [core.make_cloud('BKN015CB')],
         'dewpoint':
         core.make_number('M01'),
         'other': ['+RA'],
         'temperature':
         core.make_number('03'),
         'visibility':
         core.make_number('3'),
         'wind_direction':
         core.make_number('360'),
         'wind_gust':
         core.make_number('20'),
         'wind_speed':
         core.make_number('12'),
         'wind_variable_direction':
         [core.make_number('340'),
          core.make_number('020', speak='020')]
     }
     data.update({
         k: None
         for k in ('raw', 'remarks', 'station', 'time', 'flight_rules',
                   'remarks_info', 'runway_visibility', 'sanitized')
     })
     data = structs.MetarData(**data)
     spoken = (
         'Winds three six zero (variable three four zero to zero two zero) '
         'at 12kt gusting to 20kt. Visibility three miles. '
         'Temperature three degrees Celsius. Dew point minus one degree Celsius. '
         'Altimeter two nine point nine two. Heavy Rain. '
         'Broken layer at 1500ft (Cumulonimbus)')
     ret = speech.metar(data, units)
     self.assertIsInstance(ret, str)
     self.assertEqual(ret, spoken)
コード例 #9
0
 def test_get_visibility(self):
     """
     Tests that the visibility item(s) gets removed and cleaned
     """
     for wx, unit, visibility in (
         (['1'], 'sm', (None, )),
         (['05SM', '1'], 'sm', ('5', 5)),
         (['10SM', '1'], 'sm', ('10', 10)),
         (['P6SM', '1'], 'sm', ('P6', )),
         (['M1/4SM', '1'], 'sm', ('M1/4', )),
         (['1/2SM', '1'], 'sm', ('1/2', 0.5)),
         (['2', '1/2SM', '1'], 'sm', ('5/2', 2.5)),
         (['1000', '1'], 'm', ('1000', 1000)),
         (['1000E', '1'], 'm', ('1000', 1000)),
         (['1000NDV', '1'], 'm', ('1000', 1000)),
         (['M1000', '1'], 'm', ('1000', 1000)),
         (['2KM', '1'], 'm', ('2000', 2000)),
     ):
         units = structs.Units(**static.NA_UNITS)
         wx, vis = core.get_visibility(wx, units)
         self.assertEqual(wx, ['1'])
         self.assert_number(vis, *visibility)
         self.assertEqual(units.visibility, unit)