TestCase

class lsst.utils.tests.TestCase(methodName='runTest')[source]

Bases: unittest.case.TestCase

Subclass of unittest.TestCase that adds some custom assertions for convenience.

Attributes Summary

longMessage
maxDiff

Methods Summary

__call__(*args, **kwds)
addCleanup(function, *args, **kwargs) Add a function, with arguments, to be called when the test is completed.
addTypeEqualityFunc(typeobj, function) Add a type specific assertEqual style function to compare a type.
assertAlmostEqual(first, second[, places, ...]) Fail if the two objects are unequal as determined by their difference rounded to the given number of decimal places (default 7) and comparing to zero, or by comparing that the between the two objects is more than the given delta.
assertAlmostEquals(*args, **kwargs)
assertAnglesAlmostEqual(testCase, ang0, ang1) !Assert that two angles are almost equal, ignoring wrap differences by default
assertAnglesNearlyEqual(*args, **kwargs)
assertBoxesAlmostEqual(testCase, box0, box1) !Assert that two boxes (Box2D or Box2I) are almost equal
assertBoxesNearlyEqual(*args, **kwargs)
assertClose(*args, **kwargs)

Note

Deprecated in 12_0

assertCoordListsAlmostEqual(testCase, ...[, ...]) !Assert that two lists of IcrsCoords represent almost the same point on the sky
assertCoordsAlmostEqual(testCase, coord0, coord1) !Assert that two coords represent almost the same point on the sky
assertCoordsNearlyEqual(*args, **kwargs)
assertCountEqual(first, second[, msg]) An unordered sequence comparison asserting that the same elements, regardless of order.
assertDictContainsSubset(subset, dictionary) Checks whether dictionary is a superset of subset.
assertDictEqual(d1, d2[, msg])
assertEqual(first, second[, msg]) Fail if the two objects are unequal as determined by the ‘==’ operator.
assertEquals(*args, **kwargs)
assertFalse(expr[, msg]) Check that the expression is false.
assertFloatsAlmostEqual(testCase, lhs, rhs) Highly-configurable floating point comparisons for scalars and arrays.
assertFloatsEqual(testCase, lhs, rhs, **kwargs) Assert that lhs == rhs (both numeric types, whether scalar or array).
assertFloatsNotEqual(testCase, lhs, rhs, **kwds) Fail a test if the given floating point values are equal to within the given tolerances.
assertGreater(a, b[, msg]) Just like self.assertTrue(a > b), but with a nicer default message.
assertGreaterEqual(a, b[, msg]) Just like self.assertTrue(a >= b), but with a nicer default message.
assertImagesAlmostEqual(testCase, image0, image1) !Assert that two images are almost equal, including non-finite values
assertImagesEqual(*args, **kwds) !Assert that two images are exactly equal, including non-finite values.
assertImagesNearlyEqual(*args, **kwargs)
assertIn(member, container[, msg]) Just like self.assertTrue(a in b), but with a nicer default message.
assertIs(expr1, expr2[, msg]) Just like self.assertTrue(a is b), but with a nicer default message.
assertIsInstance(obj, cls[, msg]) Same as self.assertTrue(isinstance(obj, cls)), with a nicer default message.
assertIsNone(obj[, msg]) Same as self.assertTrue(obj is None), with a nicer default message.
assertIsNot(expr1, expr2[, msg]) Just like self.assertTrue(a is not b), but with a nicer default message.
assertIsNotNone(obj[, msg]) Included for symmetry with assertIsNone.
assertLess(a, b[, msg]) Just like self.assertTrue(a < b), but with a nicer default message.
assertLessEqual(a, b[, msg]) Just like self.assertTrue(a <= b), but with a nicer default message.
assertListEqual(list1, list2[, msg]) A list-specific equality assertion.
assertLogs([logger, level]) Fail unless a log message of level level or higher is emitted on logger_name or its children.
assertMaskedImagesAlmostEqual(testCase, ...) !Assert that two masked images are nearly equal, including non-finite values
assertMaskedImagesEqual(*args, **kwds) !Assert that two masked images are exactly equal, including non-finite values.
assertMaskedImagesNearlyEqual(*args, **kwargs)
assertMasksEqual(testCase, mask0, mask1[, ...]) !Assert that two masks are equal
assertMultiLineEqual(first, second[, msg]) Assert that two multi-line strings are equal.
assertNotAlmostEqual(first, second[, ...]) Fail if the two objects are equal as determined by their difference rounded to the given number of decimal places (default 7) and comparing to zero, or by comparing that the between the two objects is less than the given delta.
assertNotAlmostEquals(*args, **kwargs)
assertNotClose(*args, **kwargs)

