Skip to content

Commit 78c12e0

Browse files
authored
Merge pull request #1233 from VisLab/fix_extras
Updated the schema compliance to check only the latest versions
2 parents b4f4d75 + 8634410 commit 78c12e0

5 files changed

Lines changed: 154 additions & 7 deletions

File tree

hed/schema/hed_schema_section.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,9 @@ def _finalize_section(self, hed_schema):
272272
attribute_section = hed_schema.attributes
273273
if hed_schema.schema_83_props:
274274
self.inheritable_attributes = [
275-
name for name, value in attribute_section.items() if not value.has_attribute(HedKey.AnnotationProperty)
275+
name
276+
for name, value in attribute_section.items()
277+
if not value.has_attribute(HedKey.AnnotationProperty) and name != HedKey.InLibrary
276278
]
277279
else:
278280
self.inheritable_attributes = [

hed/schema/schema_attribute_validators.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,10 @@ def tag_is_deprecated_check(hed_schema, tag_entry, attribute_name) -> list:
203203
if hasattr(tag_entry, "children"):
204204
# Fix up this error message if we ever actually issue it for units
205205
for child in tag_entry.children.values():
206-
if not child.has_attribute(attribute_name):
206+
# Check the child's own attributes, not inherited_attributes,
207+
# because deprecatedFrom is inheritable and would always be found
208+
# via has_attribute() on child tags of a deprecated parent.
209+
if attribute_name not in child.attributes:
207210
issues += ErrorHandler.format_error(
208211
SchemaAttributeErrors.SCHEMA_CHILD_OF_DEPRECATED, tag_entry.name, child.name
209212
)

spec_tests/_debug_dep_tests.py

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
"""Debug the 7 remaining deprecation test failures."""
2+
3+
import sys
4+
5+
sys.path.insert(0, ".")
6+
7+
from hed.schema.hed_schema_io import from_string
8+
from hed.schema.hed_schema_constants import HedKey, HedSectionKey
9+
10+
11+
def load_and_check(label, lines, expect_fail=True):
12+
print("\n" + "=" * 60)
13+
print(f"{label}")
14+
print("=" * 60)
15+
schema_str = "\n".join(lines)
16+
schema = from_string(schema_str, schema_format=".mediawiki")
17+
issues = schema.check_compliance()
18+
if issues:
19+
for i in issues:
20+
print(f" {i['code']}: {i.get('message', str(i))[:150]}")
21+
if not expect_fail:
22+
print(f" ** PROBLEM: {len(issues)} issues but test expects PASS **")
23+
else:
24+
if expect_fail:
25+
print(" ** PROBLEM: NO ISSUES but test expects FAIL **")
26+
else:
27+
print(" OK: No issues (expected)")
28+
return schema, issues
29+
30+
31+
# Test #1 fail[2]: deprecatedFrom=1.0.0 at version 1.0.0
32+
schema, issues = load_and_check(
33+
"Test #1 fail[2]: deprecatedFrom=1.0.0 at version 1.0.0",
34+
[
35+
'HED version="1.0.0" library="score" withStandard="8.3.0" unmerged="True"',
36+
"'''Prologue'''",
37+
"!# start schema",
38+
"'''BaseTag'''",
39+
"* Extension {deprecatedFrom=1.0.0}",
40+
"!# end schema",
41+
"'''Unit classes'''",
42+
"'''Unit modifiers'''",
43+
"'''Value classes'''",
44+
"'''Schema attributes'''",
45+
"'''Properties'''",
46+
"'''Epilogue'''",
47+
"!# end hed",
48+
],
49+
expect_fail=True,
50+
)
51+
# Check what InLibrary looks like for Extension
52+
tags = schema[HedSectionKey.Tags]
53+
for e in tags.all_entries:
54+
if "Extension" in e.name:
55+
print(f" Extension InLibrary: {e.has_attribute(HedKey.InLibrary, return_value=True)}")
56+
print(f" Extension deprecatedFrom: {e.attributes.get('deprecatedFrom')}")
57+
break
58+
59+
# Test #2 fail[1]: deprecated parent, non-deprecated child
60+
schema, issues = load_and_check(
61+
"Test #2 fail[1]: deprecated parent with non-deprecated child",
62+
[
63+
'HED version="1.1.0" library="score" withStandard="8.3.0" unmerged="True"',
64+
"'''Prologue'''",
65+
"!# start schema",
66+
"'''BaseTag''' {deprecatedFrom=1.0.0}",
67+
"* Extension",
68+
"!# end schema",
69+
"'''Unit classes'''",
70+
"'''Unit modifiers'''",
71+
"'''Value classes'''",
72+
"'''Schema attributes'''",
73+
"'''Properties'''",
74+
"'''Epilogue'''",
75+
"!# end hed",
76+
],
77+
expect_fail=True,
78+
)
79+
# Check BaseTag's children
80+
tags = schema[HedSectionKey.Tags]
81+
for e in tags.all_entries:
82+
if e.name == "BaseTag":
83+
print(f" BaseTag children: {list(e.children.keys())}")
84+
print(f" BaseTag deprecatedFrom: {e.attributes.get('deprecatedFrom')}")
85+
print(f" BaseTag InLibrary: {e.has_attribute(HedKey.InLibrary, return_value=True)}")
86+
break
87+
88+
# Test #7 fail[1]: Extension with deprecatedAttribute (custom attribute)
89+
schema, issues = load_and_check(
90+
"Test #7 fail[1]: tag with deprecated custom attribute (should FAIL)",
91+
[
92+
'HED version="1.1.0" library="score" withStandard="8.3.0" unmerged="True"',
93+
"'''Prologue'''",
94+
"!# start schema",
95+
"'''BaseTag'''",
96+
"* Extension{deprecatedAttribute}",
97+
"!# end schema",
98+
"'''Unit classes'''",
99+
"'''Unit modifiers'''",
100+
"'''Value classes'''",
101+
"'''Schema attributes'''",
102+
"* deprecatedAttribute {deprecatedFrom=1.0.0, elementProperty}",
103+
"'''Properties'''",
104+
"'''Epilogue'''",
105+
"!# end hed",
106+
],
107+
expect_fail=True,
108+
)
109+
# Check what attributes section contains
110+
print(" Schema attributes defined:")
111+
attr_section = schema[HedSectionKey.Attributes]
112+
for name, entry in attr_section.items():
113+
if "deprecated" in name.lower():
114+
print(f" {name}: {entry.attributes}")
115+
116+
# Check properties section
117+
print(" Properties defined:")
118+
props = schema[HedSectionKey.Properties]
119+
for name, entry in props.items():
120+
if "element" in name.lower() or "property" in name.lower():
121+
print(f" {name}: {entry.attributes}")
122+
123+
# Test #7 pass[1]: Extension with deprecatedAttribute AND deprecatedFrom
124+
schema, issues = load_and_check(
125+
"Test #7 pass[1]: tag with deprecated custom attribute + deprecatedFrom (should PASS)",
126+
[
127+
'HED version="1.1.0" library="score" withStandard="8.3.0" unmerged="True"',
128+
"'''Prologue'''",
129+
"!# start schema",
130+
"'''BaseTag'''",
131+
"* Extension{deprecatedAttribute, deprecatedFrom=1.0.0}",
132+
"!# end schema",
133+
"'''Unit classes'''",
134+
"'''Unit modifiers'''",
135+
"'''Value classes'''",
136+
"'''Schema attributes'''",
137+
"* deprecatedAttribute {deprecatedFrom=1.0.0, elementProperty}",
138+
"'''Properties'''",
139+
"'''Epilogue'''",
140+
"!# end hed",
141+
],
142+
expect_fail=False,
143+
)

spec_tests/test_errors.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -187,10 +187,9 @@ def run_single_test(self, test_file, test_name=None, test_type=None):
187187
test_index,
188188
)
189189
if section_name == "schema_tests":
190-
pass
191-
# self._run_single_schema_test(
192-
# section, error_code, all_codes, description, name, error_handler, file_basename, test_index
193-
# )
190+
self._run_single_schema_test(
191+
section, error_code, all_codes, description, name, error_handler, file_basename, test_index
192+
)
194193

195194
def report_result(
196195
self, expected_result, issues, error_code, all_codes, description, name, test, test_type, test_file, test_index

0 commit comments

Comments
 (0)