Skip to content

Fix running unit tests locally #68

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

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -175,3 +175,5 @@ fair-mast-*.e*
fair-mast-*.o*
.s5cfg*
*.db

uv.lock
8 changes: 7 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ dependencies = {file = ["requirements.txt"]}
dev = [
"pytest",
"pytest-mock",
"pytest-env",
"ruff"
]

Expand All @@ -36,4 +37,9 @@ mpi = [
[project.urls]

[tool.ruff]
exclude = [".venv", "notebooks"]
exclude = [".venv", "notebooks"]

[tool.pytest_env]
UDA_HOST = "uda2.mast.l"
UDA_META_PLUGINNAME = "MASTU_DB"
UDA_METANEW_PLUGINNAME = "MAST_DB"
12 changes: 8 additions & 4 deletions src/core/writer.py
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the fix I was using, but in the docs: https://docs.xarray.dev/en/stable/generated/xarray.Dataset.to_zarr.html

It states that zarr_version is being depreciated? I'm not sure if this is a wider zarr bug

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Swapped back to zarr_version for now.

Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ def _convert_dict_attrs_to_json(self, dataset: xr.Dataset):

class ZarrDatasetWriter(DatasetWriter):
def __init__(
self, output_path: str, mode: str = "single", zarr_format: int = 2, **kwargs
self, output_path: str, mode: str = "single", zarr_version: int = 2, **kwargs
):
super().__init__(output_path)
self.version = zarr_format
self.version = zarr_version
self.mode = mode

@property
Expand All @@ -73,15 +73,19 @@ def write(self, file_name: str, group_name: str, dataset: xr.Dataset):
def _write_single_zarr(self, file_name: str, name: str, dataset: xr.Dataset):
file_name = self.output_path / file_name
dataset.to_zarr(
file_name, group=name, mode="w", zarr_format=self.version, consolidated=True
file_name,
group=name,
mode="w",
zarr_version=self.version,
consolidated=True,
)
zarr.consolidate_metadata(file_name)

def _write_multi_zarr(self, file_name: str, name: str, dataset: xr.Dataset):
file_name = Path(file_name)
path = self.output_path / f"{file_name.stem}/{name}.zarr"
path.parent.mkdir(exist_ok=True, parents=True)
dataset.to_zarr(path, mode="a", zarr_format=self.version, consolidated=True)
dataset.to_zarr(path, mode="a", zarr_version=self.version, consolidated=True)
zarr.consolidate_metadata(path)


Expand Down
13 changes: 12 additions & 1 deletion tests/core/test_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,18 @@
from src.core.load import SALLoader, UDALoader, ZarrLoader


@pytest.mark.skip(reason="Pyuda client unavailable")
def try_uda():
try:
import pyuda

client = pyuda.Client()
client.get("ip", 30421)
return False
except Exception:
return True


@pytest.mark.skipif(try_uda(), reason="Pyuda client unavailable")
def test_load_uda():
loader = UDALoader()
signal = loader.load(30420, "ip")
Expand Down