Note

Deprecated in 12_0

assertNotEqual(first, second[, msg]) Fail if the two objects are equal as determined by the ‘!=’ operator.
assertNotEquals(*args, **kwargs)
assertNotIn(member, container[, msg]) Just like self.assertTrue(a not in b), but with a nicer default message.
assertNotIsInstance(obj, cls[, msg]) Included for symmetry with assertIsInstance.
assertNotRegex(text, unexpected_regex[, msg]) Fail the test if the text matches the regular expression.
assertNotRegexpMatches(*args, **kwargs)
assertPairListsAlmostEqual(testCase, list0, ...) !Assert that two lists of Cartesian points are almost equal
assertPairsAlmostEqual(testCase, pair0, pair1) !Assert that two Cartesian points are almost equal.
assertPairsNearlyEqual(*args, **kwargs)
assertRaises(expected_exception, *args, **kwargs) Fail unless an exception of class expected_exception is raised by the callable when invoked with specified positional and keyword arguments.
assertRaisesLsstCpp(testcase, excClass, ...)

Note

Deprecated in 12_0

assertRaisesRegex(expected_exception, ...) Asserts that the message in a raised exception matches a regex.
assertRaisesRegexp(*args, **kwargs)
assertRegex(text, expected_regex[, msg]) Fail the test unless the text matches the regular expression.
assertRegexpMatches(*args, **kwargs)
assertSequenceEqual(seq1, seq2[, msg, seq_type]) An equality assertion for ordered sequences (like lists and tuples).
assertSetEqual(set1, set2[, msg]) A set-specific equality assertion.
assertSpherePointListsAlmostEqual(testCase, ...) !Assert that two lists of SpherePoints are almost equal
assertSpherePointsAlmostEqual(testCase, sp0, sp1) !Assert that two SpherePoints are almost equal
assertTrue(expr[, msg]) Check that the expression is true.
assertTupleEqual(tuple1, tuple2[, msg]) A tuple-specific equality assertion.
assertWarns(expected_warning, *args, **kwargs) Fail unless a warning of class warnClass is triggered by the callable when invoked with specified positional and keyword arguments.
assertWarnsRegex(expected_warning, ...) Asserts that the message in a triggered warning matches a regexp.
assertWcsAlmostEqualOverBBox(testCase, wcs0, ...) !Assert that two WCS are almost equal over a grid of pixel positions
assertWcsNearlyEqualOverBBox(*args, **kwargs)
assert_(*args, **kwargs)
countTestCases()
debug() Run the test without collecting errors in a TestResult
defaultTestResult()
doCleanups() Execute all cleanup functions.
fail([msg]) Fail immediately, with the given message.
failIf(*args, **kwargs)
failIfAlmostEqual(*args, **kwargs)
failIfEqual(*args, **kwargs)
failUnless(*args, **kwargs)
failUnlessAlmostEqual(*args, **kwargs)
failUnlessEqual(*args, **kwargs)
failUnlessRaises(*args, **kwargs)
id()
makeEndpoints(testCase) Generate a representative sample of Endpoints.
run([result])
setUp() Hook method for setting up the test fixture before exercising it.
setUpClass() Hook method for setting up class fixture before running tests in the class.
shortDescription() Returns a one-line description of the test, or None if no description has been provided.
skipTest(reason) Skip this test.
subTest([msg]) Return a context manager that will return the enclosed block of code in a subtest identified by the optional message and keyword parameters.
tearDown() Hook method for deconstructing the test fixture after testing it.
tearDownClass() Hook method for deconstructing the class fixture after running all tests in the class.

Attributes Documentation

longMessage = True
maxDiff = 640

Methods Documentation

__call__(*args, **kwds)[source]
addCleanup(function, *args, **kwargs)[source]

Add a function, with arguments, to be called when the test is completed. Functions added are called on a LIFO basis and are called after tearDown on test failure or success.

