25 from .schema
import Schema
27 __all__ = [
"assertSchemasEqual",
"diffSchemas",
"joinWords"]
31 """Join a sequence of words into a comma-separated, 'and'-finalized 32 string with correct English syntax. 37 result =
"%s and %s" % tuple(items)
39 result =
"%s, and %s" % (
", ".join(items[:-1]), items[-1])
44 """Return a string diff of two schemas. 48 schema1 : :py:class:`lsst.afw.table.Schema` 49 First schema to diff. Items appearing only in this schema 50 will be prefixed with "-" in the diff. 51 schema2 : :py:class:`lsst.afw.table.Schema` 52 Second schema to diff. Items appearing only in this schema 53 will be prefixed with "-" in the diff. 55 A bitwise OR of :py:class:`lsst.afw.table.Schema.ComparisonFlags` 56 indicating which features of schema items to compare. The returned 57 diff will always show all differences, but no diff will be shown if 58 the only differences are not included in the flags. Default is 59 `lsst.afw.table.Schema.IDENTICAL`, which checks everything. 64 A "unified diff" string representation of the difference between the 65 schemas, or an empty string if there is no difference. 67 result = schema1.compare(schema2, flags)
71 if not result & Schema.EQUAL_KEYS:
72 components.append(
"keys")
73 if not result & Schema.EQUAL_NAMES:
74 components.append(
"names")
75 if not result & Schema.EQUAL_DOCS:
76 components.append(
"docs")
77 if not result & Schema.EQUAL_UNITS:
78 components.append(
"units")
79 if not result & Schema.EQUAL_ALIASES:
80 components.append(
"aliases")
81 diff =
"\n".join(difflib.unified_diff(
82 str(schema1).split(
"\n"), str(schema2).split(
"\n")))
83 return "%s differ:\n%s" % (
joinWords(components).capitalize(), diff)
86 @lsst.utils.tests.inTestCase
88 """Assert that two Schemas are equal. 90 Generates a message from the difference between the schemas; see 91 :py:func:`diffSchemas` for more information.
def diffSchemas(schema1, schema2, flags=Schema.IDENTICAL)
def assertSchemasEqual(testCase, schema1, schema2, flags=Schema.IDENTICAL)