def test_positional_regions():
    df = geodata.regions_city(request=['york', 'york'],
                              within=[
                                  geodata.regions_state(['New York']),
                                  geodata.regions_state(['Illinois']),
                              ]).to_data_frame()

    assert ['New York City', 'Little York'] == df['found name'].tolist()
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_duplication_with_us48():
    df = geodata.regions_state(request=['tx', 'us-48', 'tx']).to_data_frame()

    assert 51 == len(df['request'])
    assert_row(df, 'tx', 'Texas', 0)
    assert_row(df, 'Missouri', 'Missouri', 1)
    assert_row(df, 'tx', 'Texas', 50)
def test_empty_request_name_columns(geometry_getter):
    request = 'Missouri'
    found_name = 'Missouri'

    states = geodata.regions_state('us-48')

    assert_row(states.to_data_frame(), request=request, found_name=found_name)
    assert_row(geometry_getter(states), request=request, found_name=found_name)
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_geocoderegion_as_region():
    usa = geodata.regions_country(request=['usa'])
    states_list = ['NY', 'TX', 'NV']
    geodata.regions_state(request=states_list, within=usa)
def test_filter_us48():
    df = geodata.regions_state(request='us-48').to_data_frame()
    assert 49 == len(df['request'].tolist())
    for state in df.request:
        assert len(state) > 0