Cleanup items are called even if setUp fails (unlike tearDown).

addTypeEqualityFunc(typeobj, function)[source]

Add a type specific assertEqual style function to compare a type.

This method is for use by TestCase subclasses that need to register their own type equality functions to provide nicer error messages.

Args:
typeobj: The data type to call this function on when both values
are of the same type in assertEqual().
function: The callable taking two arguments and an optional
msg= argument that raises self.failureException with a useful error message when the two arguments are not equal.
assertAlmostEqual(first, second, places=None, msg=None, delta=None)[source]

Fail if the two objects are unequal as determined by their difference rounded to the given number of decimal places (default 7) and comparing to zero, or by comparing that the between the two objects is more than the given delta.

Note that decimal places (from zero) are usually not the same as significant digits (measured from the most significant digit).

If the two objects compare equal then they will automatically compare almost equal.

assertAlmostEquals(*args, **kwargs)
assertAnglesAlmostEqual(testCase, ang0, ang1, maxDiff=4.84814e-09 rad, ignoreWrap=True, msg='Angles differ')

!Assert that two angles are almost equal, ignoring wrap differences by default

@param[in] testCase unittest.TestCase instance the test is part of;
an object supporting one method: fail(self, msgStr)

@param[in] ang0 angle 0 (an lsst.afw.geom.Angle) @param[in] ang1 angle 1 (an lsst.afw.geom.Angle) @param[in] maxDiff maximum difference between the two angles (an lsst.afw.geom.Angle) @param[in] ignoreWrap ignore wrap when comparing the angles?

  • if True then wrap is ignored, e.g. 0 and 360 degrees are considered equal
  • if False then wrap matters, e.g. 0 and 360 degrees are considered different

@param[in] msg exception message prefix; details of the error are appended after ”: “

@throw AssertionError if the difference is greater than maxDiff

assertAnglesNearlyEqual(*args, **kwargs)
assertBoxesAlmostEqual(testCase, box0, box1, maxDiff=1e-07, msg='Boxes differ')

!Assert that two boxes (Box2D or Box2I) are almost equal

@warning Does not compare types, just compares values.

@param[in] testCase unittest.TestCase instance the test is part of;
an object supporting one method: fail(self, msgStr)

@param[in] box0 box 0 @param[in] box1 box 1 @param[in] maxDiff maximum radial separation between the min points and max points @param[in] msg exception message prefix; details of the error are appended after ”: “

@throw AssertionError if the radial difference of the min points or max points is greater than maxDiff

assertBoxesNearlyEqual(*args, **kwargs)
assertClose(*args, **kwargs)

Note

Deprecated in 12_0

assertCoordListsAlmostEqual(testCase, coordlist0, coordlist1, maxDiff=4.84814e-09 rad, msg=None)

!Assert that two lists of IcrsCoords represent almost the same point on the sky

@warning the coordinate systems are not compared; instead both sets of angles are converted to ICRS and the angular separation measured.

@param[in] testCase unittest.TestCase instance the test is part of;
an object supporting one method: fail(self, msgStr)

@param[in] coordlist0 list of IcrsCoords 0 @param[in] coordlist1 list of IcrsCoords 1 @param[in] maxDiff maximum angular separation, an lsst.afw.geom.Angle @param[in] msg exception message prefix; details of the error are appended after ”: “

assertCoordsAlmostEqual(testCase, coord0, coord1, maxDiff=4.84814e-09 rad, msg='Coords differ')

!Assert that two coords represent almost the same point on the sky

@warning the coordinate systems are not compared; instead both angles are converted to ICRS and the angular separation measured.

@param[in] testCase unittest.TestCase instance the test is part of;
an object supporting one method: fail(self, msgStr)

@param[in] coord0 coord 0 (an lsst.afw.geom.Coord) @param[in] coord1 coord 1 (an lsst.afw.geom.Coord) @param[in] maxDiff maximum angular separation between the two coords (an lsst.afw.geom.Angle) @param[in] msg exception message prefix; details of the error are appended after ”: “

@throw AssertionError if the unwrapped difference is greater than maxDiff

assertCoordsNearlyEqual(*args, **kwargs)
assertCountEqual(first, second, msg=None)[source]

An unordered sequence comparison asserting that the same elements, regardless of order. If the same element occurs more than once, it verifies that the elements occur the same number of times.

