Beispiel #1
0
async def test_set_station(aiohttp_client, loop, urls):
    """Getting response succeeds"""
    app = aiohttp.web.Application()
    app.router.add_get("/obs", obs)
    app.router.add_get("/stations", stn)
    client = await aiohttp_client(app)
    snws = pynws.SimpleNWS(*LATLON, USERID, client)
    await snws.set_station("STN")
    assert snws.station == "STN"
    assert snws.stations == ["STN"]
    assert snws.nws.station == "STN"
    snws = pynws.SimpleNWS(*LATLON, USERID, client)
    await snws.set_station()
    assert snws.station == "STNA"
    assert snws.stations == ["STNA", "STNB", "STNC", "STND"]
    assert snws.nws.station == "STNA"
Beispiel #2
0
async def test_obs_strings(aiohttp_client, loop, urls):
    """No error when missing value."""
    app = aiohttp.web.Application()
    app.router.add_get("/obs", obs_strings)
    app.router.add_get("/stations", stn)
    app.router.add_get("/point", point)

    client = await aiohttp_client(app)
    snws = pynws.SimpleNWS(*LATLON, USERID, client)
    await snws.set_station("STN")
    await snws.update_observation()

    observation = snws.observation

    assert observation["temperature"] == float(10)
    assert observation["dewpoint"] == float(10)
    assert observation["relativeHumidity"] == float(10)
    assert observation["windDirection"] == float(10)
    assert observation["visibility"] == float(10000)
    assert observation["seaLevelPressure"] == float(100000)
    assert observation["windSpeed"] == float(10)
    assert observation["iconTime"] == "day"
    assert observation["windGust"] == float(10)
    assert observation["iconWeather"][0][0] == "A few clouds"
    assert observation["iconWeather"][0][1] is None
Beispiel #3
0
async def test_obs(aiohttp_client, loop, urls):
    """Getting response succeeds"""
    app = aiohttp.web.Application()
    app.router.add_get('/obs', obs)
    app.router.add_get('/stations', stn)
    app.router.add_get('/forecast', forc)
    client = await aiohttp_client(app)
    snws = pynws.SimpleNWS(*LATLON, USERID, MODE, client)
    await snws.set_station('STN')
    await snws.update_observation()

    observation = snws.observation
    assert observation['temperature'] == 10
    assert observation['dewpoint'] == 10
    assert observation['relativeHumidity'] == 10
    assert observation['windDirection'] == 10
    assert observation['visibility'] == 10000
    assert observation['seaLevelPressure'] == 100000
    assert observation['windSpeed'] == 10
    assert observation['iconTime'] == "day"
    assert observation['windGust'] == 10
    assert observation['iconWeather'][0][0] == "A few clouds"
    assert observation['iconWeather'][0][1] is None

    await snws.update_forecast()
    forecast = snws.forecast[0]
    assert forecast['iconWeather'][0][0] == "Thunderstorm (high cloud cover)"
    assert forecast['iconWeather'][0][1] == 40
    assert forecast['iconWeather'][1][0] == "Overcast"
    assert forecast['iconWeather'][1][1] is None
    assert forecast['windSpeedAvg'] == 10
    assert forecast['windBearing'] == 180
Beispiel #4
0
async def test_obs(aiohttp_client, loop, urls, obs_json):
    """Getting response succeeds"""
    app = aiohttp.web.Application()
    app.router.add_get("/obs", obs_json)
    app.router.add_get("/stations", stn)
    app.router.add_get("/point", point)
    app.router.add_get("/forecast", grid_forecast)
    client = await aiohttp_client(app)
    snws = pynws.SimpleNWS(*LATLON, USERID, client)
    await snws.set_station("STN")
    await snws.update_observation()

    observation = snws.observation
    assert observation["temperature"] == 10
    assert observation["dewpoint"] == 10
    assert observation["relativeHumidity"] == 10
    assert observation["windDirection"] == 10
    assert observation["visibility"] == 10000
    assert observation["seaLevelPressure"] == 100000
    assert observation["windSpeed"] == 10
    assert observation["iconTime"] == "day"
    assert observation["windGust"] == 10
    assert observation["iconWeather"][0][0] == "A few clouds"
    assert observation["iconWeather"][0][1] is None

    await snws.update_forecast()
    forecast = snws.forecast[0]
    assert forecast["iconWeather"][0][0] == "Thunderstorm (high cloud cover)"
    assert forecast["iconWeather"][0][1] == 40
    assert forecast["iconWeather"][1][0] == "Overcast"
    assert forecast["iconWeather"][1][1] is None
    assert forecast["windSpeedAvg"] == 10
    assert forecast["windBearing"] == 180
