Skip to content

Commit 4ff470e

Browse files
committed
Updated tests per review
1 parent bc476db commit 4ff470e

6 files changed

Lines changed: 41 additions & 14 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Previously, loading a schema whose version existed only in the prerelease cache
1111
- Removed the `check_prerelease` parameter from `load_schema_version()`, `load_schema()`, `from_string()`, and `from_dataframes()` in `hed_schema_io.py`.
1212
- Removed the parameter from `SchemaLoader` (base class) and all subclasses (`SchemaLoaderXML`, `SchemaLoaderWiki`, `SchemaLoaderJSON`, `SchemaLoaderDF`).
1313
- `get_hed_version_path()` in `hed_cache.py` now always searches both regular and prerelease directories (regular first).
14-
- `get_hed_versions()` in `hed_cache.py` now defaults to `check_prerelease=True`; the compliance checker explicitly passes `False` to compare against released versions only.
14+
- `get_hed_versions()` in `hed_cache.py` now defaults to `check_prerelease=True`. **This is a silent API change**: external callers that omitted `check_prerelease` will now receive prerelease versions. Internal callers that need released-only versions (compliance checker, `deprecatedFrom` validation, hedId comparison) explicitly pass `check_prerelease=False`.
1515
- Default schema version is now resolved dynamically from the cache (highest released version) instead of being hardcoded, so new schema releases no longer require a code change.
1616
- `check_schema_loading.py` simplified — removed `_is_prerelease_partner()` helper.
1717
- `run_loading_check()` now raises `ValueError` immediately for mutually exclusive flag combinations (`prerelease_only` + `exclude_prereleases`, or `library_filter` + `standard_only`), consistent with the existing CLI-level validation.

hed/schema/hed_schema_io.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -358,12 +358,12 @@ def _load_schema_version_sub(xml_version, schema_namespace="", xml_folder=None,
358358
"""
359359
if not xml_version:
360360
versions = hed_cache.get_hed_versions(xml_folder, check_prerelease=False)
361-
if versions:
361+
if isinstance(versions, list) and versions:
362362
xml_version = versions[0]
363363
else:
364364
raise HedFileError(
365365
HedExceptions.FILE_NOT_FOUND,
366-
"No HED schema versions found in cache. Ensure schemas are installed or cached.",
366+
"No HED standard schema versions found in cache. Ensure schemas are installed or cached.",
367367
"",
368368
)
369369

hed/schema/schema_validation/attribute_validators.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ def tag_is_deprecated_check(hed_schema, tag_entry, attribute_name) -> list:
194194
library_name = tag_entry.has_attribute(HedKey.InLibrary, return_value=True)
195195
if not library_name and not hed_schema.with_standard:
196196
library_name = hed_schema.library
197-
all_versions = get_hed_versions(library_name=library_name)
197+
all_versions = get_hed_versions(library_name=library_name, check_prerelease=False)
198198
if deprecated_version:
199199
library_version = schema_version_for_library(hed_schema, library_name)
200200
# Allow the current schema version even if it's prerelease (not yet in known versions)

hed/schema/schema_validation/hed_id_validator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def __init__(self, hed_schema):
5050
@staticmethod
5151
def _get_previous_version(version, library):
5252
current_version = Version(version)
53-
all_schema_versions = get_hed_versions(library_name=library)
53+
all_schema_versions = get_hed_versions(library_name=library, check_prerelease=False)
5454
for old_version in all_schema_versions:
5555
if Version(old_version) < current_version:
5656
prev_version = old_version

spec_tests/test_hed_cache.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -79,15 +79,20 @@ def test_get_hed_versions_library(self):
7979
self.assertTrue(len(cached_versions) > 0)
8080

8181
def test_get_hed_versions_library_prerelease(self):
82-
all_versions = hed_cache.get_hed_versions(self.hed_cache_dir, library_name="score")
83-
released_only = hed_cache.get_hed_versions(self.hed_cache_dir, library_name="score", check_prerelease=False)
84-
self.assertIsInstance(all_versions, list)
85-
self.assertTrue(len(all_versions) > 0)
86-
self.assertGreater(
87-
len(all_versions),
88-
len(released_only),
89-
"Default (prerelease included) should return more versions than released-only",
90-
)
82+
# Plant a known prerelease file so this test is deterministic
83+
prerelease_dir = os.path.join(self.hed_cache_dir, "prerelease")
84+
os.makedirs(prerelease_dir, exist_ok=True)
85+
fake_prerelease = os.path.join(prerelease_dir, "HED_score_0.0.1-alpha.1.xml")
86+
try:
87+
with open(fake_prerelease, "w") as f:
88+
f.write("")
89+
all_versions = hed_cache.get_hed_versions(self.hed_cache_dir, library_name="score")
90+
released_only = hed_cache.get_hed_versions(self.hed_cache_dir, library_name="score", check_prerelease=False)
91+
self.assertIsInstance(all_versions, list)
92+
self.assertIn("0.0.1-alpha.1", all_versions)
93+
self.assertNotIn("0.0.1-alpha.1", released_only)
94+
finally:
95+
os.remove(fake_prerelease)
9196

9297
def test_sort_version_list(self):
9398
valid_versions = ["8.1.0", "8.0.0", "8.0.0-alpha.1", "7.1.1", "1.0.0"]

tests/schema/test_hed_schema_io.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,28 @@ def test_verify_utf8_dupe(self):
8888
self.assertTrue(schema.get_tag_entry("Wßord"))
8989
self.assertTrue(schema.get_tag_entry("Wssord"))
9090

91+
def test_load_schema_version_default_resolves_latest(self):
92+
"""Test that empty version resolves to the highest released standard schema."""
93+
schema_default = load_schema_version("")
94+
self.assertIsInstance(schema_default, HedSchema)
95+
# Should be the highest standard version in the cache
96+
versions = hed_cache.get_hed_versions(check_prerelease=False)
97+
self.assertIsInstance(versions, list)
98+
self.assertEqual(schema_default.version_number, versions[0])
99+
100+
def test_load_schema_version_default_no_standard_raises(self):
101+
"""Test that empty version with only library schemas raises HedFileError."""
102+
with tempfile.TemporaryDirectory() as tmp_dir:
103+
# Copy only a library schema into the temp directory (no standard schemas)
104+
src = os.path.join(
105+
os.path.dirname(os.path.realpath(__file__)), "../../hed/schema/schema_data/HED_score_1.0.0.xml"
106+
)
107+
shutil.copy(src, tmp_dir)
108+
109+
with self.assertRaises(HedFileError) as context:
110+
load_schema_version("", xml_folder=tmp_dir)
111+
self.assertIn("No HED standard schema", str(context.exception))
112+
91113
def test_load_and_verify_tags(self):
92114
# Load 'testlib' by itself
93115
testlib = load_schema_version("testlib_2.0.0")

0 commit comments

Comments
 (0)