self.assertEqual(Counter(list(first)),
Counter(list(second)))
Example:
  • [0, 1, 1] and [1, 0, 1] compare equal.
  • [0, 0, 1] and [0, 1] compare unequal.
assertDictContainsSubset(subset, dictionary, msg=None)[source]

Checks whether dictionary is a superset of subset.

assertDictEqual(d1, d2, msg=None)[source]
assertEqual(first, second, msg=None)[source]

Fail if the two objects are unequal as determined by the ‘==’ operator.

assertEquals(*args, **kwargs)
assertFalse(expr, msg=None)[source]

Check that the expression is false.

assertFloatsAlmostEqual(testCase, lhs, rhs, rtol=2.220446049250313e-16, atol=2.220446049250313e-16, relTo=None, printFailures=True, plotOnFailure=False, plotFileName=None, invert=False, msg=None)

Highly-configurable floating point comparisons for scalars and arrays.

The test assertion will fail if all elements lhs and rhs are not equal to within the tolerances specified by rtol and atol. More precisely, the comparison is:

abs(lhs - rhs) <= relTo*rtol OR abs(lhs - rhs) <= atol

If rtol or atol is None, that term in the comparison is not performed at all.

When not specified, relTo is the elementwise maximum of the absolute values of lhs and rhs. If set manually, it should usually be set to either lhs or rhs, or a scalar value typical of what is expected.

Parameters:

testCase : unittest.TestCase

Instance the test is part of.

lhs : scalar or array-like

LHS value(s) to compare; may be a scalar or array-like of any dimension

rhs : scalar or array-like

RHS value(s) to compare; may be a scalar or array-like of any dimension

rtol : float or None

Relative tolerance for comparison; defaults to double-precision epsilon.

atol : float or None

Absolute tolerance for comparison; defaults to double-precision epsilon.

relTo : float

Value to which comparison with rtol is relative.

printFailures : bool

Upon failure, print all inequal elements as part of the message.

plotOnFailure : bool

Upon failure, plot the originals and their residual with matplotlib. Only 2-d arrays are supported.

plotFileName : str

Filename to save the plot to. If None, the plot will be displayed in a window.

invert : bool

If True, invert the comparison and fail only if any elements are equal. Used to implement assertFloatsNotEqual, which should generally be used instead for clarity.

msg : str

String to append to the error message when assert fails.

assertFloatsEqual(testCase, lhs, rhs, **kwargs)

Assert that lhs == rhs (both numeric types, whether scalar or array).

See assertFloatsAlmostEqual (called with rtol=atol=0) for more information.

assertFloatsNotEqual(testCase, lhs, rhs, **kwds)

Fail a test if the given floating point values are equal to within the given tolerances.

See assertFloatsAlmostEqual (called with rtol=atol=0) for more information.

assertGreater(a, b, msg=None)[source]

Just like self.assertTrue(a > b), but with a nicer default message.

assertGreaterEqual(a, b, msg=None)[source]

Just like self.assertTrue(a >= b), but with a nicer default message.

assertImagesAlmostEqual(testCase, image0, image1, skipMask=None, rtol=1e-05, atol=1e-08, msg='Images differ')

!Assert that two images are almost equal, including non-finite values

@param[in] testCase unittest.TestCase instance the test is part of;
an object supporting one method: fail(self, msgStr)
@param[in] image0 image 0, an lsst.afw.image.Image, lsst.afw.image.Mask,
or transposed numpy array (see warning)
@param[in] image1 image 1, an lsst.afw.image.Image, lsst.afw.image.Mask,
or transposed numpy array (see warning)
@param[in] skipMask mask of pixels to skip, or None to compare all pixels;
an lsst.afw.image.Mask, lsst.afw.image.Image, or transposed numpy array (see warning); all non-zero pixels are skipped

@param[in] rtol maximum allowed relative tolerance; more info below @param[in] atol maximum allowed absolute tolerance; more info below @param[in] msg exception message prefix; details of the error are appended after ”: “

The images are nearly equal if all pixels obey:
|val1 - val0| <= rtol*|val1| + atol

or, for float types, if nan/inf/-inf pixels match.

@warning the comparison equation is not symmetric, so in rare cases the assertion may give different results depending on which image comes first.

