|
| 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 | +) |
0 commit comments