# TestCase¶

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

Bases: unittest.case.TestCase

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

Methods Summary

 assertAmplifiersEqual(amp1, amp2) assertAnglesAlmostEqual(ang0, ang1[, …]) Assert that two Angles are almost equal, ignoring wrap differences by default. assertBoxesAlmostEqual(box0, box1[, …]) Assert that two boxes (Box2D or Box2I) are almost equal assertCamerasEqual(camera1, camera2, **kwds) Compare two Camers. assertDetectorCollectionsEqual(collection1, …) Compare two DetectorCollections. assertDetectorsEqual(detector1, detector2, *) Compare two Detectors. assertFloatsAlmostEqual(lhs, numpy.ndarray], …) Highly-configurable floating point comparisons for scalars and arrays. assertFloatsEqual(lhs, numpy.ndarray], rhs, …) Assert that lhs == rhs (both numeric types, whether scalar or array). assertFloatsNotEqual(lhs, numpy.ndarray], …) Fail a test if the given floating point values are equal to within the given tolerances. assertImagesAlmostEqual(image0, image1[, …]) !Assert that two images are almost equal, including non-finite values assertImagesEqual(**kwds) !Assert that two images are exactly equal, including non-finite values. assertMaskedImagesAlmostEqual(maskedImage0, …) !Assert that two masked images are nearly equal, including non-finite values assertMaskedImagesEqual(**kwds) !Assert that two masked images are exactly equal, including non-finite values. assertMasksEqual(mask0, mask1[, skipMask, msg]) !Assert that two masks are equal assertPairListsAlmostEqual(list0, list1[, …]) Assert that two lists of Cartesian points are almost equal assertPairsAlmostEqual(pair0, pair1[, …]) Assert that two Cartesian points are almost equal. assertSchemasEqual(schema1, schema2[, flags]) Assert that two Schemas are equal. assertSpherePointListsAlmostEqual(splist0, …) Assert that two lists of SpherePoints are almost equal assertSpherePointsAlmostEqual(sp0, sp1[, …]) Assert that two SpherePoints are almost equal assertTransformMapsEqual(map1, map2, **kwds) Compare two TransformMaps. assertWcsAlmostEqualOverBBox(wcs0, wcs1, bbox) Assert that two WCS are almost equal over a grid of pixel positions compare2DFunctions(func1, func2[, minVal, …]) Compare two Point2D(Point2D) functions by evaluating them over a range of values. makeEndpoints() Generate a representative sample of Endpoints.

Methods Documentation

assertAmplifiersEqual(amp1, amp2)
assertAnglesAlmostEqual(ang0, ang1, maxDiff=4.84814e-09 rad, ignoreWrap=True, msg='Angles differ')

Assert that two Angles are almost equal, ignoring wrap differences by default.

If both arguments are NaN the assert will pass. If one of the arguments is NaN but the other is not the assert will fail.

Parameters: testCase : unittest.TestCase test case the test is part of; an object supporting one method: fail(self, msgStr) ang0 : lsst.geom.Angle angle 0 ang1 : lsst.geom.Angle angle 1 maxDiff : lsst.geom.Angle maximum difference between the two angles ignoreWrap : bool 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 msg : str exception message prefix; details of the error are appended after “: “ AssertionError Raised if the difference is greater than maxDiff
assertBoxesAlmostEqual(box0, box1, maxDiff=1e-07, msg='Boxes differ')

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

Parameters: testCase : unittest.TestCase test case the test is part of; an object supporting one method: fail(self, msgStr) box0 : box 0 box1 : box 1 maxDiff : float maximum radial separation between the min points and max points msg : str exception message prefix; details of the error are appended after “: “ AssertionError Raised if the radial difference of the min points or max points is greater than maxDiff

Notes

Warning

Does not compare types, just compares values.

assertCamerasEqual(camera1, camera2, **kwds)

Compare two Camers.

assertDetectorCollectionsEqual(collection1, collection2, **kwds)

Compare two DetectorCollections.

assertDetectorsEqual(detector1, detector2, *, compareTransforms=True, **kwds)

Compare two Detectors.