@warning the axes of numpy arrays are transposed with respect to Image and Mask data. Thus for example if image0 and image1 are both lsst.afw.image.ImageD with dimensions (2, 3) and skipMask is a numpy array, then skipMask must have shape (3, 2).

@throw self.failureException (usually AssertionError) if any of the following are true for un-skipped pixels: - non-finite values differ in any way (e.g. one is “nan” and another is not) - finite values differ by too much, as defined by atol and rtol

@throw TypeError if the dimensions of image0, image1 and skipMask do not match, or any are not of a numeric data type.

assertImagesEqual(*args, **kwds)

!Assert that two images are exactly equal, including non-finite values.

All arguments are forwarded to assertAnglesAlmostEqual aside from atol and rtol, which are set to zero.

assertImagesNearlyEqual(*args, **kwargs)
assertIn(member, container, msg=None)[source]

Just like self.assertTrue(a in b), but with a nicer default message.

assertIs(expr1, expr2, msg=None)[source]

Just like self.assertTrue(a is b), but with a nicer default message.

assertIsInstance(obj, cls, msg=None)[source]

Same as self.assertTrue(isinstance(obj, cls)), with a nicer default message.

assertIsNone(obj, msg=None)[source]

Same as self.assertTrue(obj is None), with a nicer default message.

assertIsNot(expr1, expr2, msg=None)[source]

Just like self.assertTrue(a is not b), but with a nicer default message.

assertIsNotNone(obj, msg=None)[source]

Included for symmetry with assertIsNone.

assertLess(a, b, msg=None)[source]

Just like self.assertTrue(a < b), but with a nicer default message.

assertLessEqual(a, b, msg=None)[source]

Just like self.assertTrue(a <= b), but with a nicer default message.

assertListEqual(list1, list2, msg=None)[source]

A list-specific equality assertion.

Args:

list1: The first list to compare. list2: The second list to compare. msg: Optional message to use on failure instead of a list of

differences.
assertLogs(logger=None, level=None)[source]

Fail unless a log message of level level or higher is emitted on logger_name or its children. If omitted, level defaults to INFO and logger defaults to the root logger.

This method must be used as a context manager, and will yield a recording object with two attributes: output and records. At the end of the context manager, the output attribute will be a list of the matching formatted log messages and the records attribute will be a list of the corresponding LogRecord objects.

Example:

with self.assertLogs('foo', level='INFO') as cm:
    logging.getLogger('foo').info('first message')
    logging.getLogger('foo.bar').error('second message')
self.assertEqual(cm.output, ['INFO:foo:first message',
                             'ERROR:foo.bar:second message'])
assertMaskedImagesAlmostEqual(testCase, maskedImage0, maskedImage1, doImage=True, doMask=True, doVariance=True, skipMask=None, rtol=1e-05, atol=1e-08, msg='Masked images differ')

!Assert that two masked images are nearly equal, including non-finite values

@param[in] testCase unittest.TestCase instance the test is part of;
an object supporting one method: fail(self, msgStr)
@param[in] maskedImage0 masked image 0 (an lsst.afw.image.MaskedImage or
collection of three transposed numpy arrays: image, mask, variance)
@param[in] maskedImage1 masked image 1 (an lsst.afw.image.MaskedImage or
collection of three transposed numpy arrays: image, mask, variance)

@param[in] doImage compare image planes if True @param[in] doMask compare mask planes if True @param[in] doVariance compare variance planes if True @param[in] skipMask mask of pixels to skip, or None to compare all pixels;

an lsst.afw.image.Mask, lsst.afw.image.Image, or transposed numpy array; all non-zero pixels are skipped

@param[in] rtol maximum allowed relative tolerance; more info below @param[in] atol maximum allowed absolute tolerance; more info below @param[in] msg exception message prefix; details of the error are appended after ”: “

The mask planes must match exactly. The image and variance planes are nearly equal if all pixels obey:
|val1 - val0| <= rtol*|val1| + atol

or, for float types, if nan/inf/-inf pixels match.

@warning the comparison equation is not symmetric, so in rare cases the assertion may give different results depending on which masked image comes first.

@warning the axes of numpy arrays are transposed with respect to MaskedImage data. Thus for example if maskedImage0 and maskedImage1 are both lsst.afw.image.MaskedImageD with dimensions (2, 3) and skipMask is a numpy array, then skipMask must have shape (3, 2).

