Skip to content

Commit

Permalink
Merge pull request #793 from hed-standard/develop
Browse files Browse the repository at this point in the history
Merging into master in preparation
  • Loading branch information
VisLab committed Oct 27, 2023
2 parents 6557bdf + 8bfc034 commit 2c4ac99
Show file tree
Hide file tree
Showing 11 changed files with 7,568 additions and 6 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ jobs:

steps:
- uses: actions/checkout@v4
with:
submodules: true

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
Expand Down Expand Up @@ -64,6 +67,9 @@ jobs:
run: |
HED_GITHUB_TOKEN=${{ secrets.HED_GITHUB_TOKEN }} coverage run -m unittest
- name: Run spec_test coverage
run: HED_GITHUB_TOKEN=${{ secrets.HED_GITHUB_TOKEN }} coverage run --append -m unittest spec_tests/test_errors.py

- name: Archive code coverage results
if: ${{matrix.python-version == '3.9'}}
uses: actions/upload-artifact@v3
Expand Down
3 changes: 2 additions & 1 deletion hed/errors/error_messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,9 @@ def val_warning_capitalization(tag):

@hed_tag_error(ValidationErrors.UNITS_MISSING, default_severity=ErrorSeverity.WARNING)
def val_warning_default_units_used(tag, default_unit):
# todo: add a test case for no default unit.
if default_unit is None:
return f"No unit specified on - '{tag}'. Multiple default values exist and cannot be inferred"
return f"No unit specified on - '{tag}'. No default unit is specified for type."
return f"No unit specified. Using '{default_unit}' as the default - '{tag}'"


Expand Down
2 changes: 2 additions & 0 deletions hed/errors/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ class HedExceptions:
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'
Expand Down
1 change: 1 addition & 0 deletions hed/models/hed_tag.py
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,7 @@ def default_unit(self):
Returns:
unit(UnitEntry or None): the default unit entry for this tag, or None
"""
# todo: Make this cached
unit_classes = self.unit_classes.values()
if len(unit_classes) == 1:
first_unit_class_entry = list(unit_classes)[0]
Expand Down
8 changes: 8 additions & 0 deletions hed/schema/hed_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from hed.errors import ErrorHandler
from hed.errors.error_types import ValidationErrors
from hed.schema.hed_schema_base import HedSchemaBase
from hed.errors.exceptions import HedFileError, HedExceptions


class HedSchema(HedSchemaBase):
Expand Down Expand Up @@ -265,10 +266,17 @@ def set_schema_prefix(self, schema_namespace):
Parameters:
schema_namespace (str): Should be empty, or end with a colon.(Colon will be automated added if missing).
:raises HedFileError:
- The prefix is invalid
"""
if schema_namespace and schema_namespace[-1] != ":":
schema_namespace += ":"

if schema_namespace and not schema_namespace[:-1].isalpha():
raise HedFileError(HedExceptions.INVALID_LIBRARY_PREFIX,
"Schema namespace must contain only alpha characters",
self.filename)

self._namespace = schema_namespace

def __eq__(self, other):
Expand Down
8 changes: 6 additions & 2 deletions hed/schema/hed_schema_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ def _load_schema_version(xml_version=None, xml_folder=None):
""" Return specified version or latest if not specified.
Parameters:
xml_folder (str): Path to a folder containing schema.
xml_version (str): HED version format string. Expected format: '[schema_namespace:][library_name_]X.Y.Z'.
xml_folder (str): Path to a folder containing schema.
Returns:
HedSchema or HedSchemaGroup: The requested HedSchema object.
Expand All @@ -121,6 +121,7 @@ def _load_schema_version(xml_version=None, xml_folder=None):
- The xml_version is not valid.
- The specified version cannot be found or loaded
- Other fatal errors loading the schema (These are unlikely if you are not editing them locally)
- The prefix is invalid
"""
schema_namespace = ""
library_name = None
Expand Down Expand Up @@ -164,14 +165,17 @@ def load_schema_version(xml_version=None, xml_folder=None):
An empty string returns the latest version
A json str format is also supported,
based on the output of HedSchema.get_formatted_version
Basic format: '[schema_namespace:][library_name_]X.Y.Z'.
xml_folder (str): Path to a folder containing schema.
Returns:
HedSchema or HedSchemaGroup: The schema or schema group extracted.
:raises HedFileError:
- The xml_version is not valid.
- A fatal error was encountered in parsing
- The specified version cannot be found or loaded
- Other fatal errors loading the schema (These are unlikely if you are not editing them locally)
- The prefix is invalid
"""
# Check if we start and end with a square bracket, or double quote. This might be valid json
if xml_version and isinstance(xml_version, str) and \
Expand Down
Loading

0 comments on commit 2c4ac99

Please sign in to comment.