rasterio/tests/test_nodata.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

44 lines
1.5 KiB
Python

import logging
import pytest
import re
import subprocess
import sys
import rasterio
logging.basicConfig(stream=sys.stderr, level=logging.DEBUG)
def test_nodata(tmpdir):
dst_path = str(tmpdir.join('lol.tif'))
with rasterio.open('tests/data/RGB.byte.tif') as src:
with rasterio.open(dst_path, 'w', **src.meta) as dst:
assert dst.nodata == 0.0
assert dst.meta['nodata'] == 0.0
assert dst.nodatavals == (0.0, 0.0, 0.0)
info = subprocess.check_output([
'gdalinfo', dst_path])
pattern = b'Band 1.*?NoData Value=0'
assert re.search(pattern, info, re.DOTALL) is not None
pattern = b'Band 2.*?NoData Value=0'
assert re.search(pattern, info, re.DOTALL) is not None
pattern = b'Band 2.*?NoData Value=0'
assert re.search(pattern, info, re.DOTALL) is not None
def test_set_nodata(tmpdir):
dst_path = str(tmpdir.join('lol.tif'))
with rasterio.open('tests/data/RGB.byte.tif') as src:
meta = src.meta
meta['nodata'] = 42
with rasterio.open(dst_path, 'w', **meta) as dst:
assert dst.nodata == 42
assert dst.meta['nodata'] == 42
assert dst.nodatavals == (42, 42, 42)
info = subprocess.check_output([
'gdalinfo', dst_path])
pattern = b'Band 1.*?NoData Value=42'
assert re.search(pattern, info, re.DOTALL) is not None
pattern = b'Band 2.*?NoData Value=42'
assert re.search(pattern, info, re.DOTALL) is not None
pattern = b'Band 2.*?NoData Value=42'
assert re.search(pattern, info, re.DOTALL) is not None