@throw self.failureException (usually AssertionError) if any of the following are true for un-skipped pixels: - non-finite image or variance values differ in any way (e.g. one is “nan” and another is not) - finite values differ by too much, as defined by atol and rtol - mask pixels differ at all

@throw TypeError if the dimensions of maskedImage0, maskedImage1 and skipMask do not match, either image or variance plane is not of a numeric data type, either mask plane is not of an integer type (unsigned or signed), or skipMask is not of a numeric data type.

assertMaskedImagesEqual(*args, **kwds)

!Assert that two masked images are exactly equal, including non-finite values.

All arguments are forwarded to assertMaskedImagesAlmostEqual aside from atol and rtol, which are set to zero.

assertMaskedImagesNearlyEqual(*args, **kwargs)
assertMasksEqual(testCase, mask0, mask1, skipMask=None, msg='Masks differ')

!Assert that two masks are equal

@param[in] testCase unittest.TestCase instance the test is part of;
an object supporting one method: fail(self, msgStr)
@param[in] mask0 mask 0, an lsst.afw.image.Mask, lsst.afw.image.Image,
or transposed numpy array (see warning)
@param[in] mask1 mask 1, an lsst.afw.image.Mask, lsst.afw.image.Image,
or transposed numpy array (see warning)
@param[in] skipMask mask of pixels to skip, or None to compare all pixels;
an lsst.afw.image.Mask, lsst.afw.image.Image, or transposed numpy array (see warning); all non-zero pixels are skipped

@param[in] msg exception message prefix; details of the error are appended after ”: “

@warning the axes of numpy arrays are transposed with respect to Mask and Image. Thus for example if mask0 and mask1 are both lsst.afw.image.Mask with dimensions (2, 3) and skipMask is a numpy array, then skipMask must have shape (3, 2).

@throw self.failureException (usually AssertionError) if any any un-skipped pixels differ

@throw TypeError if the dimensions of mask0, mask1 and skipMask do not match, or any are not of a numeric data type.

assertMultiLineEqual(first, second, msg=None)[source]

Assert that two multi-line strings are equal.

assertNotAlmostEqual(first, second, places=None, msg=None, delta=None)[source]

Fail if the two objects are equal as determined by their difference rounded to the given number of decimal places (default 7) and comparing to zero, or by comparing that the between the two objects is less than the given delta.

Note that decimal places (from zero) are usually not the same as significant digits (measured from the most significant digit).

Objects that are equal automatically fail.

assertNotAlmostEquals(*args, **kwargs)
assertNotClose(*args, **kwargs)

Note

Deprecated in 12_0

assertNotEqual(first, second, msg=None)[source]

Fail if the two objects are equal as determined by the ‘!=’ operator.

assertNotEquals(*args, **kwargs)
assertNotIn(member, container, msg=None)[source]

Just like self.assertTrue(a not in b), but with a nicer default message.

assertNotIsInstance(obj, cls, msg=None)[source]

Included for symmetry with assertIsInstance.

assertNotRegex(text, unexpected_regex, msg=None)[source]

Fail the test if the text matches the regular expression.

assertNotRegexpMatches(*args, **kwargs)
assertPairListsAlmostEqual(testCase, list0, list1, maxDiff=1e-07, msg=None)

!Assert that two lists of Cartesian points are almost equal

Each point can be any indexable pair of two floats, including Point2D or Extent2D, a list or a tuple.

@warning Does not compare types, just values.

@param[in] testCase unittest.TestCase instance the test is part of;
an object supporting one method: fail(self, msgStr)

@param[in] list0 list of pairs 0 (each element a pair of floats) @param[in] list1 list of pairs 1 @param[in] maxDiff maximum radial separation between the two points @param[in] msg additional information for the error message; appended after ”: “

@throw AssertionError if the radial difference is greater than maxDiff

assertPairsAlmostEqual(testCase, pair0, pair1, maxDiff=1e-07, msg='Pairs differ')

!Assert that two Cartesian points are almost equal.

Each point can be any indexable pair of two floats, including Point2D or Extent2D, a list or a tuple.

@warning Does not compare types, just compares values.

@param[in] testCase unittest.TestCase instance the test is part of;
an object supporting one method: fail(self, msgStr)

