Skip to content

Commit

Permalink
fix Windows tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ocefpaf committed Aug 15, 2024
1 parent 170bd2f commit 3213f6d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 23 deletions.
15 changes: 10 additions & 5 deletions compliance_checker/protocols/zarr.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import platform
import zipfile
from pathlib import Path
from urllib.parse import urlparse
Expand All @@ -6,7 +7,11 @@

from compliance_checker.protocols import netcdf

#

def _fix_windows_slashes(zarr_url):
if platform.system() == "Windows":
zarr_url = zarr_url.replace("///", "//")

Check warning on line 13 in compliance_checker/protocols/zarr.py

View check run for this annotation

Codecov / codecov/patch

compliance_checker/protocols/zarr.py#L13

Added line #L13 was not covered by tests
return zarr_url


def is_zarr(url):
Expand Down Expand Up @@ -55,10 +60,9 @@ def as_zarr(url):
pr = urlparse(str(url))

if "mode=nczarr" in pr.fragment:
if pr.netloc:
return str(url) # already valid nczarr url
elif pr.scheme == "file":
return str(url) # already valid nczarr url
if pr.netloc or pr.scheme == "file":
url = _fix_windows_slashes(url)
return url

zarr_url = Path(
url2pathname(pr.path),
Expand All @@ -78,4 +82,5 @@ def as_zarr(url):
url_base = url if mode == "s3" else zarr_url.as_uri()

zarr_url = f"{url_base}#mode=nczarr,{mode}"
zarr_url = _fix_windows_slashes(zarr_url)
return zarr_url
5 changes: 0 additions & 5 deletions compliance_checker/suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import inspect
import itertools
import os
import platform
import re
import subprocess
import sys
Expand Down Expand Up @@ -893,10 +892,6 @@ def load_local_dataset(self, ds_str):
ds_str = self.generate_dataset(ds_str)

if zarr.is_zarr(ds_str):
if platform.system() != "Linux":
print(
f"WARNING: {platform.system()} OS detected. NCZarr is not officially supported for your OS as of when this API was written. Your mileage may vary.",
)
return Dataset(zarr.as_zarr(ds_str))

if netcdf.is_netcdf(ds_str):
Expand Down
24 changes: 11 additions & 13 deletions compliance_checker/tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@

from .conftest import datadir, static_files

if platform.system() == "Windows":
ncconfig = ["bash", f"{os.environ['CONDA_PREFIX']}\\Library\\bin\\nc-config"]
on_windows = platform.system() == "Windows"

if on_windows:
ncconfig = ["sh", f"{os.environ['CONDA_PREFIX']}\\Library\\bin\\nc-config"]
else:
ncconfig = ["nc-config"]

Expand Down Expand Up @@ -236,18 +238,9 @@ def _check_libnetcdf_version():
< 8.0
)

# TODO uncomment the third parameter once S3 support is working
@pytest.mark.skipif(
_check_libnetcdf_version(),
reason="NCZarr support was not available until netCDF version 4.8.0. Please upgrade to the latest libnetcdf version to test this functionality",
)
@pytest.mark.skipif(
subprocess.check_output(ncconfig + ["--has-nczarr"]) != b"yes\n",
reason="NCZarr is not officially supported for your OS as of when this API was written",
)
@pytest.mark.skipif(
subprocess.check_output(["nc-config", "--has-nczarr"]) != b"yes\n",
reason="NCZarr support was not built with this netCDF version",
reason="NCZarr is not available.",
)
@pytest.mark.parametrize(
"zarr_url",
Expand All @@ -256,7 +249,12 @@ def _check_libnetcdf_version():
str(datadir / "zip.zarr"),
# "s3://hrrrzarr/sfc/20210408/20210408_10z_anl.zarr#mode=nczarr,s3"
],
ids=["local_file", "zip_file"], # ,'s3_url'
ids=[
"local_file",
"zip_file",
# TODO uncomment once S3 support is working.
# "s3_url",
],
)
def test_nczarr_pass_through(self, zarr_url):
"""
Expand Down

0 comments on commit 3213f6d

Please sign in to comment.