예제 #1
0
def test_workflow(city: str) -> None:
    """Test classical workflow usage with the Python library."""
    # Init client
    client = MeteoFranceClient()

    # Search a location from name.
    list_places = client.search_places(city)
    if (len(list_places) > 0) :
        my_place = list_places[0]
    else :
        print("Rien trouvé")
        return ""

    # Fetch weather forecast for the location
    my_place_weather_forecast = client.get_forecast_for_place(my_place)

    # Get the daily forecast
    my_place_daily_forecast = my_place_weather_forecast.daily_forecast

    # Fetch weather alerts.
    if my_place.admin2:
        my_place_weather_alerts = client.get_warning_current_phenomenoms(
            my_place.admin2
        )
        readable_warnings = readeable_phenomenoms_dict(
            my_place_weather_alerts.phenomenons_max_colors
        )

    return [my_place, readable_warnings["Neige-verglas"], my_place_daily_forecast]
예제 #2
0
    def get_meteo(self):
        client = MeteoFranceClient()

        marseille = client.search_places('Marseille')[0]
        current_forecast = client.get_forecast_for_place(marseille).current_forecast

        return current_forecast
예제 #3
0
def test_places_print() -> None:
    """Test different way to print Places class."""
    client = MeteoFranceClient()

    place_in_france = client.search_places("montreal")[0]
    place_not_in_france = client.search_places("montreal", "45.50884",
                                               "-73.58")[0]

    assert (repr(place_in_france) ==
            "<Place(name=Montréal, country=FR, admin=Languedoc-Roussillon)>")
    assert str(place_in_france) == "Montréal - Languedoc-Roussillon (11) - FR"

    assert (repr(place_not_in_france) ==
            "<Place(name=Montréal, country=CA, admin=Quebec)>")
    assert str(place_not_in_france) == "Montréal - Quebec - CA"
    assert f"I live in {place_not_in_france}" == "I live in Montréal - Quebec - CA"
예제 #4
0
def test_places_not_found() -> None:
    """Test when no places are found."""
    client = MeteoFranceClient()

    list_places = client.search_places("sqdmfkjdsmkf")

    assert not list_places
예제 #5
0
def test_places_with_gps() -> None:
    """Test a place search by specifying a GPS point to search arround."""
    client = MeteoFranceClient()

    list_places = client.search_places("montreal", "45.50884", "-73.58")

    assert list_places

    place = list_places[0]

    assert place.name == "Montréal"
    assert place.country == "CA"
    assert place.admin == "Quebec"
    assert place.admin2 == "06"
예제 #6
0
def test_places() -> None:
    """Test for simple seach of Place."""
    client = MeteoFranceClient()

    list_places = client.search_places("montreal")

    assert list_places

    place = list_places[0]

    assert place.insee
    assert place.latitude
    assert place.longitude
    assert place.postal_code

    assert place.name == "Montréal"
    assert place.country == "FR"
    assert place.admin == "Languedoc-Roussillon"
    assert place.admin2 == "11"
예제 #7
0
def test_workflow(city: str) -> None:
    """Test classical workflow usage with the Python library."""
    # Init client
    client = MeteoFranceClient()

    # Search a location from name.
    list_places = client.search_places(city)
    my_place = list_places[0]

    # Fetch weather forecast for the location
    my_place_weather_forecast = client.get_forecast_for_place(my_place)

    # Get the daily forecast
    my_place_daily_forecast = my_place_weather_forecast.daily_forecast

    # If rain in the hour forecast is available, get it.
    if my_place_weather_forecast.position["rain_product_available"] == 1:
        my_place_rain_forecast = client.get_rain(my_place.latitude, my_place.longitude)
        next_rain_dt = my_place_rain_forecast.next_rain_date_locale()
        if not next_rain_dt:
            rain_status = "No rain expected in the following hour."
        else:
            rain_status = next_rain_dt.strftime("%H:%M")
    else:
        rain_status = "No rain forecast available."

    # Fetch weather alerts.
    if my_place.admin2:
        my_place_weather_alerts = client.get_warning_current_phenomenoms(
            my_place.admin2
        )
        readable_warnings = readeable_phenomenoms_dict(
            my_place_weather_alerts.phenomenons_max_colors
        )

    assert type(my_place_daily_forecast) == list
    assert rain_status
    assert type(readable_warnings) == dict