Skip to content

Commit

Permalink
Fix spec tests/minor error tweaks for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
IanCa committed Apr 18, 2024
1 parent cec8527 commit 5c2066b
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 10 deletions.
5 changes: 3 additions & 2 deletions hed/errors/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class HedExceptions:
SCHEMA_LIBRARY_INVALID = "SCHEMA_LIBRARY_INVALID"
BAD_HED_LIBRARY_NAME = 'SCHEMA_LIBRARY_INVALID'
BAD_WITH_STANDARD = "SCHEMA_LIBRARY_INVALID"
BAD_WITH_STANDARD_VERSION = "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"
Expand All @@ -40,13 +40,14 @@ class HedExceptions:
WIKI_LINE_START_INVALID = 'WIKI_LINE_START_INVALID'
HED_SCHEMA_NODE_NAME_INVALID = 'HED_SCHEMA_NODE_NAME_INVALID'

SCHEMA_DUPLICATE_PREFIX = 'schemaDuplicatePrefix'
SCHEMA_DUPLICATE_PREFIX = 'SCHEMA_LOAD_FAILED'
SCHEMA_DUPLICATE_LIBRARY = "SCHEMA_LIBRARY_INVALID"
BAD_COLUMN_NAMES = 'BAD_COLUMN_NAMES'

SCHEMA_DUPLICATE_NAMES = "SCHEMA_DUPLICATE_NAMES"

CANNOT_PARSE_RDF = "CANNOT_PARSE_RDF"
SCHEMA_LOAD_FAILED = "SCHEMA_LOAD_FAILED"


class HedFileError(Exception):
Expand Down
14 changes: 10 additions & 4 deletions spec_tests/test_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import io
import json
from hed import HedFileError
from hed.errors import ErrorHandler, get_printable_issue_string
from hed.errors import ErrorHandler, get_printable_issue_string, SchemaWarnings


skip_tests = {
Expand Down Expand Up @@ -46,7 +46,7 @@ def run_single_test(self, test_file):
print(f"Skipping {name} test because: {skip_tests[name]}")
continue

# if name != "sidecar-braces-invalid-spot":
# if name != "library-invalid-bad_with-standard-version":
# continue
description = info['description']
schema = info['schema']
Expand All @@ -56,8 +56,12 @@ def run_single_test(self, test_file):
try:
schema = load_schema_version(schema)
except HedFileError as e:
print(f"Failed to load schema version {schema} for test, failing test {name}")
self.fail_count.append(name)
issues = e.issues
if not issues:
issues += [{"code": e.code,
"message": e.message}]
self.report_result("fails", issues, error_code, description, name, "dummy", "Schema")
# self.fail_count.append(name)
continue
definitions = info.get('definitions', None)
def_dict = DefinitionDict(definitions, schema)
Expand All @@ -77,6 +81,8 @@ def run_single_test(self, test_file):
self._run_single_schema_test(section, error_code, description, name, error_handler)

def report_result(self, expected_result, issues, error_code, description, name, test, test_type):
# Filter out pre-release warnings, we don't care about them.
issues = [issue for issue in issues if issue["code"] != SchemaWarnings.SCHEMA_PRERELEASE_VERSION_USED]
if expected_result == "fails":
if not issues:
print(f"{error_code}: {description}")
Expand Down
7 changes: 4 additions & 3 deletions tests/schema/test_hed_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from hed.schema import hed_cache
from hed import schema
import shutil
from hed.errors import HedExceptions


class Test(unittest.TestCase):
Expand Down Expand Up @@ -128,15 +129,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], 'schemaDuplicatePrefix')
self.assertEqual(context4.exception.args[0], HedExceptions.SCHEMA_DUPLICATE_PREFIX)

with self.assertRaises(HedFileError) as context5:
load_schema_version(["sc:8.2.0", "sc:score_1.0.0"])
self.assertEqual(context5.exception.args[0], 'schemaDuplicatePrefix')
self.assertEqual(context5.exception.args[0], HedExceptions.SCHEMA_DUPLICATE_PREFIX)

with self.assertRaises(HedFileError) as context6:
load_schema_version(["8.1.0", "score_1.0.0"])
self.assertEqual(context6.exception.args[0], 'schemaDuplicatePrefix')
self.assertEqual(context6.exception.args[0], HedExceptions.SCHEMA_DUPLICATE_PREFIX)

with self.assertRaises(HedFileError) as context8:
load_schema_version(["8.1.0", "notreallibrary_1.0.0"])
Expand Down

0 comments on commit 5c2066b

Please sign in to comment.