Skip to content

Commit

Permalink
transform url path to os path
Browse files Browse the repository at this point in the history
normalize os path in tests
  • Loading branch information
alambare committed Dec 5, 2024
1 parent 18e4d55 commit e9b3e3e
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 7 deletions.
7 changes: 4 additions & 3 deletions eodag_cube/api/product/_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
from collections import UserDict
from contextlib import contextmanager
from typing import TYPE_CHECKING, Any, Dict, List, Optional, Union
from urllib.parse import urlparse
import urllib.parse
import urllib.request

import numpy as np
import rasterio
Expand Down Expand Up @@ -258,8 +259,8 @@ def _get_rio_env(self, dataset_address: str) -> Dict[str, Any]:
def _build_xarray_dict(self, **kwargs):
logger.warning(">>>>>>>>>>>>>>>>>>")
result = XarrayDict()
product_path = urlparse(self.location).path
logger.warning("### product_path: %s" % product_path)
url_path = urllib.parse.urlparse(self.location).path
product_path = urllib.request.url2pathname(url_path)
for root, _dirs, filenames in os.walk(product_path):
logger.warning("### root: %s filenames: %s" % (root, filenames))
for filename in filenames:
Expand Down
6 changes: 5 additions & 1 deletion tests/units/test_eoproduct.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import shutil
from pathlib import Path
from tempfile import TemporaryDirectory
import urllib.request

import numpy as np
import xarray as xr
Expand Down Expand Up @@ -277,7 +278,7 @@ def test_build_xarray_dict(self):
product = EOProduct(
self.provider, self.eoproduct_props, productType=self.product_type
)
product.location = f"file://{tmp_dir}"
product.location = "file:" + urllib.request.pathname2url(tmp_dir)
self.populate_directory_with_heterogeneous_files(tmp_dir)

xarray_dict = product._build_xarray_dict()
Expand All @@ -287,3 +288,6 @@ def test_build_xarray_dict(self):
for key, value in xarray_dict.items():
self.assertIn(Path(key).suffix, {".nc", ".jp2"})
self.assertIsInstance(value, xr.Dataset)

for ds in xarray_dict.values():
ds.close()
8 changes: 6 additions & 2 deletions tests/units/test_eoproduct_driver_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,19 @@ def test_driver_get_local_dataset_address_ok(self):
with self._filesystem_product() as product:
band = "B01"
address = self.product.driver.get_data_address(product, band)
self.assertEqual(address, self.local_band_file)
self.assertEqual(
os.path.normcase(address), os.path.normcase(self.local_band_file)
)

def test_driver_get_local_grib_dataset_address_ok(self):
"""Driver returns a good address for a grib file"""
with self._grib_product() as product:

address = self.product.driver.get_data_address(product, TEST_GRIB_FILENAME)

self.assertEqual(address, TEST_GRIB_FILE_PATH)
self.assertEqual(
os.path.normcase(address), os.path.normcase(TEST_GRIB_FILE_PATH)
)

def test_driver_get_http_remote_dataset_address_fail(self):
"""Driver must raise UnsupportedDatasetAddressScheme if location scheme is http or https"""
Expand Down
4 changes: 3 additions & 1 deletion tests/units/test_eoproduct_driver_sentinel2_l1c.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ def test_driver_get_local_dataset_address_ok(self):
with self._filesystem_product() as product:
band = "B01"
address = self.product.driver.get_data_address(product, band)
self.assertEqual(address, self.local_band_file)
self.assertEqual(
os.path.normcase(address), os.path.normcase(self.local_band_file)
)

@mock_aws
def test_driver_get_amazon_s3_remote_dataset_address_ok(self):
Expand Down

0 comments on commit e9b3e3e

Please sign in to comment.