54 """Return a string diff of two schemas.
58 schema1 : :py:class:`lsst.afw.table.Schema`
59 First schema to diff. Items appearing only in this schema
60 will be prefixed with "-" in the diff.
61 schema2 : :py:class:`lsst.afw.table.Schema`
62 Second schema to diff. Items appearing only in this schema
63 will be prefixed with "-" in the diff.
65 A bitwise OR of :py:class:`lsst.afw.table.Schema.ComparisonFlags`
66 indicating which features of schema items to compare. The returned
67 diff will always show all differences, but no diff will be shown if
68 the only differences are not included in the flags. Default is
69 `lsst.afw.table.Schema.IDENTICAL`, which checks everything.
74 A "unified diff" string representation of the difference between the
75 schemas, or an empty string if there is no difference.
77 result = schema1.compare(schema2, flags)
81 if not result & Schema.EQUAL_KEYS:
82 components.append(
"keys")
83 if not result & Schema.EQUAL_NAMES:
84 components.append(
"names")
85 if not result & Schema.EQUAL_DOCS:
86 components.append(
"docs")
87 if not result & Schema.EQUAL_UNITS:
88 components.append(
"units")
89 if not result & Schema.EQUAL_ALIASES:
90 components.append(
"aliases")
91 diff =
"\n".join(difflib.unified_diff(
92 str(schema1).split(
"\n"), str(schema2).split(
"\n")))
93 return f
"{joinWords(components).capitalize()} differ:\n{diff}"
96@lsst.utils.tests.inTestCase