Skip to content

Commit

Permalink
Add test for setting --nodata 0 from a template.
Browse files Browse the repository at this point in the history
  • Loading branch information
Sean Gillies committed Jul 8, 2015
1 parent ee1ef2d commit 5ea8c75
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
2 changes: 1 addition & 1 deletion rasterio/rio/info.py
Expand Up @@ -183,7 +183,7 @@ def in_dtype_range(value, dtype):
transform = allmd['transform']
tags = allmd['tags']

if nodata:
if nodata is not None:
dtype = dst.dtypes[0]
if not in_dtype_range(nodata, dtype):
raise click.BadParameter(
Expand Down
29 changes: 29 additions & 0 deletions tests/test_rio_info.py
Expand Up @@ -224,6 +224,7 @@ def test_tags_callback(data):
def test_edit_crs_like(data):
runner = CliRunner()

# Set up the file to be edited.
inputfile = str(data.join('RGB.byte.tif'))
with rasterio.open(inputfile, 'r+') as dst:
dst.crs = {'init': 'epsg:32617'}
Expand All @@ -234,6 +235,7 @@ def test_edit_crs_like(data):
assert src.crs == {'init': 'epsg:32617'}
assert src.nodata == 1.0

# The test.
templatefile = 'tests/data/RGB.byte.tif'
result = runner.invoke(info.edit, [
inputfile, '--like', templatefile, '--crs', 'like'])
Expand All @@ -243,23 +245,50 @@ def test_edit_crs_like(data):
assert src.nodata == 1.0


def test_edit_nodata_like(data):
runner = CliRunner()

# Set up the file to be edited.
inputfile = str(data.join('RGB.byte.tif'))
with rasterio.open(inputfile, 'r+') as dst:
dst.crs = {'init': 'epsg:32617'}
dst.nodata = 1.0

# Double check.
with rasterio.open(inputfile) as src:
assert src.crs == {'init': 'epsg:32617'}
assert src.nodata == 1.0

# The test.
templatefile = 'tests/data/RGB.byte.tif'
result = runner.invoke(info.edit, [
inputfile, '--like', templatefile, '--nodata', 'like'])
assert result.exit_code == 0
with rasterio.open(inputfile) as src:
assert src.crs == {'init': 'epsg:32617'}
assert src.nodata == 0.0


def test_edit_all_like(data):
runner = CliRunner()

inputfile = str(data.join('RGB.byte.tif'))
with rasterio.open(inputfile, 'r+') as dst:
dst.crs = {'init': 'epsg:32617'}
dst.nodata = 1.0

# Double check.
with rasterio.open(inputfile) as src:
assert src.crs == {'init': 'epsg:32617'}
assert src.nodata == 1.0

templatefile = 'tests/data/RGB.byte.tif'
result = runner.invoke(info.edit, [
inputfile, '--like', templatefile, '--all'])
assert result.exit_code == 0
with rasterio.open(inputfile) as src:
assert src.crs == {'init': 'epsg:32618'}
assert src.nodata == 0.0


def test_env():
Expand Down

0 comments on commit 5ea8c75

Please sign in to comment.