Skip to content

Commit

Permalink
Update pytests: Fail access-om2 tests for unknown resolutions and add…
Browse files Browse the repository at this point in the history
… default metadata schema
  • Loading branch information
jo-basevi committed Apr 2, 2024
1 parent 31ed470 commit f787291
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 13 deletions.
12 changes: 9 additions & 3 deletions test/test_access_om2_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ def set_resolution(self):
if res in self.branch_name:
self.resolution = res
return
# TODO Should unknown resolutions fail the pytests or be ignored?

pytest.fail(
f"Branch name {self.branch_name} has an unknown resolution. " +
f"Current supported resolutions: {', '.join(resolutions)}"
)


@pytest.fixture(scope="class")
Expand Down Expand Up @@ -88,7 +92,6 @@ def test_restart_period(self, branch, control_path):
accessom2_nml = f90nml.read(accessom2_nml_path)
restart_period = accessom2_nml['date_manager_nml']['restart_period']

# TODO: Here it's fixed, should it be a set of accepted values?
if branch.resolution == '1deg':
expected_period = [5, 0, 0]
elif branch.resolution == '025deg':
Expand All @@ -102,7 +105,10 @@ def test_restart_period(self, branch, control_path):
else:
expected_period = [0, 3, 0]
else:
return
pytest.fail(
f"The expected restart period is not defined for given "
f"resolution: {branch.resolution}"
)
assert restart_period == expected_period

def test_metadata_keywords(self, metadata):
Expand Down
29 changes: 19 additions & 10 deletions test/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,17 @@

from pathlib import Path
import re
import warnings

import pytest
import requests
import jsonschema
import yaml

# #TODO: Pointing to main, allows testing to point to recent schema versions,
# though makes this test code less robust.
# Could point to a commit - then if schema_version was a version not defined,
# at that commit, use the default schema version.
BASE_SCHEMA_URL = "https://raw.githubusercontent.com/ACCESS-NRI/schema/main/au.org.access-nri/model/output/experiment-metadata/"
BASE_SCHEMA_URL = "https://raw.githubusercontent.com/ACCESS-NRI/schema"
BASE_SCHEMA_PATH = "au.org.access-nri/model/output/experiment-metadata"
DEFAULT_SCHEMA_VERSION = "1-0-0"
DEFAULT_SCHEMA_COMMIT = "bfc15e3c6fa20d492ccfa0c4706805d64c531e7c"


@pytest.fixture(scope="class")
Expand Down Expand Up @@ -145,13 +144,23 @@ def test_no_scripts_in_top_level_directory(self, control_path):
)

def test_validate_metadata(self, metadata):
# Schema URL
schema_version = metadata.get("schema_version", DEFAULT_SCHEMA_VERSION)
url = f"{BASE_SCHEMA_URL}/{schema_version}.json"

# Get schema from Github
schema_version = metadata.get("schema_version", DEFAULT_SCHEMA_VERSION)
schema_path = f"{BASE_SCHEMA_PATH}/{schema_version}.json"

url = f"{BASE_SCHEMA_URL}/main/{schema_path}"
response = requests.get(url)
assert response.status_code == 200
if response.status_code != 200:
# Use default schema
warnings.warn(
f"Failed to retrieve schema from url: {url}\n" +
f"Defaulting to schema version: {DEFAULT_SCHEMA_VERSION}"
)
schema_path = f"{BASE_SCHEMA_PATH}/{DEFAULT_SCHEMA_VERSION}.json"

url = f"{BASE_SCHEMA_URL}/{DEFAULT_SCHEMA_COMMIT}/{schema_path}"
response = requests.get(url)
assert response.status_code == 200
schema = response.json()

# In schema version (1-0-0), required fields are name, experiment_uuid,
Expand Down

0 comments on commit f787291

Please sign in to comment.