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: use regex to exactly match asset band #61

Merged
merged 1 commit into from
Jul 18, 2024
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
3 changes: 2 additions & 1 deletion eodag_cube/api/product/_assets.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,9 @@ def get_data(
array if unable to get the data
:rtype: xarray.DataArray
"""
band_pattern = rf"^{self.key}$"
return self.product.get_data(
band=self.key,
band=band_pattern,
crs=crs,
resolution=resolution,
extent=extent,
Expand Down
15 changes: 15 additions & 0 deletions tests/units/test_eoproduct_driver_stac_assets.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

from tests import TEST_RESOURCES_PATH, EODagTestCase
from tests.context import AddressNotFound, EOProduct, StacAssets
from tests.utils import mock


class TestEOProductDriverStacAssets(EODagTestCase):
Expand Down Expand Up @@ -121,6 +122,20 @@ def test_asset_get_data(self):
)
self.assertIsInstance(data, DataArray)

@mock.patch("eodag_cube.api.product._product.EOProduct.get_data", autospec=True)
def test_asset_get_data_pattern(self, mock_get_data):
"""get_data on asset should use a pattern to match exactly its band"""

self.product.assets["T31TDH_20180101T124911_B01.jp2"].get_data()
mock_get_data.assert_called_once_with(
self.product,
band=r"^T31TDH_20180101T124911_B01.jp2$",
crs=None,
resolution=None,
extent=None,
resampling=None,
)

@contextmanager
def _filesystem_product(self):
original = self.product.location
Expand Down
Loading