24 from ._schema
import Schema
26 __all__ = [
"assertSchemasEqual",
"diffSchemas",
"joinWords"]
30 """Join a sequence of words into a comma-separated, 'and'-finalized
31 string with correct English syntax.
35 items : Array of `str`
36 Sequence to be joined.
41 Correct English Oxford-comma terminated string.
46 result = f
"{items[0]} and {items[1]}"
48 allButLast =
", ".join(items[:-1])
49 result = f
"{allButLast}, and items{[-1]}"
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
98 """Assert that two Schemas are equal.
100 Generates a message from the difference between the schemas; see
101 :py:func:`diffSchemas` for more information.
106 Comparison test case that should fail is schemas differ.
107 schema1 : :py:class:`lsst.afw.table.Schema`
109 schema2 : :py:class:`lsst.afw.table.Schema`
112 A bitwise OR of :py:class:`lsst.afw.table.Schema.ComparisonFlags`
113 indicating which features of schema items to compare.