Skip to content
Open
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
6 changes: 4 additions & 2 deletions cmr/queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -856,10 +856,12 @@ def cloud_cover(self, min_cover: FloatLike = 0, max_cover: FloatLike = 100) -> S
:returns: self
"""

if not min_cover and not max_cover:
has_min = min_cover is not None and min_cover != ""
has_max = max_cover is not None and max_cover != ""
if not has_min and not has_max:
raise ValueError("Please provide at least min_cover, max_cover or both")

if min_cover and max_cover:
if has_min and has_max:
try:
minimum = float(min_cover)
maxiumum = float(max_cover)
Expand Down
16 changes: 16 additions & 0 deletions tests/test_granule.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,22 @@ def test_day_night_flag_invalid_type_set(self):
query.day_night_flag(True) # type: ignore[arg-type]
self.assertNotIn(self.day_night_flag, query.params)

def test_cloud_cover_zero(self):
query = GranuleQuery().cloud_cover(0, 0)
self.assertEqual(query.params[self.cloud_cover], "0,0")

def test_cloud_cover_zero_open_bound(self):
for bounds, expected in [(("", 0), ",0"), ((0, ""), "0,")]:
with self.subTest(bounds=bounds):
query = GranuleQuery().cloud_cover(*bounds)
self.assertEqual(query.params[self.cloud_cover], expected)

def test_cloud_cover_invalid_with_zero(self):
for bounds in [(1, 0), (0, -1), (0, "invalid"), ("invalid", 0), ("", "")]:
with self.subTest(bounds=bounds):
with self.assertRaises(ValueError):
GranuleQuery().cloud_cover(*bounds)

def test_cloud_cover_min_only(self):
query = GranuleQuery()
query.cloud_cover(-70)
Expand Down