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 =
"%s and %s" % tuple(items)
48 result =
"%s, and %s" % (
", ".join(items[:-1]), items[-1])
53 """Return a string diff of two schemas. 57 schema1 : :py:class:`lsst.afw.table.Schema` 58 First schema to diff. Items appearing only in this schema 59 will be prefixed with "-" in the diff. 60 schema2 : :py:class:`lsst.afw.table.Schema` 61 Second schema to diff. Items appearing only in this schema 62 will be prefixed with "-" in the diff. 64 A bitwise OR of :py:class:`lsst.afw.table.Schema.ComparisonFlags` 65 indicating which features of schema items to compare. The returned 66 diff will always show all differences, but no diff will be shown if 67 the only differences are not included in the flags. Default is 68 `lsst.afw.table.Schema.IDENTICAL`, which checks everything. 73 A "unified diff" string representation of the difference between the 74 schemas, or an empty string if there is no difference. 76 result = schema1.compare(schema2, flags)
80 if not result & Schema.EQUAL_KEYS:
81 components.append(
"keys")
82 if not result & Schema.EQUAL_NAMES:
83 components.append(
"names")
84 if not result & Schema.EQUAL_DOCS:
85 components.append(
"docs")
86 if not result & Schema.EQUAL_UNITS:
87 components.append(
"units")
88 if not result & Schema.EQUAL_ALIASES:
89 components.append(
"aliases")
90 diff =
"\n".join(difflib.unified_diff(
91 str(schema1).split(
"\n"), str(schema2).split(
"\n")))
92 return "%s differ:\n%s" % (
joinWords(components).capitalize(), diff)
95 @lsst.utils.tests.inTestCase
97 """Assert that two Schemas are equal. 99 Generates a message from the difference between the schemas; see 100 :py:func:`diffSchemas` for more information. 105 Comparison test case that should fail is schemas differ. 106 schema1 : :py:class:`lsst.afw.table.Schema` 108 schema2 : :py:class:`lsst.afw.table.Schema` 111 A bitwise OR of :py:class:`lsst.afw.table.Schema.ComparisonFlags` 112 indicating which features of schema items to compare.
def diffSchemas(schema1, schema2, flags=Schema.IDENTICAL)
def assertSchemasEqual(testCase, schema1, schema2, flags=Schema.IDENTICAL)