Skip to content

Commit

Permalink
added tests for _stack_bands and deprecated stack_raster_tifs. (#241)
Browse files Browse the repository at this point in the history
* added tests for _stack_bands and deprecated stack_raster_tifs. Also edited _stack_bands in spatial.py since it needed to change ValueError to Exception for except clause to be accessed. Otherwise, the specific error in the test is an AttributeError.
* cleaned up imports and changed Exception to AssertionError in spatial.py stack function
* Adding warning message to stack_raster_tifs deprecation test
  • Loading branch information
Joe McGlinchy authored and Leah Wasser committed Feb 19, 2019
1 parent 5bc49cb commit cdfb644
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 2 deletions.
4 changes: 2 additions & 2 deletions earthpy/spatial.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,8 @@ def _stack_bands(sources, write_raster=False, dest=None):
for src in sources:
src.profile

except ValueError as ve:
raise ValueError("The sources object should be Dataset Reader")
except AttributeError as ae:
raise AttributeError("The sources object should be Dataset Reader")
sys.exit()

else:
Expand Down
25 changes: 25 additions & 0 deletions earthpy/tests/test__stack_bands.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
""" Tests for the _stack_bands() method """

import numpy as np
import pytest
import earthpy.spatial as es


@pytest.fixture
def b1_b2_arrs():
b1 = np.array([[6, 7, 8, 9, 10], [16, 17, 18, 19, 20]])
b2 = np.array([[1, 2, 3, 4, 5], [14, 12, 13, 14, 17]])
return b1, b2


def test__stack_bands(b1_b2_arrs):
"""_stack_bands input should be of type DatasetReader."""

# Test data
b1, b2 = b1_b2_arrs

# Check ValueError for Dataset Reader
with pytest.raises(
AttributeError, match="The sources object should be Dataset Reader"
):
es._stack_bands([b1, b2])
23 changes: 23 additions & 0 deletions earthpy/tests/test_stack_raster_tifs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
""" Tests for the _stack_bands() method """

import numpy as np
import pytest
import earthpy.spatial as es


@pytest.fixture
def b1_b2_arrs():
b1 = np.array([[6, 7, 8, 9, 10], [16, 17, 18, 19, 20]])
b2 = np.array([[1, 2, 3, 4, 5], [14, 12, 13, 14, 17]])
return b1, b2


def test_stack_raster_tifs(b1_b2_arrs):
"""stack_raster_tifs() should return a Warning."""

# Test data
b1, b2 = b1_b2_arrs

# Check Warning for Deprecation
with pytest.raises(Warning, match="stack_raster_tifs is deprecated"):
es.stack_raster_tifs([b1, b2], out_path="test.tif")

0 comments on commit cdfb644

Please sign in to comment.