Skip to content

Commit

Permalink
fix tests (#97)
Browse files Browse the repository at this point in the history
 fix tests

Co-authored-by: Harrison Cook <harrison.cook@ecmwf.int>
  • Loading branch information
floriankrb and HCookie authored Oct 25, 2024
1 parent 70528ea commit 75e8c2e
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 16 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Keep it human-readable, your future self will thank you!
### Changed

- Bugfix in `auto_adjust`
- Improve tests

### Added

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ dynamic = [
]
dependencies = [
"anemoi-transform>=0.0.5",
"anemoi-utils[provenance]>=0.4.1",
"anemoi-utils[provenance]>=0.4.2",
"cfunits",
"numpy",
"pyyaml",
Expand Down
4 changes: 1 addition & 3 deletions src/anemoi/datasets/commands/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@


def task(what, options, *args, **kwargs):
"""
Make sure `import Creator` is done in the sub-processes, and not in the main one.
"""
"""Make sure `import Creator` is done in the sub-processes, and not in the main one."""

now = datetime.datetime.now()
LOG.info(f"🎬 Task {what}({args},{kwargs}) starting")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,8 @@ def __repr__(self):
)

def __getitem__(self, i):
"""
Get a 2D field from the variable
"""
"""Get a 2D field from the variable"""

if i >= self.length:
raise IndexError(i)

Expand Down
4 changes: 2 additions & 2 deletions src/anemoi/datasets/data/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ class Dataset:
arguments = {}

def mutate(self) -> "Dataset":
"""
Give an opportunity to a subclass to return a new Dataset
"""Give an opportunity to a subclass to return a new Dataset
object of a different class, if needed.
"""

return self

def swap_with_parent(self, parent):
Expand Down
24 changes: 17 additions & 7 deletions tests/create/test_create.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@

TEST_DATA_ROOT = "https://object-store.os-api.cci1.ecmwf.int/ml-tests/test-data/anemoi-datasets/create"

UPLOAD_EXE = os.path.realpath(os.path.join(os.path.dirname(__file__), "../../tools/upload-sample-dataset.py"))


HERE = os.path.dirname(__file__)
# find_yamls
Expand Down Expand Up @@ -56,11 +58,9 @@ def get_data(self, args, kwargs, path):
ds = original_from_source("mars", *args, **kwargs)
ds.save(upload_path)
print(f"Mockup: Saving to {upload_path} for {args}, {kwargs}")
exe = os.path.realpath(os.path.join(os.path.dirname(__file__), "../../tools/upload-sample-dataset.py"))
print()
print("⚠️ To upload the test data, run this:")
print()
print(f"{exe} {upload_path} anemoi-datasets/create/{os.path.basename(path)} --overwrite")
print(f"python3 {UPLOAD_EXE} {upload_path} anemoi-datasets/create/{os.path.basename(path)} --overwrite")
print()
exit(1)
raise ValueError("Test data is missing")
Expand Down Expand Up @@ -196,15 +196,15 @@ def compare_statistics(ds1, ds2):
class Comparer:
def __init__(self, name, output_path=None, reference_path=None):
self.name = name
self.output = output_path or os.path.join(name + ".zarr")
self.output_path = output_path or os.path.join(name + ".zarr")
self.reference_path = reference_path
print(f"Comparing {self.output} and {self.reference_path}")
print(f"Comparing {self.output_path} and {self.reference_path}")

self.z_output = open_zarr(self.output)
self.z_output = open_zarr(self.output_path)
self.z_reference = open_zarr(self.reference_path)

self.z_reference["data"]
self.ds_output = open_dataset(self.output)
self.ds_output = open_dataset(self.output_path)
self.ds_reference = open_dataset(self.reference_path)

def compare(self):
Expand All @@ -215,6 +215,16 @@ def compare(self):
print("\n".join(errors))

if errors:
print()
print("⚠️ To update the test reference metadata, run this:")
print(
f"python3 {UPLOAD_EXE} {self.output_path}/.zattrs anemoi-datasets/create/{self.name}.zarr/.zattrs --overwrite"
)
print()
print()
print("⚠️ To update the reference data, run this:")
print(f"anemoi-datasets copy {self.output_path} {self.reference_path} --overwrite")
print()
raise AssertionError("Comparison failed")

compare_datasets(self.ds_output, self.ds_reference)
Expand Down

0 comments on commit 75e8c2e

Please sign in to comment.