def test_gdal_config_accessers(): """Low level GDAL config access.""" assert get_gdal_config('foo') is None set_gdal_config('foo', 'bar') assert get_gdal_config('foo') == 'bar' del_gdal_config('foo') assert get_gdal_config('foo') is None
def test_gdal_config_accessors_no_normalize(): """Disables casting keys to upper case and normalizing values to boolean Python values. """ assert get_gdal_config('foo') is None set_gdal_config('foo', 'ON', normalize=False) assert get_gdal_config('foo', normalize=False) == 'ON' del_gdal_config('foo') assert get_gdal_config('foo') is None
def test_gdal_config_accessors_capitalization(): """GDAL normalizes config names to upper case so Rasterio does not need to do it on its own. This test serves as a canary in case GDAL changes its behavior, which is an important part of reinstating discovered environment variables when ``rasterio.Env()`` starts. GDAL does not alter config values. """ assert get_gdal_config('foo') is None assert get_gdal_config('FOO') is None set_gdal_config('foo', 'bar') assert get_gdal_config('foo') == 'bar' assert get_gdal_config('FOO') == 'bar' del_gdal_config('foo') assert get_gdal_config('foo') is None assert get_gdal_config('FOO') is None set_gdal_config('upper', 'UPPER') assert get_gdal_config('upper') == 'UPPER' del_gdal_config('upper')
def test_env_discovery(key, val): """When passing options to ``rasterio.Env()`` Rasterio first checks to see if they were set in the environment and reinstates on exit. The discovered environment should only be reinstated when the outermost environment exits. It's really important that this test use an environment default. """ assert rasterio.env._discovered_options is None, \ "Something has gone horribly wrong." try: # This should persist when all other environment managers exit. set_gdal_config(key, val) # Start an environment and overwrite the value that should persist with rasterio.Env(**{key: True}): assert get_gdal_config(key) is True assert rasterio.env._discovered_options == {key: val} # Start another nested environment, again overwriting the value # that should persist with rasterio.Env(**{key: False}): assert rasterio.env._discovered_options == {key: val} assert get_gdal_config(key) is False # Ensure the outer state is restored. assert rasterio.env._discovered_options == {key: val} assert get_gdal_config(key) is True # Ensure the discovered value remains unchanged. assert rasterio.env._discovered_options is None assert get_gdal_config(key, normalize=False) == val # Leaving this option in the GDAL environment could cause a problem # for other tests. finally: del_gdal_config(key)
def test_env_discovery(key, val): """When passing options to ``rasterio.Env()`` Rasterio first checks to see if they were set in the environment and reinstates on exit. The discovered environment should only be reinstated when the outermost environment exits. It's really important that this test use an environment default. """ assert rasterio.env.local._discovered_options is None, \ "Something has gone horribly wrong." try: # This should persist when all other environment managers exit. set_gdal_config(key, val) # Start an environment and overwrite the value that should persist with rasterio.Env(**{key: True}): assert get_gdal_config(key) is True assert rasterio.env.local._discovered_options == {key: val} # Start another nested environment, again overwriting the value # that should persist with rasterio.Env(**{key: False}): assert rasterio.env.local._discovered_options == {key: val} assert get_gdal_config(key) is False # Ensure the outer state is restored. assert rasterio.env.local._discovered_options == {key: val} assert get_gdal_config(key) is True # Ensure the discovered value remains unchanged. assert rasterio.env.local._discovered_options is None assert get_gdal_config(key, normalize=False) == val # Leaving this option in the GDAL environment could cause a problem # for other tests. finally: del_gdal_config(key)