rasterio/tests/test_open_sharing.py
Sean Gillies 9e30d22d6d
Switch sharing kwarg default to False (#1775)
* Switch sharing kwarg default to False

Resolves #1705

* Replace GDALOpenShared with GDALOpen except in one shim

* Revert two open_dataset to GDALOpen

* Run tests under gdb

* Increment ref count in WarpedVRTBase

* Open a new dataset handle in WarpedVRT

* Remove gdb

* Remove exceptions from open_dataset in _shim1

Makes usage much easier

* Fix in-memory dataset leaks in _reproject
2019-09-13 08:05:14 -06:00

46 lines
1.5 KiB
Python

"""Tests of dataset connection sharing"""
import rasterio
from .conftest import requires_gdal2
@requires_gdal2
def test_sharing_on(capfd, path_rgb_byte_tif):
"""Datasets are shared"""
with rasterio.Env() as env:
# Opens a new file.
with rasterio.open(path_rgb_byte_tif) as srcx:
env._dump_open_datasets()
captured = capfd.readouterr()
assert "1 N GTiff" in captured.err
assert "1 S GTiff" not in captured.err
# Does not open a new file.
with rasterio.open(path_rgb_byte_tif, sharing=True) as srcy:
env._dump_open_datasets()
captured = capfd.readouterr()
assert "1 N GTiff" in captured.err
assert "1 S GTiff" in captured.err
@requires_gdal2
def test_sharing_off(capfd, path_rgb_byte_tif):
"""Datasets are not shared"""
with rasterio.Env() as env:
# Opens a new file.
with rasterio.open(path_rgb_byte_tif, sharing=False) as srcx:
env._dump_open_datasets()
captured = capfd.readouterr()
assert "1 N GTiff" in captured.err
assert "1 S GTiff" not in captured.err
# Opens a new file.
with rasterio.open(path_rgb_byte_tif, sharing=False) as srcy:
env._dump_open_datasets()
captured = capfd.readouterr()
assert captured.err.count("1 N GTiff") == 2
assert "1 S GTiff" not in captured.err