Beispiel #1
0
def test_read_carto_wrong_credentials(mocker):
    # When
    with pytest.raises(ValueError) as e:
        read_carto('__source__', 1234)

    # Then
    assert str(e.value) == 'Credentials attribute is required. Please pass a `Credentials` ' + \
                           'instance or use the `set_default_credentials` function.'
Beispiel #2
0
def test_read_carto_wrong_source(mocker):
    # When
    with pytest.raises(ValueError) as e:
        read_carto(1234)

    # Then
    assert str(
        e.value
    ) == 'Wrong source. You should provide a valid table_name or SQL query.'
Beispiel #3
0
def test_read_carto_schema(mocker):
    # Given
    mocker.patch('cartoframes.utils.geom_utils.set_geometry')
    cm_mock = mocker.patch.object(ContextManager, 'copy_to')

    # When
    read_carto('__source__', CREDENTIALS, schema='__schema__')

    # Then
    cm_mock.assert_called_once_with('__source__', '__schema__', None, 3)
Beispiel #4
0
def test_read_carto_decode_geom_false(mocker):
    # Given
    cm_mock = mocker.patch.object(ContextManager, 'copy_to')
    cm_mock.return_value = GeoDataFrame({
        'cartodb_id': [1, 2, 3],
        'the_geom': [
            '010100000000000000000000000000000000000000',
            '010100000000000000000024400000000000002e40',
            '010100000000000000000034400000000000003e40'
        ]
    })
    expected = GeoDataFrame({
        'cartodb_id': [1, 2, 3],
        'the_geom': [
            '010100000000000000000000000000000000000000',
            '010100000000000000000024400000000000002e40',
            '010100000000000000000034400000000000003e40'
        ]
    })

    # When
    gdf = read_carto('__source__', CREDENTIALS, decode_geom=False)

    # Then
    assert expected.equals(gdf)
Beispiel #5
0
def test_read_carto(mocker):
    # Given
    cm_mock = mocker.patch.object(ContextManager, 'copy_to')
    cm_mock.return_value = GeoDataFrame({
        'cartodb_id': [1, 2, 3],
        'the_geom': [
            '010100000000000000000000000000000000000000',
            '010100000000000000000024400000000000002e40',
            '010100000000000000000034400000000000003e40'
        ]
    })
    expected = GeoDataFrame(
        {
            'cartodb_id': [1, 2, 3],
            'the_geom': [Point([0, 0]),
                         Point([10, 15]),
                         Point([20, 30])]
        },
        geometry='the_geom')

    # When
    gdf = read_carto('__source__', CREDENTIALS)

    # Then
    cm_mock.assert_called_once_with('__source__', None, None, 3)
    assert expected.equals(gdf)
    assert gdf.crs == 'epsg:4326'
Beispiel #6
0
def test_read_carto_index_col_not_exists(mocker):
    # Given
    cm_mock = mocker.patch.object(ContextManager, 'copy_to')
    cm_mock.return_value = GeoDataFrame({
        'cartodb_id': [1, 2, 3],
        'the_geom': [
            '010100000000000000000000000000000000000000',
            '010100000000000000000024400000000000002e40',
            '010100000000000000000034400000000000003e40'
        ]
    })
    expected = GeoDataFrame(
        {
            'cartodb_id': [1, 2, 3],
            'the_geom': [Point([0, 0]),
                         Point([10, 15]),
                         Point([20, 30])]
        },
        geometry='the_geom',
        index=Index([0, 1, 2], name='rename_index'))

    # When
    gdf = read_carto('__source__', CREDENTIALS, index_col='rename_index')

    # Then
    assert expected.equals(gdf)
Beispiel #7
0
def test_read_carto_basegeometry_as_null_geom_value(mocker):
    # Given
    cm_mock = mocker.patch.object(ContextManager, 'copy_to')
    cm_mock.return_value = GeoDataFrame({
        'cartodb_id': [1],
        'the_geom': [None]
    })

    # When
    gdf = read_carto('__source__', CREDENTIALS, null_geom_value=BaseGeometry())

    # Then
    expected = GeoDataFrame({
        'cartodb_id': [1],
        'the_geom': [BaseGeometry()]
    },
                            geometry='the_geom')

    cm_mock.assert_called_once_with('__source__', None, None, 3)
    assert expected.equals(gdf)
    assert gdf.crs == 'epsg:4326'