assertFloatsAlmostEqual(lhs: Union[float, numpy.ndarray], rhs: Union[float, numpy.ndarray], rtol: Optional[float] = 2.220446049250313e-16, atol: Optional[float] = 2.220446049250313e-16, relTo: Optional[float] = None, printFailures: bool = True, plotOnFailure: bool = False, plotFileName: Optional[str] = None, invert: bool = False, msg: Optional[str] = None, ignoreNaNs: bool = False) → 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, optional Relative tolerance for comparison; defaults to double-precision epsilon. atol : float, optional Absolute tolerance for comparison; defaults to double-precision epsilon. relTo : float, optional Value to which comparison with rtol is relative. printFailures : bool, optional Upon failure, print all inequal elements as part of the message. plotOnFailure : bool, optional Upon failure, plot the originals and their residual with matplotlib. Only 2-d arrays are supported. plotFileName : str, optional Filename to save the plot to. If None, the plot will be displayed in a window. invert : bool, optional 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. will return True). msg : str, optional String to append to the error message when assert fails. ignoreNaNs : bool, optional If True (False is default) mask out any NaNs from operand arrays before performing comparisons if they are in the same locations; NaNs in different locations are trigger test assertion failures, even when invert=True. Scalar NaNs are treated like arrays containing only NaNs of the same shape as the other operand, and no comparisons are performed if both sides are scalar NaNs. AssertionError The values are not almost equal.
assertFloatsEqual(lhs: Union[float, numpy.ndarray], rhs: Union[float, numpy.ndarray], **kwargs) → None

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

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

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. AssertionError The values are not equal.
assertFloatsNotEqual(lhs: Union[float, numpy.ndarray], rhs: Union[float, numpy.ndarray], **kwds) → None

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.

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. AssertionError The values are almost equal.
assertImagesAlmostEqual(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(**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.

assertMaskedImagesAlmostEqual(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)
collection of three transposed numpy arrays: image, mask, variance)
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(**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.

assertMasksEqual(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)
or transposed numpy array (see warning)
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.

assertPairListsAlmostEqual(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.

Parameters: testCase : unittest.TestCase test case the test is part of; an object supporting one method: fail(self, msgStr) list0 : list of pairs of float list of pairs 0 list1 : list of pairs of float list of pairs 1 maxDiff : float maximum radial separation between the two points msg : str additional information for the error message; appended after “: “ AssertionError Raised if the radial difference is greater than maxDiff

Notes

Warning

Does not compare types, just values.

assertPairsAlmostEqual(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.

Parameters: testCase : unittest.TestCase test case the test is part of; an object supporting one method: fail(self, msgStr) pair0 : pair of float pair 0 pair1 : pair of floats pair 1 maxDiff : float maximum radial separation between the two points msg : str exception message prefix; details of the error are appended after “: “ AssertionError Raised if the radial difference is greater than maxDiff

Notes

Warning

Does not compare types, just compares values.

assertSchemasEqual(schema1, schema2, flags=31)

Assert that two Schemas are equal.

Generates a message from the difference between the schemas; see diffSchemas() for more information.

Parameters: testCase Comparison test case that should fail is schemas differ. schema1 : lsst.afw.table.Schema First input schema. schema2 : lsst.afw.table.Schema Second input schema. flags : int A bitwise OR of lsst.afw.table.Schema.ComparisonFlags indicating which features of schema items to compare.
assertSpherePointListsAlmostEqual(splist0, splist1, maxSep=4.84814e-09 rad, msg=None)

Assert that two lists of SpherePoints are almost equal

Parameters: testCase : unittest.TestCase test case the test is part of; an object supporting one method: fail(self, msgStr) splist0 : list of SpherePoints 0 splist1 : list of SpherePoints 1 maxSep : lsst.geom.Angle maximum separation msg : str exception message prefix; details of the error are appended after “: “ AssertionError The SpherePoint lists are not equal.
assertSpherePointsAlmostEqual(sp0, sp1, maxSep=4.84814e-09 rad, msg='')

Assert that two SpherePoints are almost equal

Parameters: testCase : unittest.TestCase test case the test is part of; an object supporting one method: fail(self, msgStr) sp0 : lsst.geom.SpherePoint SpherePoint 0 sp1 : lsst.geom.SpherePoint SpherePoint 1 maxSep : lsst.geom.Angle maximum separation msg : str extra information to be printed with any error message AssertionError The SpherePoints are not equal.
assertTransformMapsEqual(map1, map2, **kwds)

Compare two TransformMaps.

assertWcsAlmostEqualOverBBox(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.

Parameters: testCase : unittest.TestCase test case the test is part of; an object supporting one method: fail(self, msgStr) wcs0 : lsst.afw.geom.SkyWcs WCS 0 wcs1 : lsst.afw.geom.SkyWcs WCS 1 bbox : boundaries of pixel grid over which to compare the WCSs maxDiffSky : lsst.geom.Angle maximum separation between sky positions computed using Wcs.pixelToSky maxDiffPix : float maximum separation between pixel positions computed using Wcs.skyToPixel nx : int number of points in x for the grid of pixel positions ny : int number of points in y for the grid of pixel positions msg : str exception message prefix; details of the error are appended after “: “
compare2DFunctions(func1, func2, minVal=-10, maxVal=None, nVal=5)

Compare two Point2D(Point2D) functions by evaluating them over a range of values.

makeEndpoints()

Generate a representative sample of Endpoints.

Parameters: testCase : unittest.TestCase test case the test is part of; an object supporting one method: fail(self, msgStr) endpoints : list List of endpoints with enough diversity to exercise Endpoint-related code. Each invocation of this method shall return independent objects.