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