def test_current_get_reading_key_error(): current = BrazilianCurrentWeatherService() current._update_readings( "<?xml version='1.0' encoding='ISO-8859-1'?><metar><codigo>SBAR</codigo><atualizacao>07/04/2019 13:00:00</atualizacao><pressao>1014</pressao><temperatura>29</temperatura><tempo>pn</tempo><tempo_desc>Parcialmente Nublado</tempo_desc><umidade>62</umidade><vento_dir>110</vento_dir><vento_int>20</vento_int><visibilidade>>10000</visibilidade></metar>" ) with pytest.raises(KeyError): assert current.get_reading('temperatura')
def test_current_station_condition(): try: sbar_station_current_conditions = Station('SBAR').set_weather_service( BrazilianCurrentWeatherService()).get_current_conditions() assert sbar_station_current_conditions.get_reading( 'station_code') == 'SBAR' except ConnectionError: pass
def test_current_get_reading(): current = BrazilianCurrentWeatherService() current._update_readings( "<?xml version='1.0' encoding='ISO-8859-1'?><metar><codigo>SBAR</codigo><atualizacao>07/04/2019 13:00:00</atualizacao><pressao>1014</pressao><temperatura>29</temperatura><tempo>pn</tempo><tempo_desc>Parcialmente Nublado</tempo_desc><umidade>62</umidade><vento_dir>110</vento_dir><vento_int>20</vento_int><visibilidade>>10000</visibilidade></metar>" ) assert current.get_reading( 'temperature') == current._conditions['temperatura'] assert current.get_reading('weather') == current._conditions['tempo'] assert current.get_reading('pressure') == current._conditions['pressao']
def test_current_station_url_symbol(): sbar_station_current_conditions = Station('SBAR').set_weather_service( BrazilianCurrentWeatherService()) sbar_station_current_conditions.weather_service._update_readings( "<?xml version='1.0' encoding='ISO-8859-1'?><metar><codigo>SBAR</codigo><atualizacao>07/04/2019 13:00:00</atualizacao><pressao>1014</pressao><temperatura>29</temperatura><tempo>pc</tempo><tempo_desc>Parcialmente Nublado</tempo_desc><umidade>62</umidade><vento_dir>110</vento_dir><vento_int>20</vento_int><visibilidade>>10000</visibilidade></metar>" ) assert sbar_station_current_conditions.weather_service.get_reading( 'station_code') == 'SBAR' try: url = sbar_station_current_conditions.get_current_symbol_url() filename = url[url.rfind('/') + 1:] assert 'pc' in filename except ConnectionError: pass
def __init__(self, async_session): self.async_session = async_session BrazilianCurrentWeatherService.__init__(self)
def test_get_current_conditions_status_code_not_200(): current = BrazilianCurrentWeatherService() try: assert not current.get_current_conditions('SBA9') except ConnectionError: pass
def load_current(lat, lon): return Station(coordenate=(lat, lon)).set_weather_service( BrazilianCurrentWeatherService()).get_current_conditions()