def test_incorrect_group_processing():
    c = geodata.regions_country().centroids()
    c = list(c.request[141:142]) + list(c.request[143:144]) + list(
        c.request[136:137]) + list(c.request[114:134])
    print(c)
    c = geodata.regions_country(c).centroids()
    r = geodata.regions_country(c['request'])
    boundaries: DataFrame = r.boundaries(resolution=10)

    assert 'group' not in boundaries.keys()
def test_case():
    usa = geodata.regions_country(request=['usa'])
    states_48 = geodata.regions_state(['us-48'])

    states_list = ['NY', 'TX', 'louisiana']
    states = geodata.regions_state(request=states_list, within=usa)

    cities_list = ['New york', 'boston', 'la']
    t_cities = geodata.regions_city(request=cities_list, within=usa)
def test_havana_new_york():
    try:
        r = geodata.regions_builder(request=['havana', 'new york city']) \
            .where(request='havana', within=geodata.regions_country('cuba')) \
            .where(request='new york city', within=geodata.regions_state('new york')) \
            .build()
    except ValueError as ex:
        assert 'No objects were found for new york city.\n' == str(ex)
        return

    assert False, 'Should throw exception'
def test_where_request_level_detection():
    """
    where('new york', region=geodata.regions_state('new york')) gives county as first detected level
    where('boston', region=geodata.regions_country('usa')) gives city as first detected level
    But 'new york' also matches a city name so common level should be a city
    """
    r = geodata.regions_builder(request=['new york', 'boston']) \
        .where('new york', within=geodata.regions_state('new york')) \
        .where('boston', within=geodata.regions_country('usa')) \
        .build()

    assert [NYC_ID, BOSTON_ID] == r.to_data_frame().id.tolist()
def test_countries():
    assert 221 == len(geodata.regions_country().centroids().request)
def test_new_server():
    c = geodata.regions_country(request='USA')
    print(c.centroids())
    print(c)
def test_error_response():
    with pytest.raises(ValueError) as exception:
        geodata.regions_country(request='blablabla').centroids()

    assert 'No objects were found for blablabla.\n' == exception.value.args[0]
def test_geocoderegion_as_region():
    usa = geodata.regions_country(request=['usa'])
    states_list = ['NY', 'TX', 'NV']
    geodata.regions_state(request=states_list, within=usa)
def test_mapregion():
    usa: geodata.Regions = geodata.regions_country(request='USA')
    print(usa.centroids())