rasterio/tests/test_colormap.py
Sean Gillies 12f8fc7e3f New, lazier AWS sessions
New Env class and tests.
More logging, tests, safer environment
Remove usage (deprecated) of rasterio.drivers()
Also pep8 cleanups throughout the tests and a fix for unchecked
dtypes when opening a dataset in 'w' mode.
Now we can simply import warnings in __init__.py. In the
deprecations tests, we needed to see a single warning only one
time to avoid multiple drivers() warnings.
Add a global env.
Add rasterio.env.setenv()
2016-04-28 15:26:55 -06:00

37 lines
1.1 KiB
Python

import logging
import subprocess
import sys
import rasterio
logging.basicConfig(stream=sys.stderr, level=logging.DEBUG)
def test_write_colormap_warn(tmpdir, recwarn):
with rasterio.open('tests/data/shade.tif') as src:
profile = src.meta
tiffname = str(tmpdir.join('foo.tif'))
with rasterio.open(tiffname, 'w', **profile) as dst:
dst.write_colormap(1, {0: (255, 0, 0, 255), 255: (0, 0, 0, 0)})
w = recwarn.pop(UserWarning)
assert "The value will be ignored" in str(w.message)
def test_write_colormap(tmpdir):
with rasterio.open('tests/data/shade.tif') as src:
shade = src.read(1)
meta = src.meta
tiffname = str(tmpdir.join('foo.png'))
meta['driver'] = 'PNG'
with rasterio.open(tiffname, 'w', **meta) as dst:
dst.write(shade, indexes=1)
dst.write_colormap(1, {0: (255, 0, 0, 255), 255: (0, 0, 0, 0)})
cmap = dst.colormap(1)
assert cmap[0] == (255, 0, 0, 255)
assert cmap[255] == (0, 0, 0, 0)
with rasterio.open(tiffname) as src:
cmap = src.colormap(1)
assert cmap[0] == (255, 0, 0, 255)
assert cmap[255] == (0, 0, 0, 0)