TestCase

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

Bases: 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, 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

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(list(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=Angle(2.7777777777777781e-07, degrees), 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:
testCaseunittest.TestCase

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

ang0lsst.geom.Angle

angle 0

ang1lsst.geom.Angle

angle 1

maxDifflsst.geom.Angle

maximum difference between the two angles

ignoreWrapbool

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

msgstr

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:
testCaseunittest.TestCase

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

box0lsst.geom.Box2D or lsst.geom.Box2I

box 0

box1lsst.geom.Box2D or lsst.geom.Box2I

box 1

maxDifffloat

maximum radial separation between the min points and max points

msgstr

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.

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: float | ndarray, rhs: float | ndarray, rtol: float | None = 2.220446049250313e-16, atol: float | None = 2.220446049250313e-16, relTo: float | None = None, printFailures: bool = True, plotOnFailure: bool = False, plotFileName: str | None = None, invert: bool = False, msg: str | None = 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:
testCaseunittest.TestCase

Instance the test is part of.

lhsscalar or array-like

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

rhsscalar or array-like

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

rtolfloat, optional

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

atolfloat, optional

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

relTofloat, optional

Value to which comparison with rtol is relative.

printFailuresbool, optional

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

plotOnFailurebool, optional

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

plotFileNamestr, optional

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

invertbool, 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).

msgstr, optional

String to append to the error message when assert fails.

ignoreNaNsbool, 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.

Raises:
AssertionError

The values are not almost equal.

assertFloatsEqual(lhs: float | ndarray, rhs: float | ndarray, **kwargs: Any) None

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

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

Parameters:
testCaseunittest.TestCase

Instance the test is part of.

lhsscalar or array-like

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

rhsscalar or array-like

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

**kwargsAny

Keyword parameters forwarded to assertFloatsAlmostEqual.

Raises:
AssertionError

The values are not equal.

assertFloatsNotEqual(lhs: float | ndarray, rhs: float | ndarray, **kwds: Any) 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:
testCaseunittest.TestCase

Instance the test is part of.

lhsscalar or array-like

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

rhsscalar or array-like

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

**kwdsAny

Keyword parameters forwarded to assertFloatsAlmostEqual.

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.

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:
testCaseunittest.TestCase

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

list0list of pairs of float

list of pairs 0

list1list of pairs of float

list of pairs 1

maxDifffloat

maximum radial separation between the two points

msgstr

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:
testCaseunittest.TestCase

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

pair0pair of float

pair 0

pair1pair of floats

pair 1

maxDifffloat

maximum radial separation between the two points

msgstr

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.

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.

schema1lsst.afw.table.Schema

First input schema.

schema2lsst.afw.table.Schema

Second input schema.

flagsint

A bitwise OR of lsst.afw.table.Schema.ComparisonFlags indicating which features of schema items to compare.

assertSpherePointListsAlmostEqual(splist0, splist1, maxSep=Angle(2.7777777777777781e-07, degrees), msg=None)

Assert that two lists of SpherePoints are almost equal

Parameters:
testCaseunittest.TestCase

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

splist0list of lsst.geom.SpherePoint

list of SpherePoints 0

splist1list of lsst.geom.SpherePoint

list of SpherePoints 1

maxSeplsst.geom.Angle

maximum separation

msgstr

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

Raises:
AssertionError

The SpherePoint lists are not equal.

assertSpherePointsAlmostEqual(sp0, sp1, maxSep=Angle(2.7777777777777781e-07, degrees), msg='')

Assert that two SpherePoints are almost equal

Parameters:
testCaseunittest.TestCase

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

sp0lsst.geom.SpherePoint

SpherePoint 0

sp1lsst.geom.SpherePoint

SpherePoint 1

maxSeplsst.geom.Angle

maximum separation

msgstr

extra information to be printed with any error message

Raises:
AssertionError

The SpherePoints are not equal.

assertTransformMapsEqual(map1, map2, **kwds)

Compare two TransformMaps.

assertWcsAlmostEqualOverBBox(wcs0, wcs1, bbox, maxDiffSky=Angle(2.7777777777777779e-06, degrees), 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:
testCaseunittest.TestCase

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

wcs0lsst.afw.geom.SkyWcs

WCS 0

wcs1lsst.afw.geom.SkyWcs

WCS 1

bboxlsst.geom.Box2I or lsst.geom.Box2D

boundaries of pixel grid over which to compare the WCSs

maxDiffSkylsst.geom.Angle

maximum separation between sky positions computed using Wcs.pixelToSky

maxDiffPixfloat

maximum separation between pixel positions computed using Wcs.skyToPixel

nxint

number of points in x for the grid of pixel positions

nyint

number of points in y for the grid of pixel positions

msgstr

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

compare2DFunctions(func1, func2, minVal=-10, maxVal=None, nVal=5)

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

Notes

Assumes the functions can be called with list[Point2D] and return list[Point2D].

makeEndpoints()

Generate a representative sample of Endpoints.

Parameters:
testCaseunittest.TestCase

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

Returns:
endpointslist

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