-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1083 from xcube-dev/konstntokas-xxx-allow_remote_…
…https_lazy_access_netcdf Allow to open netcdf file from remote HTTPS server
- Loading branch information
Showing
4 changed files
with
55 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# Copyright (c) 2018-2024 by xcube team and contributors | ||
# Permissions are hereby granted under the terms of the MIT License: | ||
# https://opensource.org/licenses/MIT. | ||
|
||
import unittest | ||
from unittest.mock import patch | ||
|
||
import xarray as xr | ||
import numpy as np | ||
|
||
from xcube.core.store import new_data_store | ||
|
||
|
||
class HttpsNetcdfTest(unittest.TestCase): | ||
""" | ||
This class tests the access of a NetCDF file from a remote HTTPS server. | ||
""" | ||
|
||
@patch("xarray.open_dataset") | ||
def test_open_netcdf_https(self, mock_open_dataset): | ||
# set-up mock | ||
mock_data = { | ||
"temperature": (("time", "x", "y"), np.random.rand(5, 5, 5)), | ||
"precipitation": (("time", "x", "y"), np.random.rand(5, 5, 5)), | ||
} | ||
mock_ds = xr.Dataset(mock_data) | ||
mock_open_dataset.return_value = mock_ds | ||
|
||
fs_path = "mockfile.nc" | ||
store = new_data_store("https", root="root.de") | ||
ds = store.open_data(fs_path) | ||
|
||
mock_open_dataset.assert_called_once_with( | ||
"https://root.de/mockfile.nc#mode=bytes", engine="netcdf4" | ||
) | ||
self.assertTrue("temperature" in ds) | ||
self.assertTrue("precipitation" in ds) | ||
self.assertEqual(ds["temperature"].shape, (5, 5, 5)) | ||
self.assertEqual(ds["precipitation"].shape, (5, 5, 5)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters