LSSTApplications  18.0.0+106,18.0.0+50,19.0.0,19.0.0+1,19.0.0+10,19.0.0+11,19.0.0+13,19.0.0+17,19.0.0+2,19.0.0-1-g20d9b18+6,19.0.0-1-g425ff20,19.0.0-1-g5549ca4,19.0.0-1-g580fafe+6,19.0.0-1-g6fe20d0+1,19.0.0-1-g7011481+9,19.0.0-1-g8c57eb9+6,19.0.0-1-gb5175dc+11,19.0.0-1-gdc0e4a7+9,19.0.0-1-ge272bc4+6,19.0.0-1-ge3aa853,19.0.0-10-g448f008b,19.0.0-12-g6990b2c,19.0.0-2-g0d9f9cd+11,19.0.0-2-g3d9e4fb2+11,19.0.0-2-g5037de4,19.0.0-2-gb96a1c4+3,19.0.0-2-gd955cfd+15,19.0.0-3-g2d13df8,19.0.0-3-g6f3c7dc,19.0.0-4-g725f80e+11,19.0.0-4-ga671dab3b+1,19.0.0-4-gad373c5+3,19.0.0-5-ga2acb9c+2,19.0.0-5-gfe96e6c+2,w.2020.01
LSSTDataManagementBasePackage
Functions
lsst.afw.table.testUtils Namespace Reference

Functions

def joinWords (items)
 
def diffSchemas (schema1, schema2, flags=Schema.IDENTICAL)
 
def assertSchemasEqual (testCase, schema1, schema2, flags=Schema.IDENTICAL)
 

Function Documentation

◆ assertSchemasEqual()

def lsst.afw.table.testUtils.assertSchemasEqual (   testCase,
  schema1,
  schema2,
  flags = Schema.IDENTICAL 
)
Assert that two Schemas are equal.

Generates a message from the difference between the schemas; see
:py:func:`diffSchemas` for more information.

Parameters
----------
testCase :
    Comparison test case that should fail is schemas differ.
schema1 : :py:class:`lsst.afw.table.Schema`
    First input schema.
schema2 : :py:class:`lsst.afw.table.Schema`
    Second input schema.
flags : `int`
    A bitwise OR of :py:class:`lsst.afw.table.Schema.ComparisonFlags`
    indicating which features of schema items to compare.

Definition at line 96 of file testUtils.py.

96 def assertSchemasEqual(testCase, schema1, schema2, flags=Schema.IDENTICAL):
97  """Assert that two Schemas are equal.
98 
99  Generates a message from the difference between the schemas; see
100  :py:func:`diffSchemas` for more information.
101 
102  Parameters
103  ----------
104  testCase :
105  Comparison test case that should fail is schemas differ.
106  schema1 : :py:class:`lsst.afw.table.Schema`
107  First input schema.
108  schema2 : :py:class:`lsst.afw.table.Schema`
109  Second input schema.
110  flags : `int`
111  A bitwise OR of :py:class:`lsst.afw.table.Schema.ComparisonFlags`
112  indicating which features of schema items to compare.
113  """
114  msg = diffSchemas(schema1, schema2, flags=flags)
115  if msg:
116  testCase.fail(msg)
117 
def diffSchemas(schema1, schema2, flags=Schema.IDENTICAL)
Definition: testUtils.py:52
def assertSchemasEqual(testCase, schema1, schema2, flags=Schema.IDENTICAL)
Definition: testUtils.py:96

◆ diffSchemas()

def lsst.afw.table.testUtils.diffSchemas (   schema1,
  schema2,
  flags = Schema.IDENTICAL 
)
Return a string diff of two schemas.

Parameters
----------
schema1 : :py:class:`lsst.afw.table.Schema`
    First schema to diff.  Items appearing only in this schema
    will be prefixed with "-" in the diff.
schema2 : :py:class:`lsst.afw.table.Schema`
    Second schema to diff.  Items appearing only in this schema
    will be prefixed with "-" in the diff.
flags : `int`
    A bitwise OR of :py:class:`lsst.afw.table.Schema.ComparisonFlags`
    indicating which features of schema items to compare.  The returned
    diff will always show all differences, but no diff will be shown if
    the only differences are not included in the flags.  Default is
    `lsst.afw.table.Schema.IDENTICAL`, which checks everything.

Returns
-------
diff : `str`
    A "unified diff" string representation of the difference between the
    schemas, or an empty string if there is no difference.

Definition at line 52 of file testUtils.py.

52 def diffSchemas(schema1, schema2, flags=Schema.IDENTICAL):
53  """Return a string diff of two schemas.
54 
55  Parameters
56  ----------
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.
63  flags : `int`
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.
69 
70  Returns
71  -------
72  diff : `str`
73  A "unified diff" string representation of the difference between the
74  schemas, or an empty string if there is no difference.
75  """
76  result = schema1.compare(schema2, flags)
77  if result == flags:
78  return ""
79  components = []
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)
93 
94 
95 @lsst.utils.tests.inTestCase
def diffSchemas(schema1, schema2, flags=Schema.IDENTICAL)
Definition: testUtils.py:52

◆ joinWords()

def lsst.afw.table.testUtils.joinWords (   items)
Join a sequence of words into a comma-separated, 'and'-finalized
string with correct English syntax.

Parameters
----------
items : Array of `str`
    Sequence to be joined.

Returns
-------
result : `str`
     Correct English Oxford-comma terminated string.

Definition at line 29 of file testUtils.py.

29 def joinWords(items):
30  """Join a sequence of words into a comma-separated, 'and'-finalized
31  string with correct English syntax.
32 
33  Parameters
34  ----------
35  items : Array of `str`
36  Sequence to be joined.
37 
38  Returns
39  -------
40  result : `str`
41  Correct English Oxford-comma terminated string.
42  """
43  if len(items) == 1:
44  result = items[0]
45  elif len(items) == 2:
46  result = "%s and %s" % tuple(items)
47  else:
48  result = "%s, and %s" % (", ".join(items[:-1]), items[-1])
49  return result
50 
51