From 1d8a15ec5c5b8aa8fff4b075f7b14b198d6fa2fc Mon Sep 17 00:00:00 2001 From: Kay Robbins <1189050+VisLab@users.noreply.github.com> Date: Wed, 11 Mar 2026 17:03:54 -0500 Subject: [PATCH] Addressed review in #1247 --- hed/errors/error_messages.py | 4 +- hed/errors/exceptions.py | 13 ----- hed/schema/hed_schema_group.py | 4 +- hed/schema/schema_header_util.py | 10 ++-- hed/schema/schema_io/base2schema.py | 16 +++--- hed/schema/schema_io/wiki2schema.py | 2 +- hed/tools/__init__.py | 2 +- hed/tools/analysis/annotation_util.py | 52 ------------------- hed/tools/analysis/hed_tag_counts.py | 2 +- hed/tools/analysis/hed_type_factors.py | 12 +++-- hed/tools/bids/bids_dataset.py | 2 +- hed/tools/util/io_util.py | 19 ------- hed/validator/def_validator.py | 3 -- hed/validator/sidecar_validator.py | 6 ++- hed/validator/spreadsheet_validator.py | 2 +- hed/validator/util/group_util.py | 2 - spec_tests/test_hed_cache.py | 6 +-- tests/schema/test_hed_schema_io.py | 18 +++---- tests/schema/test_schema_wiki_fatal_errors.py | 6 +-- 19 files changed, 48 insertions(+), 133 deletions(-) diff --git a/hed/errors/error_messages.py b/hed/errors/error_messages.py index 70661c99..b47f0b24 100644 --- a/hed/errors/error_messages.py +++ b/hed/errors/error_messages.py @@ -272,7 +272,7 @@ def val_error_def_value_missing(tag): @hed_tag_error(ValidationErrors.HED_DEF_VALUE_EXTRA, actual_code=ValidationErrors.DEF_INVALID) def val_error_def_value_extra(tag): - return f"A def tag does not take a placeholder value, but was given one. Definition: '{tag}" + return f"A def tag does not take a placeholder value, but was given one. Definition: '{tag}'" @hed_tag_error(ValidationErrors.HED_DEF_EXPAND_UNMATCHED, actual_code=ValidationErrors.DEF_EXPAND_INVALID) @@ -287,7 +287,7 @@ def val_error_def_expand_value_missing(tag): @hed_tag_error(ValidationErrors.HED_DEF_EXPAND_VALUE_EXTRA, actual_code=ValidationErrors.DEF_EXPAND_INVALID) def val_error_def_expand_value_extra(tag): - return f"A Def-expand tag does not take a placeholder value, but was given one. Definition: '{tag}" + return f"A Def-expand tag does not take a placeholder value, but was given one. Definition: '{tag}'" @hed_tag_error(ValidationErrors.HED_TOP_LEVEL_TAG, actual_code=ValidationErrors.TAG_GROUP_ERROR) diff --git a/hed/errors/exceptions.py b/hed/errors/exceptions.py index e77486e4..d2f7d71e 100644 --- a/hed/errors/exceptions.py +++ b/hed/errors/exceptions.py @@ -18,20 +18,8 @@ class HedExceptions: INVALID_FILE_FORMAT = "INVALID_FILE_FORMAT" # These are actual schema issues, not that the file cannot be found or parsed - SCHEMA_HEADER_MISSING = "SCHEMA_HEADER_INVALID" SCHEMA_HEADER_INVALID = "SCHEMA_HEADER_INVALID" - SCHEMA_UNKNOWN_HEADER_ATTRIBUTE = "SCHEMA_HEADER_INVALID" - SCHEMA_LIBRARY_INVALID = "SCHEMA_LIBRARY_INVALID" - BAD_HED_LIBRARY_NAME = "SCHEMA_LIBRARY_INVALID" - BAD_WITH_STANDARD = "SCHEMA_LIBRARY_INVALID" - BAD_WITH_STANDARD_MULTIPLE_VALUES = "SCHEMA_LOAD_FAILED" - ROOTED_TAG_INVALID = "SCHEMA_LIBRARY_INVALID" - ROOTED_TAG_HAS_PARENT = "SCHEMA_LIBRARY_INVALID" - ROOTED_TAG_DOES_NOT_EXIST = "SCHEMA_LIBRARY_INVALID" - IN_LIBRARY_IN_UNMERGED = "SCHEMA_LIBRARY_INVALID" - INVALID_LIBRARY_PREFIX = "SCHEMA_LIBRARY_INVALID" - SCHEMA_VERSION_INVALID = "SCHEMA_VERSION_INVALID" SCHEMA_SECTION_MISSING = "SCHEMA_SECTION_MISSING" SCHEMA_INVALID = "SCHEMA_INVALID" @@ -44,7 +32,6 @@ class HedExceptions: WIKI_LINE_INVALID = "WIKI_LINE_INVALID" HED_SCHEMA_NODE_NAME_INVALID = "HED_SCHEMA_NODE_NAME_INVALID" - SCHEMA_DUPLICATE_PREFIX = "SCHEMA_LOAD_FAILED" SCHEMA_DUPLICATE_LIBRARY = "SCHEMA_LIBRARY_INVALID" BAD_COLUMN_NAMES = "BAD_COLUMN_NAMES" diff --git a/hed/schema/hed_schema_group.py b/hed/schema/hed_schema_group.py index 99567ae3..368782a4 100644 --- a/hed/schema/hed_schema_group.py +++ b/hed/schema/hed_schema_group.py @@ -43,8 +43,8 @@ def __init__(self, schema_list, name=""): schema_prefixes = [hed_schema._namespace for hed_schema in schema_list] if len(set(schema_prefixes)) != len(schema_prefixes): raise HedFileError( - HedExceptions.SCHEMA_DUPLICATE_PREFIX, - "Multiple schema share the same tag name_prefix. This is not allowed.", + HedExceptions.SCHEMA_LOAD_FAILED, + "Multiple schema share the same tag name_prefix so schema cannot be loaded.", filename=self.name, ) self._schemas = {hed_schema._namespace: hed_schema for hed_schema in schema_list} diff --git a/hed/schema/schema_header_util.py b/hed/schema/schema_header_util.py index 4e157ba9..507cfc60 100644 --- a/hed/schema/schema_header_util.py +++ b/hed/schema/schema_header_util.py @@ -17,9 +17,9 @@ def validate_library_name(library_name): """ for i, character in enumerate(library_name): if not character.isalpha(): - return f"Non alpha character '{character}' at position {i} in '{library_name}'" + return f"Non alpha character '{character}' at position {i} in library name '{library_name}'" if character.isupper(): - return f"Non lowercase character '{character}' at position {i} in '{library_name}'" + return f"Non lowercase character '{character}' at position {i} in library name '{library_name}'" def validate_version_string(version_string): @@ -41,7 +41,7 @@ def validate_version_string(version_string): header_attribute_validators = { constants.VERSION_ATTRIBUTE: (validate_version_string, HedExceptions.SCHEMA_VERSION_INVALID), - constants.LIBRARY_ATTRIBUTE: (validate_library_name, HedExceptions.BAD_HED_LIBRARY_NAME), + constants.LIBRARY_ATTRIBUTE: (validate_library_name, HedExceptions.SCHEMA_LIBRARY_INVALID), } @@ -61,7 +61,7 @@ def validate_present_attributes(attrib_dict, name): """ if constants.WITH_STANDARD_ATTRIBUTE in attrib_dict and constants.LIBRARY_ATTRIBUTE not in attrib_dict: raise HedFileError( - HedExceptions.BAD_WITH_STANDARD, + HedExceptions.SCHEMA_LIBRARY_INVALID, "withStandard header attribute found, but no library attribute is present", name, ) @@ -93,7 +93,7 @@ def validate_attributes(attrib_dict, name): raise HedFileError(error_code, had_error, name) if attribute_name not in valid_header_attributes: raise HedFileError( - HedExceptions.SCHEMA_UNKNOWN_HEADER_ATTRIBUTE, + HedExceptions.SCHEMA_HEADER_INVALID, f"Unknown attribute {attribute_name} found in header line", filename=name, ) diff --git a/hed/schema/schema_io/base2schema.py b/hed/schema/schema_io/base2schema.py index 1d9b1d18..baa74579 100644 --- a/hed/schema/schema_io/base2schema.py +++ b/hed/schema/schema_io/base2schema.py @@ -63,14 +63,14 @@ def __init__(self, filename, schema_as_string=None, schema=None, file_format=Non self.appending_to_schema = True if not self._schema.with_standard: raise HedFileError( - HedExceptions.SCHEMA_DUPLICATE_PREFIX, + HedExceptions.SCHEMA_LOAD_FAILED, "Loading multiple normal schemas as a merged one with the same namespace. " "Ensure schemas have the withStandard header attribute set", self.name, ) elif with_standard != self._schema.with_standard: raise HedFileError( - HedExceptions.BAD_WITH_STANDARD_MULTIPLE_VALUES, + HedExceptions.SCHEMA_LOAD_FAILED, f"Merging schemas requires same withStandard value ({with_standard} != {self._schema.with_standard}).", self.name, ) @@ -125,7 +125,7 @@ def _load(self): base_version = load_schema_version(self._schema.with_standard, check_prerelease=self.check_prerelease) except HedFileError as e: raise HedFileError( - HedExceptions.BAD_WITH_STANDARD, + HedExceptions.SCHEMA_LIBRARY_INVALID, message=f"Cannot load withStandard schema '{self._schema.with_standard}'", filename=e.filename, ) from e @@ -194,28 +194,28 @@ def find_rooted_entry(tag_entry, schema, loading_merged): if rooted_tag is not None: if not schema.with_standard: raise HedFileError( - HedExceptions.ROOTED_TAG_INVALID, + HedExceptions.SCHEMA_ATTRIBUTE_INVALID, f"Rooted tag attribute found on '{tag_entry.short_tag_name}' in a standard schema.", schema.name, ) if not isinstance(rooted_tag, str): raise HedFileError( - HedExceptions.ROOTED_TAG_INVALID, + HedExceptions.SCHEMA_LIBRARY_INVALID, f"Rooted tag '{tag_entry.short_tag_name}' is not a string.\"", schema.name, ) if tag_entry.parent_name and not loading_merged: raise HedFileError( - HedExceptions.ROOTED_TAG_INVALID, + HedExceptions.SCHEMA_LIBRARY_INVALID, f"Found rooted tag '{tag_entry.short_tag_name}' as a non root node.", schema.name, ) if not tag_entry.parent_name and loading_merged: raise HedFileError( - HedExceptions.ROOTED_TAG_INVALID, + HedExceptions.SCHEMA_LIBRARY_INVALID, f"Found rooted tag '{tag_entry.short_tag_name}' as a root node in a merged schema.", schema.name, ) @@ -223,7 +223,7 @@ def find_rooted_entry(tag_entry, schema, loading_merged): rooted_entry = schema.tags.get(rooted_tag) if not rooted_entry or rooted_entry.has_attribute(constants.HedKey.InLibrary): raise HedFileError( - HedExceptions.ROOTED_TAG_DOES_NOT_EXIST, + HedExceptions.LIBRARY_SCHEMA_INVALID, f"Rooted tag '{tag_entry.short_tag_name}' not found in paired standard schema", schema.name, ) diff --git a/hed/schema/schema_io/wiki2schema.py b/hed/schema/schema_io/wiki2schema.py index 1695ef35..3fa70181 100644 --- a/hed/schema/schema_io/wiki2schema.py +++ b/hed/schema/schema_io/wiki2schema.py @@ -77,7 +77,7 @@ def _get_header_attributes(self, file_data): hed_attributes = self._get_header_attributes_internal(line[len(wiki_constants.HEADER_LINE_STRING) :]) return hed_attributes msg = f"First line of file should be HED, instead found: {line}" - raise HedFileError(HedExceptions.SCHEMA_HEADER_MISSING, msg, filename=self.name) + raise HedFileError(HedExceptions.SCHEMA_HEADER_INVALID, msg, filename=self.name) def _parse_data(self): wiki_lines_by_section = self._split_lines_into_sections(self.input_data) diff --git a/hed/tools/__init__.py b/hed/tools/__init__.py index 03cbbb2e..6b0c8dfc 100644 --- a/hed/tools/__init__.py +++ b/hed/tools/__init__.py @@ -20,7 +20,7 @@ from .bids.bids_util import parse_bids_filename from .util.data_util import get_new_dataframe, get_value_dict, replace_values, reorder_columns -from .util.io_util import check_filename, clean_filename, extract_suffix_path, get_file_list, make_path +from .util.io_util import check_filename, clean_filename, extract_suffix_path, get_file_list from .util.io_util import get_path_components from .analysis.annotation_util import ( diff --git a/hed/tools/analysis/annotation_util.py b/hed/tools/analysis/annotation_util.py index 0db39184..ccf02904 100644 --- a/hed/tools/analysis/annotation_util.py +++ b/hed/tools/analysis/annotation_util.py @@ -367,37 +367,6 @@ def _flatten_val_col(col_key, col_dict) -> tuple[list[str], list[str], list[str] return [col_key], ["n/a"], [description], [tags] -# def _get_row_tags(row, description_tag=True): -# """ Return the HED string associated with row, possibly without the description. -# -# Parameters: -# row (DataSeries): Pandas data frame containing a row of a tagging spreadsheet. -# description_tag (bool): If True, include any Description tags in the returned string. -# -# Returns: -# str: A HED string extracted from the row. -# str: A string representing the description (without the Description tag). -# -# Notes: -# If description_tag is True the entire tag string is included with description. -# If there was a description extracted, it is appended to any existing description. -# -# """ -# remainder, extracted = extract_tags(row['HED'], 'Description/') -# if description_tag: -# tags = row["HED"] -# else: -# tags = remainder -# -# if row["description"] != 'n/a': -# description = row["description"] -# else: -# description = "" -# if extracted: -# description = " ".join([description, extracted]) -# return tags, description - - def _get_value_entry(hed_entry, description_entry, description_tag=True): """Return a HED dictionary representing a value entry in a HED tagging spreadsheet. @@ -473,24 +442,3 @@ def _update_cat_dict(cat_dict, value_entry, hed_entry, description_entry, descri hed_part = cat_dict.get("HED", {}) hed_part[value_entry] = value_dict["HED"] cat_dict["HED"] = hed_part - - -# def _update_remainder(remainder, update_piece): -# """ Update remainder with update piece. -# -# Parameters: -# remainder (str): A tag string without trailing comma. -# update_piece (str): A tag string to be appended. -# -# Returns: -# str: A concatenation of remainder and update_piece, paying attention to separating commas. -# -# """ -# if not update_piece: -# return remainder -# elif not remainder: -# return update_piece -# elif remainder.endswith(')') or update_piece.startswith('('): -# return remainder + update_piece -# else: -# return remainder + ", " + update_piece diff --git a/hed/tools/analysis/hed_tag_counts.py b/hed/tools/analysis/hed_tag_counts.py index 19565394..3e691da6 100644 --- a/hed/tools/analysis/hed_tag_counts.py +++ b/hed/tools/analysis/hed_tag_counts.py @@ -143,7 +143,7 @@ def merge_tag_dicts(self, other_dict): continue for value, val_count in count.value_dict.items(): if value in self.tag_dict[tag].value_dict: - self.tag_dict[tag].value_dict[value] = self.tag_dict[tag].value_dict + val_count + self.tag_dict[tag].value_dict[value] = self.tag_dict[tag].value_dict[value] + val_count else: self.tag_dict[tag].value_dict[value] = val_count diff --git a/hed/tools/analysis/hed_type_factors.py b/hed/tools/analysis/hed_type_factors.py index dce6e742..e55a5b78 100644 --- a/hed/tools/analysis/hed_type_factors.py +++ b/hed/tools/analysis/hed_type_factors.py @@ -1,7 +1,7 @@ """Manager for factor information for a columnar file.""" import pandas as pd -from hed.errors.exceptions import HedFileError +from hed.errors.exceptions import HedExceptions, HedFileError class HedTypeFactors: @@ -58,15 +58,17 @@ def get_factors(self, factor_encoding="one-hot"): sum_factors = factors.sum(axis=1) if factor_encoding == "categorical" and sum_factors.max() > 1: raise HedFileError( - "MultipleFactorSameEvent", + HedExceptions.BAD_PARAMETERS, f"{self.type_value} has multiple occurrences at index {sum_factors.idxmax()}", "", ) elif factor_encoding == "categorical": return self._one_hot_to_categorical(factors, levels) else: - raise ValueError( - "BadFactorEncoding", f"{factor_encoding} is not in the allowed encodings: {str(self.ALLOWED_ENCODINGS)}" + raise HedFileError( + HedExceptions.BAD_PARAMETERS, + f"{factor_encoding} is not in the allowed encodings: {str(self.ALLOWED_ENCODINGS)}", + "", ) def _one_hot_to_categorical(self, factors, levels): @@ -77,7 +79,7 @@ def _one_hot_to_categorical(self, factors, levels): levels (list): List of categorical columns to convert. Return: - pd.ataFrame: Contains one-hot representation of requested levels. + pd.DataFrame: Contains one-hot representation of requested levels. """ df = pd.DataFrame("n/a", index=range(len(factors.index)), columns=[self.type_value]) diff --git a/hed/tools/bids/bids_dataset.py b/hed/tools/bids/bids_dataset.py index 1a90bb7f..0a5ffb15 100644 --- a/hed/tools/bids/bids_dataset.py +++ b/hed/tools/bids/bids_dataset.py @@ -108,7 +108,7 @@ def validate(self, check_for_warnings=False, schema=None): return [ { "code": "SCHEMA_LOAD_FAILED", - "message": "BIDS dataset_description.json has invalid HEDVersion and passed schema was invalid}", + "message": "BIDS dataset_description.json has invalid HEDVersion and passed schema was invalid", } ] diff --git a/hed/tools/util/io_util.py b/hed/tools/util/io_util.py index c2cd0f36..ae900a2c 100644 --- a/hed/tools/util/io_util.py +++ b/hed/tools/util/io_util.py @@ -279,25 +279,6 @@ def get_timestamp(): return now.strftime(TIME_FORMAT)[:-3] -def make_path(root_path, sub_path, filename): - """Get path for a file, verifying all components exist. - - Parameters: - root_path (str): path of the root directory. - sub_path (str): sub-path relative to the root directory. - filename (str): filename of the file. - - Returns: - str: A valid realpath for the specified file. - - Notes: This function is useful for creating files within BIDS datasets. - - """ - - dir_path = os.path.realpath(os.path.join(root_path, sub_path)) - os.makedirs(dir_path, exist_ok=True) - - def get_task_from_file(file_path): """Returns the task name entity from a BIDS-type file path. diff --git a/hed/validator/def_validator.py b/hed/validator/def_validator.py index 663dd866..3fbe7bd0 100644 --- a/hed/validator/def_validator.py +++ b/hed/validator/def_validator.py @@ -119,9 +119,6 @@ def validate_def_value_units(self, def_tag, hed_validator, allow_placeholders=Fa # Validate the def name vs the name class def_issues = hed_validator._unit_validator._check_value_class(def_tag, tag_label, report_as=None) - # def_issues += hed_validator.validate_units(def_tag, - # tag_label, - # error_code=error_code) def_contents = def_entry.get_definition(def_tag, placeholder_value=placeholder, return_copy_of_tag=True) if def_contents and def_entry.takes_value and hed_validator: diff --git a/hed/validator/sidecar_validator.py b/hed/validator/sidecar_validator.py index 5ddb88a2..95849c2e 100644 --- a/hed/validator/sidecar_validator.py +++ b/hed/validator/sidecar_validator.py @@ -14,6 +14,8 @@ from hed.errors.error_reporter import check_for_any_errors from hed.models import df_util +COLUMN_REF_PATTERN = re.compile(r"\{([a-z_\-0-9]+)\}", re.IGNORECASE) + # todo: Add/improve validation for definitions being in known columns(right now it just assumes they aren't) class SidecarValidator: @@ -95,7 +97,7 @@ def validate(self, sidecar, extra_def_dicts=None, name=None, error_handler=None) # Only do full string checks on full columns, not partial ref columns. if not is_ref_column: # TODO: Figure out why this pattern is giving lint errors. - refs = re.findall(r"\{([a-z_\-0-9]+)\}", hed_string, re.IGNORECASE) + refs = COLUMN_REF_PATTERN.findall(hed_string) refs_strings = {data.column_name: data.get_hed_strings() for data in sidecar} if "HED" not in refs_strings: refs_strings["HED"] = ["n/a"] @@ -170,7 +172,7 @@ def _validate_refs(self, sidecar, error_handler): ColumnErrors.MALFORMED_COLUMN_REF, column_name, loc, bad_symbol ) - sub_matches = re.findall(r"\{([a-z_\-0-9]+)\}", hed_string, re.IGNORECASE) + sub_matches = COLUMN_REF_PATTERN.findall(hed_string) matches.append(sub_matches) for match in sub_matches: if match not in possible_column_refs: diff --git a/hed/validator/spreadsheet_validator.py b/hed/validator/spreadsheet_validator.py index d4800962..49b49f59 100644 --- a/hed/validator/spreadsheet_validator.py +++ b/hed/validator/spreadsheet_validator.py @@ -20,7 +20,7 @@ class SpreadsheetValidator: - ONSET_TOLERANCE = 10 - 7 + ONSET_TOLERANCE = 1e-7 TEMPORAL_ANCHORS = re.compile(r"|".join(map(re.escape, ["onset", "inset", "offset", "delay"]))) def __init__(self, hed_schema): diff --git a/hed/validator/util/group_util.py b/hed/validator/util/group_util.py index 15d423ec..39c14554 100644 --- a/hed/validator/util/group_util.py +++ b/hed/validator/util/group_util.py @@ -42,7 +42,6 @@ def run_tag_level_validators(self, hed_string_obj) -> list[dict]: checks = [ self._check_group_relationships, self._duplicate_checker.check_for_duplicates, - # self.validate_duration_tags, ] for check in checks: @@ -125,7 +124,6 @@ def _check_reserved_group_requirements(self, group): if len(validation_issues) > 0: return validation_issues - # validation_errors = self._reserved_checker.check_reserved_duplicates(reserved_tags, group) return validation_issues @staticmethod diff --git a/spec_tests/test_hed_cache.py b/spec_tests/test_hed_cache.py index d9a39d64..354ca47d 100644 --- a/spec_tests/test_hed_cache.py +++ b/spec_tests/test_hed_cache.py @@ -136,15 +136,15 @@ def test_schema_load_schema_version_invalid(self): with self.assertRaises(HedFileError) as context4: load_schema_version(["8.2.0", "score_1.0.0"]) - self.assertEqual(context4.exception.args[0], HedExceptions.SCHEMA_DUPLICATE_PREFIX) + self.assertEqual(context4.exception.args[0], HedExceptions.SCHEMA_LOAD_FAILED) with self.assertRaises(HedFileError) as context5: load_schema_version(["sc:8.2.0", "sc:score_1.0.0"]) - self.assertEqual(context5.exception.args[0], HedExceptions.SCHEMA_DUPLICATE_PREFIX) + self.assertEqual(context5.exception.args[0], HedExceptions.SCHEMA_LOAD_FAILED) with self.assertRaises(HedFileError) as context6: load_schema_version(["8.1.0", "score_1.0.0"]) - self.assertEqual(context6.exception.args[0], HedExceptions.SCHEMA_DUPLICATE_PREFIX) + self.assertEqual(context6.exception.args[0], HedExceptions.SCHEMA_LOAD_FAILED) with self.assertRaises(HedFileError) as context8: load_schema_version(["8.1.0", "notreallibrary_1.0.0"]) diff --git a/tests/schema/test_hed_schema_io.py b/tests/schema/test_hed_schema_io.py index d407a3a0..50f0e832 100644 --- a/tests/schema/test_hed_schema_io.py +++ b/tests/schema/test_hed_schema_io.py @@ -692,7 +692,7 @@ class TestLoadSchemaWithPrereleasePartner(unittest.TestCase): ``load_schema_version("X.Y.Z")`` to fetch the standard schema and merges the library's tags on top of it. If version X.Y.Z only exists in the *prerelease* subdirectory of the cache (not in the regular cache root), that ``load_schema_version`` call will fail with - ``BAD_WITH_STANDARD`` unless ``check_prerelease=True`` is forwarded along the entire call + ``SCHEMA_LIBRARY_INVALID`` unless ``check_prerelease=True`` is forwarded along the entire call chain: load_schema / from_string @@ -703,7 +703,7 @@ class TestLoadSchemaWithPrereleasePartner(unittest.TestCase): → looks in {cache}/prerelease/ when True These tests exercise both the success path (flag=True → schema loads and is merged correctly) - and the default/False failure path (flag omitted or False → BAD_WITH_STANDARD is raised + and the default/False failure path (flag omitted or False → SCHEMA_LIBRARY_INVALID is raised before any merge happens). Fixture design @@ -774,7 +774,7 @@ def setUpClass(cls): # prerelease/ # HED9.9.9.xml ← only found when check_prerelease=True # Nothing is placed in {tmpdir}/ directly, so a lookup without - # check_prerelease finds no 9.9.9 and raises BAD_WITH_STANDARD. + # check_prerelease finds no 9.9.9 and raises SCHEMA_LIBRARY_INVALID. cls._tmpdir = tempfile.TemporaryDirectory() prerelease_dir = os.path.join(cls._tmpdir.name, "prerelease") os.makedirs(prerelease_dir) @@ -820,7 +820,7 @@ def test_load_schema_prerelease_partner_with_flag(self): self.assertIn("prerelease-partner-only-item", result.tags.all_names) def test_load_schema_prerelease_partner_default_raises(self): - """load_schema(...) with the default check_prerelease=False raises BAD_WITH_STANDARD + """load_schema(...) with the default check_prerelease=False raises SCHEMA_LIBRARY_INVALID when the withStandard partner exists only in the prerelease subdirectory. This confirms the default is safe: users must explicitly opt in to prerelease @@ -829,10 +829,10 @@ def test_load_schema_prerelease_partner_default_raises(self): with patch.object(hed_cache, "HED_CACHE_DIRECTORY", self._cache_dir): with self.assertRaises(HedFileError) as ctx: load_schema(self.lib_schema_path) - self.assertEqual(ctx.exception.code, HedExceptions.BAD_WITH_STANDARD) + self.assertEqual(ctx.exception.code, HedExceptions.SCHEMA_LIBRARY_INVALID) def test_load_schema_prerelease_partner_explicit_false_raises(self): - """load_schema(..., check_prerelease=False) raises BAD_WITH_STANDARD when the + """load_schema(..., check_prerelease=False) raises SCHEMA_LIBRARY_INVALID when the withStandard partner exists only in the prerelease subdirectory. Mirrors the default test but with the flag set explicitly, confirming that @@ -841,7 +841,7 @@ def test_load_schema_prerelease_partner_explicit_false_raises(self): with patch.object(hed_cache, "HED_CACHE_DIRECTORY", self._cache_dir): with self.assertRaises(HedFileError) as ctx: load_schema(self.lib_schema_path, check_prerelease=False) - self.assertEqual(ctx.exception.code, HedExceptions.BAD_WITH_STANDARD) + self.assertEqual(ctx.exception.code, HedExceptions.SCHEMA_LIBRARY_INVALID) # ------------------------------------------------------------------ # from_string() tests @@ -863,7 +863,7 @@ def test_from_string_prerelease_partner_with_flag(self): self.assertEqual(result.library, "testpre") def test_from_string_prerelease_partner_default_raises(self): - """from_string(...) with default check_prerelease=False raises BAD_WITH_STANDARD + """from_string(...) with default check_prerelease=False raises SCHEMA_LIBRARY_INVALID when the withStandard partner exists only in the prerelease subdirectory. Confirms the same safe default behaviour as load_schema when the schema @@ -874,4 +874,4 @@ def test_from_string_prerelease_partner_default_raises(self): with patch.object(hed_cache, "HED_CACHE_DIRECTORY", self._cache_dir): with self.assertRaises(HedFileError) as ctx: from_string(schema_str, schema_format=".mediawiki") - self.assertEqual(ctx.exception.code, HedExceptions.BAD_WITH_STANDARD) + self.assertEqual(ctx.exception.code, HedExceptions.SCHEMA_LIBRARY_INVALID) diff --git a/tests/schema/test_schema_wiki_fatal_errors.py b/tests/schema/test_schema_wiki_fatal_errors.py index 48e17d0f..34ef9dcc 100644 --- a/tests/schema/test_schema_wiki_fatal_errors.py +++ b/tests/schema/test_schema_wiki_fatal_errors.py @@ -16,13 +16,13 @@ def setUpClass(cls): "HED_schema_no_end.mediawiki": HedExceptions.SCHEMA_SECTION_MISSING, "HED_hed_no_end.mediawiki": HedExceptions.SCHEMA_SECTION_MISSING, "HED_separator_invalid.mediawiki": HedExceptions.WIKI_SEPARATOR_INVALID, - "HED_header_missing.mediawiki": HedExceptions.SCHEMA_HEADER_MISSING, + "HED_header_missing.mediawiki": HedExceptions.SCHEMA_HEADER_INVALID, "HED_header_invalid.mediawiki": HedExceptions.SCHEMA_HEADER_INVALID, "empty_file.mediawiki": HedExceptions.WIKI_LINE_INVALID, "HED_header_invalid_version.mediawiki": HedExceptions.SCHEMA_VERSION_INVALID, "HED_header_missing_version.mediawiki": HedExceptions.SCHEMA_VERSION_INVALID, - "HED_header_unknown_attribute.mediawiki": HedExceptions.SCHEMA_UNKNOWN_HEADER_ATTRIBUTE, - "HED_header_bad_library.mediawiki": HedExceptions.BAD_HED_LIBRARY_NAME, + "HED_header_unknown_attribute.mediawiki": HedExceptions.SCHEMA_HEADER_INVALID, + "HED_header_bad_library.mediawiki": HedExceptions.SCHEMA_LIBRARY_INVALID, "HED_schema_out_of_order.mediawiki": HedExceptions.SCHEMA_SECTION_MISSING, "empty_node.mediawiki": HedExceptions.WIKI_DELIMITERS_INVALID, "malformed_line.mediawiki": HedExceptions.WIKI_DELIMITERS_INVALID,