@param[in] pair0 pair 0 (a pair of floats) @param[in] pair1 pair 1 (a pair of floats) @param[in] maxDiff maximum radial separation between the two points @param[in] msg exception message prefix; details of the error are appended after ”: “

@throw AssertionError if the radial difference is greater than maxDiff

assertPairsNearlyEqual(*args, **kwargs)
assertRaises(expected_exception, *args, **kwargs)[source]

Fail unless an exception of class expected_exception is raised by the callable when invoked with specified positional and keyword arguments. If a different type of exception is raised, it will not be caught, and the test case will be deemed to have suffered an error, exactly as for an unexpected exception.

If called with the callable and arguments omitted, will return a context object used like this:

with self.assertRaises(SomeException):
    do_something()

An optional keyword argument ‘msg’ can be provided when assertRaises is used as a context object.

The context manager keeps a reference to the exception as the ‘exception’ attribute. This allows you to inspect the exception after the assertion:

with self.assertRaises(SomeException) as cm:
    do_something()
the_exception = cm.exception
self.assertEqual(the_exception.error_code, 3)
assertRaisesLsstCpp(testcase, excClass, callableObj, *args, **kwargs)

Note

Deprecated in 12_0

assertRaisesRegex(expected_exception, expected_regex, *args, **kwargs)[source]

Asserts that the message in a raised exception matches a regex.

Args:

expected_exception: Exception class expected to be raised. expected_regex: Regex (re pattern object or string) expected

to be found in error message.

args: Function to be called and extra positional args. kwargs: Extra kwargs. msg: Optional message used in case of failure. Can only be used

when assertRaisesRegex is used as a context manager.
assertRaisesRegexp(*args, **kwargs)
assertRegex(text, expected_regex, msg=None)[source]

Fail the test unless the text matches the regular expression.

assertRegexpMatches(*args, **kwargs)
assertSequenceEqual(seq1, seq2, msg=None, seq_type=None)[source]

An equality assertion for ordered sequences (like lists and tuples).

For the purposes of this function, a valid ordered sequence type is one which can be indexed, has a length, and has an equality operator.

Args:

seq1: The first sequence to compare. seq2: The second sequence to compare. seq_type: The expected datatype of the sequences, or None if no

datatype should be enforced.
msg: Optional message to use on failure instead of a list of
differences.
assertSetEqual(set1, set2, msg=None)[source]

A set-specific equality assertion.

Args:

set1: The first set to compare. set2: The second set to compare. msg: Optional message to use on failure instead of a list of

differences.

assertSetEqual uses ducktyping to support different types of sets, and is optimized for sets specifically (parameters must support a difference method).

assertSpherePointListsAlmostEqual(testCase, splist0, splist1, maxSep=4.84814e-09 rad, msg=None)

!Assert that two lists of SpherePoints are almost equal

@param[in] testCase unittest.TestCase instance the test is part of;
an object supporting one method: fail(self, msgStr)

@param[in] splist0 list of SpherePoints 0 @param[in] splist1 list of SpherePoints 1 @param[in] maxSep maximum separation, an lsst.afw.geom.Angle @param[in] msg exception message prefix; details of the error are appended after ”: “

assertSpherePointsAlmostEqual(testCase, sp0, sp1, maxSep=4.84814e-09 rad, msg='')

!Assert that two SpherePoints are almost equal

@param[in] testCase unittest.TestCase instance the test is part of;
an object supporting one method: fail(self, msgStr)

@param[in] sp0 SpherePoint 0 @param[in] sp1 SpherePoint 1 @param[in] maxSep maximum separation, an lsst.afw.geom.Angle @param[in] msg extra information to be printed with any error message

assertTrue(expr, msg=None)[source]

Check that the expression is true.

assertTupleEqual(tuple1, tuple2, msg=None)[source]

A tuple-specific equality assertion.

Args:

tuple1: The first tuple to compare. tuple2: The second tuple to compare. msg: Optional message to use on failure instead of a list of

differences.
assertWarns(expected_warning, *args, **kwargs)[source]

Fail unless a warning of class warnClass is triggered by the callable when invoked with specified positional and keyword arguments. If a different type of warning is triggered, it will not be handled: depending on the other warning filtering rules in effect, it might be silenced, printed out, or raised as an exception.

