Skip to content

Commit

Permalink
fix: be specific about nodata being None (#363)
Browse files Browse the repository at this point in the history
* fix: be specific about nodata being None

* fix: format

* fix: update comment and correctly format if statement
  • Loading branch information
MDavidson17 authored Feb 19, 2023
1 parent a1154e8 commit 8fe8211
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
5 changes: 3 additions & 2 deletions scripts/files/file_tiff.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,10 @@ def check_no_data(self, gdalinfo: GdalInfo) -> None:
)

def is_no_data(self, gdalinfo: GdalInfo) -> bool:
"""return True if bands have a "noDataValue" and it is set to 255."""
"""return True if bands have a "noDataValue" set."""
bands = gdalinfo["bands"]
if "noDataValue" in bands[0] and bands[0]["noDataValue"]:
# 0 in noDataValue can return false unless specific here about None
if "noDataValue" in bands[0] and bands[0]["noDataValue"] is not None:
return True
return False

Expand Down
15 changes: 13 additions & 2 deletions scripts/files/tests/file_tiff_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,9 @@ def test_check_no_data_no_value() -> None:
assert file_tiff.get_errors()


def test_is_no_data_true() -> None:
def test_is_no_data_true_255() -> None:
"""
tests is_no_data when the input layer that has no_data value assigned
tests is_no_data when the input layer that has 255 no_data value assigned
"""
gdalinfo = fake_gdal_info()
add_band(gdalinfo, no_data_value=255)
Expand All @@ -166,6 +166,17 @@ def test_is_no_data_true() -> None:
assert file_tiff.is_no_data(gdalinfo)


def test_is_no_data_true_0() -> None:
"""
tests is_no_data when the input layer that has 0 no_data value assigned
"""
gdalinfo = fake_gdal_info()
add_band(gdalinfo, no_data_value=0)

file_tiff = FileTiff("test")
assert file_tiff.is_no_data(gdalinfo)


def test_is_no_data_false() -> None:
"""
tests is_no_data when the input layer that does not have no_data value assigned
Expand Down

0 comments on commit 8fe8211

Please sign in to comment.