Beispiel #5
0
async def test_set_station(aiohttp_client, loop, urls):
    """Getting response succeeds"""
    app = aiohttp.web.Application()
    app.router.add_get('/obs', obs)
    app.router.add_get('/stations', stn)
    client = await aiohttp_client(app)
    snws = pynws.SimpleNWS(*LATLON, USERID, MODE, client)
    await snws.set_station('STN')
    assert snws.station == 'STN'
    assert snws.stations == ['STN']
    assert snws.nws.station == 'STN'
    snws = pynws.SimpleNWS(*LATLON, USERID, MODE, client)
    await snws.set_station()
    assert snws.station == 'STNA'
    assert snws.stations == ['STNA', 'STNB', 'STNC', 'STND']
    assert snws.nws.station == 'STNA'
Beispiel #6
0
async def example():
    async with aiohttp.ClientSession() as session:
        nws = pynws.SimpleNWS(*PHILLY, USERID, session)
        await nws.set_station()
        await nws.update_observation()
        await nws.update_forecast()
        await nws.update_alerts_forecast_zone()
        print(nws.observation)
        print(nws.forecast[0])
        print(nws.alerts_forecast_zone)
Beispiel #7
0
async def test_hourly_forecast(aiohttp_client, loop, urls):
    """Getting response succeeds"""
    app = aiohttp.web.Application()
    app.router.add_get('/obs', obs)
    app.router.add_get('/stations', stn)
    app.router.add_get('/forecast_hourly', forc_hourly)
    client = await aiohttp_client(app)
    snws = pynws.SimpleNWS(*LATLON, USERID, 'hourly', client)
    await snws.set_station('STN')
    await snws.update_forecast()
    assert snws.forecast
Beispiel #8
0
async def test_empty_fore(aiohttp_client, loop, urls):
    """Getting response succeeds"""
    app = aiohttp.web.Application()
    app.router.add_get("/obs", obs)
    app.router.add_get("/stations", stn)
    app.router.add_get("/point", point)
    app.router.add_get("/forecast", empty_fore)
    client = await aiohttp_client(app)
    snws = pynws.SimpleNWS(*LATLON, USERID, client)
    await snws.set_station("STN")
    await snws.update_forecast()
    assert snws.forecast
Beispiel #9
0
async def test_noparse_metar_obs(aiohttp_client, loop, urls):
    """Getting response succeeds"""
    app = aiohttp.web.Application()
    app.router.add_get('/obs', noparse_metar_obs)
    app.router.add_get('/stations', stn)
    app.router.add_get('/forecast', forc)
    client = await aiohttp_client(app)
    snws = pynws.SimpleNWS(*LATLON, USERID, MODE, client)
    await snws.set_station('STN')
    await snws.update_observation()

    observation = snws.observation
    assert observation['temperature'] is None
Beispiel #10
0
async def test_noparse_metar_obs(aiohttp_client, loop, urls):
    """Getting response succeeds"""
    app = aiohttp.web.Application()
    app.router.add_get("/obs", noparse_metar_obs)
    app.router.add_get("/stations", stn)
    app.router.add_get("/point", point)

    client = await aiohttp_client(app)
    snws = pynws.SimpleNWS(*LATLON, USERID, client)
    await snws.set_station("STN")
    await snws.update_observation()

    observation = snws.observation
    assert observation["temperature"] is None