If called with the callable and arguments omitted, will return a context object used like this:

with self.assertWarns(SomeWarning):
    do_something()

An optional keyword argument ‘msg’ can be provided when assertWarns is used as a context object.

The context manager keeps a reference to the first matching warning as the ‘warning’ attribute; similarly, the ‘filename’ and ‘lineno’ attributes give you information about the line of Python code from which the warning was triggered. This allows you to inspect the warning after the assertion:

with self.assertWarns(SomeWarning) as cm:
    do_something()
the_warning = cm.warning
self.assertEqual(the_warning.some_attribute, 147)
assertWarnsRegex(expected_warning, expected_regex, *args, **kwargs)[source]

Asserts that the message in a triggered warning matches a regexp. Basic functioning is similar to assertWarns() with the addition that only warnings whose messages also match the regular expression are considered successful matches.

Args:

expected_warning: Warning class expected to be triggered. expected_regex: Regex (re pattern object or string) expected

to be found in error message.

args: Function to be called and extra positional args. kwargs: Extra kwargs. msg: Optional message used in case of failure. Can only be used

when assertWarnsRegex is used as a context manager.
assertWcsAlmostEqualOverBBox(testCase, wcs0, wcs1, bbox, maxDiffSky=4.84814e-08 rad, maxDiffPix=0.01, nx=5, ny=5, msg='WCSs differ')

!Assert that two WCS are almost equal over a grid of pixel positions

Compare pixelToSky and skyToPixel for two WCS over a rectangular grid of pixel positions. If the WCS are too divergent at any point, call testCase.fail; the message describes the largest error measured in pixel coordinates (if sky to pixel error was excessive) and sky coordinates (if pixel to sky error was excessive) across the entire pixel grid.

@param[in] testCase unittest.TestCase instance the test is part of;
an object supporting one method: fail(self, msgStr)

@param[in] wcs0 WCS 0 (an lsst.afw.geom.SkyWcs) @param[in] wcs1 WCS 1 (an lsst.afw.geom.SkyWcs) @param[in] bbox boundaries of pixel grid over which to compare the WCSs (an lsst.afw.geom.Box2I or Box2D) @param[in] maxDiffSky maximum separation between sky positions computed using Wcs.pixelToSky

(an lsst.afw.geom.Angle)

@param[in] maxDiffPix maximum separation between pixel positions computed using Wcs.skyToPixel @param[in] nx number of points in x for the grid of pixel positions @param[in] ny number of points in y for the grid of pixel positions @param[in] msg exception message prefix; details of the error are appended after ”: “

assertWcsNearlyEqualOverBBox(*args, **kwargs)
assert_(*args, **kwargs)
countTestCases()[source]
debug()[source]

Run the test without collecting errors in a TestResult

defaultTestResult()[source]
doCleanups()[source]

Execute all cleanup functions. Normally called for you after tearDown.

fail(msg=None)[source]

Fail immediately, with the given message.

failIf(*args, **kwargs)
failIfAlmostEqual(*args, **kwargs)
failIfEqual(*args, **kwargs)
failUnless(*args, **kwargs)
failUnlessAlmostEqual(*args, **kwargs)
failUnlessEqual(*args, **kwargs)
failUnlessRaises(*args, **kwargs)
id()[source]
makeEndpoints(testCase)

Generate a representative sample of Endpoints.

Returns:

x : list

List of endpoints with enough diversity to exercise Endpoint-related code. Each invocation of this method shall return independent objects.

run(result=None)[source]
setUp()[source]

Hook method for setting up the test fixture before exercising it.

setUpClass()[source]

Hook method for setting up class fixture before running tests in the class.

shortDescription()[source]

Returns a one-line description of the test, or None if no description has been provided.

The default implementation of this method returns the first line of the specified test method’s docstring.

skipTest(reason)[source]

Skip this test.

subTest(msg=<object object>, **params)[source]

Return a context manager that will return the enclosed block of code in a subtest identified by the optional message and keyword parameters. A failure in the subtest marks the test case as failed but resumes execution at the end of the enclosed block, allowing further test code to be executed.

tearDown()[source]

Hook method for deconstructing the test fixture after testing it.

tearDownClass()[source]

Hook method for deconstructing the class fixture after running all tests in the class.