Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix failing tests #18

Merged
merged 4 commits into from
Mar 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,7 @@ target/
.*.swp

docs/notebooks/.ipynb_checkpoints/*

.pytest_cache
.hypothesis
.coverage*
2 changes: 1 addition & 1 deletion rio_rgbify/mbtiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def _tile_worker(tile):
reproject(
rasterio.band(src, 1), out,
dst_transform=toaffine,
dst_crs="init='epsg:3857'",
dst_crs="epsg:3857",
resampling=RESAMPLING.bilinear)

out = data_to_rgb(out, global_args['base_val'], global_args['interval'])
Expand Down
10 changes: 5 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""rio-rgbify: setup."""

import os
import sys
from setuptools import setup, find_packages
from setuptools.extension import Extension

# Parse the version from the fiona module.
with open('rio_rgbify/__init__.py') as f:
Expand All @@ -18,6 +18,7 @@
def read(fname):
return open(os.path.join(os.path.dirname(__file__), fname)).read()


setup(name='rio-rgbify',
version=version,
description=u"Encode arbitrary bit depth rasters in psuedo base-256 as RGB",
Expand All @@ -36,6 +37,5 @@ def read(fname):
'test': ['pytest', 'pytest-cov', 'codecov', 'hypothesis', 'raster_tester']},
entry_points="""
[rasterio.rio_plugins]
toa=rio_rgbify.scripts.cli:rgbify
"""
)
rgbify=rio_rgbify.scripts.cli:rgbify
""")
159 changes: 62 additions & 97 deletions test/test_cli.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,19 @@
import os

import click
from click.testing import CliRunner
import rasterio as rio

import numpy as np
from rio_rgbify.scripts.cli import rgbify
import click

from tempfile import mkdtemp
from shutil import rmtree
import os
import rasterio as rio
from rio_rgbify.scripts.cli import rgbify

from raster_tester.compare import affaux, upsample_array

class TestingDir:
def __init__(self):
self.tmpdir = mkdtemp()
def __enter__(self):
return self
def __exit__(self, a, b, c):
rmtree(self.tmpdir)
def mkpath(self, filename):
return os.path.join(self.tmpdir, filename)

in_elev_src = os.path.join(os.path.dirname(__file__), 'fixtures', 'elev.tif')
expected_src = os.path.join(os.path.dirname(__file__), 'expected', 'elev-rgb.tif')


def flex_compare(r1, r2, thresh=10):
upsample = 4
Expand All @@ -36,17 +31,13 @@ def flex_compare(r1, r2, thresh=10):


def test_cli_good_elev():
in_elev_src = 'test/fixtures/elev.tif'
expected_src = 'test/expected/elev-rgb.tif'
with TestingDir() as tmpdir:
out_rgb_src = tmpdir.mkpath('rgb.tif')

runner = CliRunner()
result = runner.invoke(rgbify, [in_elev_src, out_rgb_src, '--interval', 0.001, '--base-val', -100, '-j', 1])
runner = CliRunner()
with runner.isolated_filesystem():
result = runner.invoke(rgbify, [in_elev_src, 'rgb.tif', '--interval', 0.001, '--base-val', -100, '-j', 1])

assert result.exit_code == 0

with rio.open(out_rgb_src) as created:
with rio.open('rgb.tif') as created:
with rio.open(expected_src) as expected:
carr = created.read()
earr = expected.read()
Expand All @@ -55,117 +46,91 @@ def test_cli_good_elev():


def test_cli_fail_elev():
in_elev_src = 'test/fixtures/elev.tif'
expected_src = 'test/expected/elev-rgb.tif'
with TestingDir() as tmpdir:
out_rgb_src = tmpdir.mkpath('rgb.tif')

runner = CliRunner()
result = runner.invoke(rgbify, [in_elev_src, out_rgb_src, '--interval', 0.00000001, '--base-val', -100, '-j', 1])

runner = CliRunner()
with runner.isolated_filesystem():
result = runner.invoke(rgbify, [in_elev_src, 'rgb.tif', '--interval', 0.00000001, '--base-val', -100, '-j', 1])
assert result.exit_code == -1


def test_mbtiler_webp():
in_elev_src = 'test/fixtures/elev.tif'

with TestingDir() as tmpdir:
out_mbtiles_finer = tmpdir.mkpath('output-0-dot-1.mbtiles')
runner = CliRunner()

result_finer = runner.invoke(rgbify, [in_elev_src, out_mbtiles_finer, '--interval', 0.1, '--min-z', 10, '--max-z', 11, '--format', 'webp', '-j', 1])

runner = CliRunner()
with runner.isolated_filesystem():
out_mbtiles_finer = 'output-0-dot-1.mbtiles'
result_finer = runner.invoke(rgbify, [in_elev_src, out_mbtiles_finer,
'--interval', 0.1, '--min-z', 10, '--max-z', 11,
'--format', 'webp', '-j', 1])
assert result_finer.exit_code == 0

out_mbtiles_coarser = tmpdir.mkpath('output-1.mbtiles')

result_coarser = runner.invoke(rgbify, [in_elev_src, out_mbtiles_coarser, '--min-z', 10, '--max-z', 11, '--format', 'webp', '-j', 1])

out_mbtiles_coarser = 'output-1.mbtiles'
result_coarser = runner.invoke(rgbify, [in_elev_src, out_mbtiles_coarser,
'--min-z', 10, '--max-z', 11, '--format', 'webp', '-j', 1])
assert result_coarser.exit_code == 0

assert os.path.getsize(out_mbtiles_finer) > os.path.getsize(out_mbtiles_coarser)


def test_mbtiler_png():
in_elev_src = 'test/fixtures/elev.tif'

with TestingDir() as tmpdir:
out_mbtiles_finer = tmpdir.mkpath('output-0-dot-1.mbtiles')
runner = CliRunner()

result_finer = runner.invoke(rgbify, [in_elev_src, out_mbtiles_finer, '--interval', 0.1, '--min-z', 10, '--max-z', 11, '--format', 'png'])

runner = CliRunner()
with runner.isolated_filesystem():
out_mbtiles_finer = 'output-0-dot-1.mbtiles'
result_finer = runner.invoke(rgbify, [in_elev_src, out_mbtiles_finer,
'--interval', 0.1, '--min-z', 10, '--max-z', 11, '--format', 'png'])
assert result_finer.exit_code == 0

out_mbtiles_coarser = tmpdir.mkpath('output-1.mbtiles')

result_coarser = runner.invoke(rgbify, [in_elev_src, out_mbtiles_coarser, '--min-z', 10, '--max-z', 11, '--format', 'png', '-j', 1])

out_mbtiles_coarser = 'output-1.mbtiles'
result_coarser = runner.invoke(rgbify, [in_elev_src, out_mbtiles_coarser,
'--min-z', 10, '--max-z', 11, '--format', 'png', '-j', 1])
assert result_coarser.exit_code == 0

assert os.path.getsize(out_mbtiles_finer) > os.path.getsize(out_mbtiles_coarser)

def test_mbtiler_png_bounding_tile():
in_elev_src = 'test/fixtures/elev.tif'

with TestingDir() as tmpdir:
out_mbtiles_not_limited = tmpdir.mkpath('output-not-limited.mbtiles')
runner = CliRunner()

result_not_limited = runner.invoke(rgbify, [in_elev_src, out_mbtiles_not_limited, '--min-z', 12, '--max-z', 12, '--format', 'png'])

def test_mbtiler_png_bounding_tile():
runner = CliRunner()
with runner.isolated_filesystem():
out_mbtiles_not_limited = 'output-not-limited.mbtiles'
result_not_limited = runner.invoke(rgbify, [in_elev_src, out_mbtiles_not_limited,
'--min-z', 12, '--max-z', 12, '--format', 'png'])
assert result_not_limited.exit_code == 0

out_mbtiles_limited = tmpdir.mkpath('output-limited.mbtiles')

result_limited = runner.invoke(rgbify, [in_elev_src, out_mbtiles_limited, '--min-z', 12, '--max-z', 12, '--format', 'png', '--bounding-tile', '[654, 1582, 12]'])

out_mbtiles_limited = 'output-limited.mbtiles'
result_limited = runner.invoke(rgbify, [in_elev_src, out_mbtiles_limited,
'--min-z', 12, '--max-z', 12, '--format', 'png',
'--bounding-tile', '[654, 1582, 12]'])
assert result_limited.exit_code == 0

assert os.path.getsize(out_mbtiles_not_limited) > os.path.getsize(out_mbtiles_limited)


def test_mbtiler_webp_badzoom():
in_elev_src = 'test/fixtures/elev.tif'

with TestingDir() as tmpdir:
out_mbtiles = tmpdir.mkpath('output.mbtiles')
runner = CliRunner()

runner = CliRunner()
with runner.isolated_filesystem():
out_mbtiles = 'output.mbtiles'
result = runner.invoke(rgbify, [in_elev_src, out_mbtiles, '--min-z', 10, '--max-z', 9, '--format', 'webp', '-j', 1])

assert result.exit_code == -1

def test_mbtiler_webp_badboundingtile():
in_elev_src = 'test/fixtures/elev.tif'

with TestingDir() as tmpdir:
out_mbtiles = tmpdir.mkpath('output.mbtiles')
runner = CliRunner()

result = runner.invoke(rgbify, [in_elev_src, out_mbtiles, '--min-z', 10, '--max-z', 9, '--format', 'webp', '--bounding-tile', '654, 1582, 12'])

def test_mbtiler_webp_badboundingtile():
runner = CliRunner()
with runner.isolated_filesystem():
out_mbtiles = 'output.mbtiles'
result = runner.invoke(rgbify, [in_elev_src, out_mbtiles,
'--min-z', 10, '--max-z', 9, '--format', 'webp', '--bounding-tile', '654, 1582, 12'])
assert result.exit_code == -1

def test_mbtiler_webp_badboundingtile_values():
in_elev_src = 'test/fixtures/elev.tif'

with TestingDir() as tmpdir:
out_mbtiles = tmpdir.mkpath('output.mbtiles')
runner = CliRunner()

result = runner.invoke(rgbify, [in_elev_src, out_mbtiles, '--min-z', 10, '--max-z', 9, '--format', 'webp', '--bounding-tile', '[654, 1582]'])

def test_mbtiler_webp_badboundingtile_values():
runner = CliRunner()
with runner.isolated_filesystem():
out_mbtiles = 'output.mbtiles'
result = runner.invoke(rgbify, [in_elev_src, out_mbtiles,
'--min-z', 10, '--max-z', 9, '--format', 'webp', '--bounding-tile', '[654, 1582]'])
assert result.exit_code == -1


def test_bad_input_format():
in_elev_src = 'test/fixtures/elev.tif'

with TestingDir() as tmpdir:
out_mbtiles = tmpdir.mkpath('output.lol')
runner = CliRunner()

runner = CliRunner()
with runner.isolated_filesystem():
out_mbtiles = 'output.lol'
result = runner.invoke(rgbify, [in_elev_src, out_mbtiles, '--min-z', 10, '--max-z', 9, '--format', 'webp', '-j', 1])

assert result.exit_code == -1
2 changes: 1 addition & 1 deletion test/test_mbtiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def test_webp_writer():

test_bytearray = _encode_as_webp(test_data)

assert len(test_bytearray) == 42
assert len(test_bytearray) == 34
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sgillies @dnomadb Not really sure why this changed!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know. I took myself off the review list for this one because I gotta focus on something else and I haven't used this project yet.


test_complex_data = test_data.copy()

Expand Down