How to use the terracotta.drivers.get_driver function in terracotta

To help you get started, we’ve selected a few terracotta examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github DHI-GRAS / terracotta / tests / drivers / test_drivers.py View on Github external
def test_connect_before_create(driver_path, provider):
    from terracotta import drivers, exceptions
    db = drivers.get_driver(driver_path, provider=provider)

    with pytest.raises(exceptions.InvalidDatabaseError):
        with db.connect():
            pass
github DHI-GRAS / terracotta / tests / drivers / test_raster_drivers.py View on Github external
def test_invalid_group_insertion(monkeypatch, driver_path, provider, raster_file):
    from terracotta import drivers

    db = drivers.get_driver(driver_path, provider=provider)
    keys = ('keyname',)

    db.create(keys)

    def throw(*args, **kwargs):
        raise NotImplementedError()

    with monkeypatch.context() as m:
        m.setattr(db, 'compute_metadata', throw)

        with db.connect():
            db.insert(['bar'], str(raster_file), skip_metadata=True)

            with pytest.raises(NotImplementedError):
                db.insert(['foo'], str(raster_file), skip_metadata=False)
github DHI-GRAS / terracotta / tests / drivers / test_raster_drivers.py View on Github external
def test_path_override(driver_path, provider, raster_file):
    from terracotta import drivers
    db = drivers.get_driver(driver_path, provider=provider)
    keys = ('some', 'keynames')
    key_value = ('some', 'value')
    bogus_path = 'foo'

    db.create(keys)
    db.insert(key_value, str(raster_file), override_path=bogus_path)
    assert db.get_datasets()[key_value] == bogus_path

    with pytest.raises(IOError) as exc:
        # overridden path doesn't exist
        db.get_raster_tile(key_value)
        assert bogus_path in exc.value
github DHI-GRAS / terracotta / tests / drivers / test_sqlite.py View on Github external
def test_version_conflict(tmpdir, raster_file, monkeypatch):
    from terracotta import drivers, exceptions

    dbfile = tmpdir.join('test.sqlite')
    db = drivers.get_driver(str(dbfile), provider='sqlite')
    keys = ('some', 'keys')

    db.create(keys)
    db.insert(['some', 'value'], str(raster_file))

    # works
    with db.connect():
        pass

    with monkeypatch.context() as m:
        fake_version = '0.0.0'
        m.setattr('terracotta.drivers.sqlite.__version__', fake_version)

        # works
        with db.connect(check=False):
            pass
github DHI-GRAS / terracotta / tests / drivers / test_drivers.py View on Github external
def test_get_driver_invalid():
    from terracotta import drivers
    with pytest.raises(ValueError) as exc:
        drivers.get_driver('', provider='foo')
    assert 'Unknown database provider' in str(exc.value)
github DHI-GRAS / terracotta / tests / drivers / test_drivers.py View on Github external
def test_creation_invalid(driver_path, provider):
    from terracotta import drivers, exceptions
    db = drivers.get_driver(driver_path, provider=provider)
    keys = ('invalid keyname',)

    with pytest.raises(exceptions.InvalidKeyError) as exc:
        db.create(keys)

    assert 'must be alphanumeric' in str(exc.value)
github DHI-GRAS / terracotta / tests / drivers / test_drivers.py View on Github external
def test_creation_descriptions(driver_path, provider):
    from terracotta import drivers
    db = drivers.get_driver(driver_path, provider=provider)
    keys = ('some', 'keynames')
    key_desc = {'some': 'explanatory text with unicode µóáßð©ßéó'}
    db.create(keys, key_descriptions=key_desc)

    assert db.key_names == keys
    assert db.get_keys()['some'] == key_desc['some']
github DHI-GRAS / terracotta / tests / drivers / test_drivers.py View on Github external
def test_broken_connection(driver_path, provider):
    """Test whether driver can recover from a broken connection"""

    class Evanescence:
        def break_me_up_inside(self, *args, **kwargs):
            raise RuntimeError('bring me to life')

        def __getattribute__(self, key):
            return object.__getattribute__(self, 'break_me_up_inside')

    from terracotta import drivers
    db = drivers.get_driver(driver_path, provider=provider)
    keys = ('some', 'keynames')
    db.create(keys)

    with pytest.raises(RuntimeError):
        with db.connect():
            db._connection = Evanescence()
            db.get_keys()

    assert not db._connected

    with db.connect():
        db.get_keys()