Beispiel #11
0
async def test_forecast_strings(aiohttp_client, loop, urls):
    """Getting response succeeds"""
    app = aiohttp.web.Application()
    app.router.add_get("/point", point)
    app.router.add_get("/forecast", grid_forecast_strings)
    client = await aiohttp_client(app)
    snws = pynws.SimpleNWS(*LATLON, USERID, client)

    await snws.update_forecast()
    forecast = snws.forecast[0]
    assert forecast["temperature"] == 41
    assert forecast["iconWeather"][0][0] == "Thunderstorm (high cloud cover)"
    assert forecast["iconWeather"][0][1] == 40
    assert forecast["iconWeather"][1][0] == "Overcast"
    assert forecast["iconWeather"][1][1] is None
    assert forecast["windSpeedAvg"] == 10
    assert forecast["windBearing"] == 180
Beispiel #12
0
async def test_empty_obs(aiohttp_client, loop, urls):
    """Getting response succeeds"""
    app = aiohttp.web.Application()
    app.router.add_get('/obs', empty_obs)
    app.router.add_get('/stations', stn)
    app.router.add_get('/forecast', forc)
    client = await aiohttp_client(app)
    snws = pynws.SimpleNWS(*LATLON, USERID, MODE, client)
    await snws.set_station('STN')
    await snws.update_observation()

    observation = snws.observation
    assert observation['temperature'] is None
    assert observation['dewpoint'] is None
    assert observation['relativeHumidity'] is None
    assert observation['windDirection'] is None
    assert observation['visibility'] is None
    assert observation['seaLevelPressure'] is None
    assert observation['windSpeed'] is None
    assert observation['windGust'] is None
Beispiel #13
0
async def test_alerts_zone(aiohttp_client, loop, urls):
    """Getting response succeeds"""
    app = aiohttp.web.Application()
    app.router.add_get("/point", point)
    app.router.add_get("/alerts_zone", alerts_zone)
    client = await aiohttp_client(app)
    snws = pynws.SimpleNWS(*LATLON, USERID, client)

    await snws.update_pointdata()
    assert snws.forecast_zone == "FLZ015"
    assert snws.county_zone == "FLC037"
    assert snws.fire_weather_zone == "FLZ015"

    await snws.update_alerts_forecast_zone()
    assert snws.alerts_forecast_zone

    await snws.update_alerts_county_zone()
    assert snws.alerts_county_zone

    await snws.update_alerts_fire_weather_zone()
    assert snws.alerts_fire_weather_zone
Beispiel #14
0
async def test_metar_obs(aiohttp_client, loop, urls):
    """Getting response succeeds"""
    app = aiohttp.web.Application()
    app.router.add_get("/obs", metar_obs)
    app.router.add_get("/stations", stn)
    app.router.add_get("/point", point)

    client = await aiohttp_client(app)
    snws = pynws.SimpleNWS(*LATLON, USERID, client)
    await snws.set_station("STN")
    await snws.update_observation()

    observation = snws.observation
    assert observation["temperature"] == 25.6
    assert observation["dewpoint"] is None
    assert observation["relativeHumidity"] is None
    assert observation["windDirection"] == 350.0
    assert observation["visibility"] == 16093.44
    assert round(observation["seaLevelPressure"]) == 101761
    assert round(observation["windSpeed"], 2) == 2.57
    assert observation["windGust"] is None
Beispiel #15
0
async def test_obs_no_prop(aiohttp_client, loop, urls):
    """Getting response succeeds"""
    app = aiohttp.web.Application()
    app.router.add_get("/obs", obs_no_prop)
    app.router.add_get("/stations", stn)
    app.router.add_get("/point", point)

    client = await aiohttp_client(app)
    snws = pynws.SimpleNWS(*LATLON, USERID, client)
    await snws.set_station("STN")
    await snws.update_observation()

    observation = snws.observation

    assert observation["temperature"] is None
    assert observation["dewpoint"] is None
    assert observation["relativeHumidity"] is None
    assert observation["windDirection"] is None
    assert observation["visibility"] is None
    assert observation["seaLevelPressure"] is None
    assert observation["windSpeed"] is None
    assert observation["windGust"] is None
    assert observation["iconTime"] is None
    assert observation["iconWeather"] is None
Beispiel #16
0
async def test_no_fore(aiohttp_client, loop):
    app = aiohttp.web.Application()
    client = await aiohttp_client(app)
    snws = pynws.SimpleNWS(*LATLON, USERID, client)
    assert snws.forecast == []