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

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
assertClose(**kwargs)

Note

Deprecated in 12_0

assertFloatsAlmostEqual(lhs, rhs[, rtol, …]) Highly-configurable floating point comparisons for scalars and arrays.
assertFloatsEqual(lhs, rhs, **kwargs) Assert that lhs == rhs (both numeric types, whether scalar or array).
assertFloatsNotEqual(lhs, rhs, **kwds) 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
assertNotClose(**kwargs)

Note

Deprecated in 12_0

assertPairListsAlmostEqual(list0, list1[, …]) Assert that two lists of Cartesian points are almost equal
assertPairsAlmostEqual(pair0, pair1[, …]) Assert that two Cartesian points are almost equal.
assertRaisesLsstCpp(excClass, callableObj, …)

Note

Deprecated in 12_0

assertSpherePointListsAlmostEqual(splist0, …) Assert that two lists of SpherePoints are almost equal
assertSpherePointsAlmostEqual(sp0, sp1[, …]) Assert that two SpherePoints are almost equal
assertWcsAlmostEqualOverBBox(wcs0, wcs1, bbox) Assert that two WCS are almost equal over a grid of pixel positions
makeEndpoints() Generate a representative sample of Endpoints.

Methods Documentation

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

Parameters:
testCase : unittest.TestCase

test case the test is part of; an object supporting one method: fail(self, msgStr)

ang0 : lsst.afw.geom.Angle

angle 0

ang1 : an lsst.afw.geom.Angle

angle 1

maxDiff : an lsst.afw.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 “: “

Raises:
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 : lsst.afw.geom.Box2D or lsst.afw.geom.Box2I

box 0

box1 : lsst.afw.geom.Box2D or lsst.afw.geom.Box2I

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 “: “

Raises:
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.

assertClose(**kwargs)

Note

Deprecated in 12_0

assertFloatsAlmostEqual(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, 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.

msg : str, optional

String to append to the error message when assert fails.

Raises:
AssertionError

The values are not almost equal.

assertFloatsEqual(lhs, rhs, **kwargs)

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.

Raises:
AssertionError

The values are not equal.

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

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.

Raises:
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)
@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(**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)
@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.

assertNotClose(**kwargs)

Note

Deprecated in 12_0

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 “: “

Raises:
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 “: “

Raises:
AssertionError

Raised if the radial difference is greater than maxDiff

Notes

Warning

Does not compare types, just compares values.

assertRaisesLsstCpp(excClass, callableObj, *args, **kwargs)

Note

Deprecated in 12_0

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 lsst.afw.geom.SpherePoint

list of SpherePoints 0

splist1 : list of lsst.afw.geom.SpherePoint

list of SpherePoints 1

maxSep : lsst.afw.geom.Angle

maximum separation

msg : str

exception message prefix; details of the error are appended after “: “

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.afw.geom.SpherePoint

SpherePoint 0

sp1 : lsst.afw.geom.SpherePoint

SpherePoint 1

maxSep : lsst.afw.geom.Angle

maximum separation

msg : str

extra information to be printed with any error message

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 : lsst.geom.Box2I or lsst.geom.Box2D

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 “: “

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)

Returns:
endpoints : list

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