Skip to content

Commit 067d2a3

Browse files
committed
Add tests for filenames with windows and fix a recursion bug #286
1 parent fbee308 commit 067d2a3

2 files changed

Lines changed: 29 additions & 3 deletions

File tree

ci/on_push/test_others.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -595,3 +595,24 @@ def test_constellations():
595595

596596
def test_regex_glob():
597597
ci.assert_val(convert_glob_to_regex("**/*_rgb.png"), r".*/.*_rgb\.png", "ASF regex")
598+
599+
600+
def test_filename_window():
601+
prod_path = opt_path().joinpath("LT05_L1TP_200030_20111110_20200820_02_T1")
602+
window_path = others_path().joinpath(
603+
"20201220T104856_L8_200030_OLI_TIRS_window.geojson"
604+
)
605+
prod = READER.open(prod_path, remove_tmp=True)
606+
extent = prod.extent()
607+
ci.assert_val(
608+
prod.get_band_file_name("RED", pixel_size=20, window=extent),
609+
prod.get_band_file_name("RED", pixel_size=20),
610+
"Extent window",
611+
)
612+
613+
with pytest.raises(AssertionError):
614+
ci.assert_val(
615+
prod.get_band_file_name("RED", pixel_size=20, window=window_path),
616+
prod.get_band_file_name("RED", pixel_size=20),
617+
"Small window",
618+
)

eoreader/products/product.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ def __init__(
141141
**kwargs,
142142
) -> None:
143143
self.needs_extraction = True
144-
"""Does this product needs to be extracted to be processed ? (:code:`True` by default)."""
144+
"""Does this product needs to be extracted to be processed? (:code:`True` by default)."""
145145

146146
self.path = AnyPath(product_path)
147147
if (
@@ -833,9 +833,14 @@ def get_band_file_name(
833833

834834
# Window
835835
window = kwargs.get("window")
836-
win_suffix = ""
836+
max_extent = None
837837
if window is not None:
838-
win_suffix = f"_{utils.get_window_suffix(window, max_extent=self.extent())}"
838+
# This way we can avoid RecursionError when computing extents (which doesn't have a window)
839+
max_extent = self.extent()
840+
841+
win_suffix = utils.get_window_suffix(window, max_extent=max_extent)
842+
if win_suffix:
843+
win_suffix = f"_{win_suffix}"
839844

840845
# Specific if needed
841846
if dem_name:

0 commit comments

Comments
 (0)