Skip to content

Commit d567f5f

Browse files
committed
Fixed copilot/claude suggestions
1 parent 1d8a15e commit d567f5f

7 files changed

Lines changed: 21 additions & 11 deletions

File tree

hed/schema/hed_schema.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ def set_schema_prefix(self, schema_namespace):
423423

424424
if schema_namespace and not schema_namespace[:-1].isalpha():
425425
raise HedFileError(
426-
HedExceptions.INVALID_LIBRARY_PREFIX,
426+
HedExceptions.SCHEMA_LIBRARY_INVALID,
427427
"Schema namespace must contain only alpha characters",
428428
self.filename,
429429
)

hed/schema/schema_io/base2schema.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,15 +194,15 @@ def find_rooted_entry(tag_entry, schema, loading_merged):
194194
if rooted_tag is not None:
195195
if not schema.with_standard:
196196
raise HedFileError(
197-
HedExceptions.SCHEMA_ATTRIBUTE_INVALID,
197+
HedExceptions.SCHEMA_LIBRARY_INVALID,
198198
f"Rooted tag attribute found on '{tag_entry.short_tag_name}' in a standard schema.",
199199
schema.name,
200200
)
201201

202202
if not isinstance(rooted_tag, str):
203203
raise HedFileError(
204204
HedExceptions.SCHEMA_LIBRARY_INVALID,
205-
f"Rooted tag '{tag_entry.short_tag_name}' is not a string.\"",
205+
f"Rooted tag '{tag_entry.short_tag_name}' is not a string.",
206206
schema.name,
207207
)
208208

@@ -223,7 +223,7 @@ def find_rooted_entry(tag_entry, schema, loading_merged):
223223
rooted_entry = schema.tags.get(rooted_tag)
224224
if not rooted_entry or rooted_entry.has_attribute(constants.HedKey.InLibrary):
225225
raise HedFileError(
226-
HedExceptions.LIBRARY_SCHEMA_INVALID,
226+
HedExceptions.SCHEMA_LIBRARY_INVALID,
227227
f"Rooted tag '{tag_entry.short_tag_name}' not found in paired standard schema",
228228
schema.name,
229229
)

hed/schema/schema_io/df2schema.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ def _add_to_dict(self, row_number, row, entry, key_class):
275275
row_number,
276276
row,
277277
"Library tag in unmerged schema has InLibrary attribute",
278-
HedExceptions.IN_LIBRARY_IN_UNMERGED,
278+
HedExceptions.SCHEMA_LIBRARY_INVALID,
279279
)
280280

281281
return self._add_to_dict_base(entry, key_class)

hed/schema/schema_io/wiki2schema.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,7 @@ def _add_to_dict(self, row_number, row, entry, key_class):
609609
row_number,
610610
row,
611611
"Library tag in unmerged schema has InLibrary attribute",
612-
HedExceptions.IN_LIBRARY_IN_UNMERGED,
612+
HedExceptions.SCHEMA_LIBRARY_INVALID,
613613
)
614614

615615
return self._add_to_dict_base(entry, key_class)

hed/schema/schema_io/xml2schema.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ def _get_elements_by_name(self, element_name="node", parent_element=None):
348348
def _add_to_dict(self, entry, key_class):
349349
if entry.has_attribute(HedKey.InLibrary) and not self._loading_merged and not self.appending_to_schema:
350350
raise HedFileError(
351-
HedExceptions.IN_LIBRARY_IN_UNMERGED,
351+
HedExceptions.SCHEMA_LIBRARY_INVALID,
352352
"Library tag in unmerged schema has InLibrary attribute",
353353
self.name,
354354
)

tests/schema/test_hed_schema_io.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,16 @@ def test_cannot_load_schemas(self):
486486
load_schema(file)
487487
self.assertEqual(context.exception.code, HedExceptions.SCHEMA_LIBRARY_INVALID)
488488

489+
def test_rooted_tag_not_in_standard_schema(self):
490+
# HED_badroot_0.0.1.mediawiki has rooted=AlsoNotRealTag which does not exist in the standard schema.
491+
# This should raise SCHEMA_LIBRARY_INVALID (not LIBRARY_SCHEMA_INVALID).
492+
bad_root_file = os.path.join(self.full_base_folder, "issues_tests/HED_badroot_0.0.1.mediawiki")
493+
with self.assertRaises(HedFileError) as context:
494+
load_schema(bad_root_file)
495+
self.assertEqual(context.exception.code, HedExceptions.SCHEMA_LIBRARY_INVALID)
496+
issue_codes = [issue.get("code") for issue in context.exception.issues]
497+
self.assertIn(HedExceptions.SCHEMA_LIBRARY_INVALID, issue_codes)
498+
489499
def test_saving_in_library_wiki(self):
490500
old_score_schema = load_schema_version("score_1.0.0")
491501

tests/tools/analysis/test_hed_type_factors.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from hed.schema.hed_schema_io import load_schema_version
88
from hed.tools.analysis.event_manager import EventManager
99
from hed.tools.analysis.hed_type import HedType
10-
from hed.errors.exceptions import HedFileError
10+
from hed.errors.exceptions import HedFileError, HedExceptions
1111
from hed.tools.analysis.hed_type_factors import HedTypeFactors
1212

1313

@@ -121,10 +121,10 @@ def test_constructor_multiple_values(self):
121121
self.assertEqual(len(fact2), len(self.event_man2.event_list))
122122
with self.assertRaises(HedFileError) as context:
123123
var_fact2.get_factors(factor_encoding="categorical")
124-
self.assertEqual(context.exception.args[0], "MultipleFactorSameEvent")
125-
with self.assertRaises(ValueError) as context:
124+
self.assertEqual(context.exception.code, HedExceptions.BAD_PARAMETERS)
125+
with self.assertRaises(HedFileError) as context:
126126
var_fact2.get_factors(factor_encoding="baloney")
127-
self.assertEqual(context.exception.args[0], "BadFactorEncoding")
127+
self.assertEqual(context.exception.code, HedExceptions.BAD_PARAMETERS)
128128

129129
def test_constructor_unmatched(self):
130130
with self.assertRaises(KeyError) as context:

0 commit comments

Comments
 (0)