Skip to content

Commit

Permalink
Use the contexts
Browse files Browse the repository at this point in the history
  • Loading branch information
kiksekage committed Mar 31, 2022
1 parent d476ac9 commit f07de5e
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions tests/drivers/test_raster_drivers.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,22 @@
METADATA_KEYS = ('bounds', 'range', 'mean', 'stdev', 'percentiles', 'metadata')


@pytest.fixture
def dynamic_non_writable_db(monkeypatch, driver_path, provider, raster_file):
from terracotta import drivers
db = drivers.get_driver(driver_path, provider=provider)
keys = ('some', 'keynames')

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

with monkeypatch.context() as m:
m.setattr(db.meta_store, "_WRITABLE", False)
yield

db.delete(['some', 'value'])


@pytest.mark.parametrize('provider', DRIVERS)
def test_insertion_and_retrieval(driver_path, provider, raster_file):
from terracotta import drivers
Expand Down Expand Up @@ -147,16 +163,9 @@ def test_lazy_loading(driver_path, provider, raster_file):


@pytest.mark.parametrize('provider', DRIVERS)
def test_non_writable_lazy_loading(driver_path, provider, raster_file):
def test_non_writable_lazy_loading(driver_path, provider, dynamic_non_writable_db):
from terracotta import drivers
db = drivers.get_driver(driver_path, provider=provider)
keys = ('some', 'keynames')

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

# Manually set the meta store to un-writable
db.meta_store._WRITABLE = False

with pytest.raises(exceptions.DatabaseNotWritableError):
db.get_metadata(['some', 'value'])
Expand Down

0 comments on commit f07de5e

Please sign in to comment.