1 from __future__
import absolute_import, division
23 """Utilities that should be imported into the lsst.afw.geom namespace when lsst.afw.geom is used
25 In the case of the assert functions, importing them makes them available in lsst.utils.tests.TestCase
32 __all__ = [
"assertAnglesNearlyEqual",
"assertPairsNearlyEqual",
"assertBoxesNearlyEqual"]
34 @lsst.utils.tests.inTestCase
36 ignoreWrap=
True, msg=
"Angles differ"):
37 """!Assert that two angles are nearly equal, ignoring wrap differences by default
39 @param[in] testCase unittest.TestCase instance the test is part of;
40 an object supporting one method: fail(self, msgStr)
41 @param[in] ang0 angle 0 (an lsst.afw.geom.Angle)
42 @param[in] ang1 angle 1 (an lsst.afw.geom.Angle)
43 @param[in] maxDiff maximum difference between the two angles (an lsst.afw.geom.Angle)
44 @param[in] ignoreWrap ignore wrap when comparing the angles?
45 - if True then wrap is ignored, e.g. 0 and 360 degrees are considered equal
46 - if False then wrap matters, e.g. 0 and 360 degrees are considered different
47 @param[in] msg exception message prefix; details of the error are appended after ": "
49 @throw AssertionError if the difference is greater than maxDiff
51 measDiff = ang1 - ang0
54 if abs(measDiff) > maxDiff:
55 testCase.fail(
"%s: measured difference %s arcsec > max allowed %s arcsec" %
56 (msg, measDiff.asArcseconds(), maxDiff.asArcseconds()))
58 @lsst.utils.tests.inTestCase
60 """!Assert that two planar pairs (e.g. Point2D or Extent2D) are nearly equal
62 @warning Does not compare types, just compares values.
64 @param[in] testCase unittest.TestCase instance the test is part of;
65 an object supporting one method: fail(self, msgStr)
66 @param[in] pair0 pair 0 (a pair of floats)
67 @param[in] pair1 pair 1 (a pair of floats)
68 @param[in] maxDiff maximum radial separation between the two points
69 @param[in] msg exception message prefix; details of the error are appended after ": "
71 @throw AssertionError if the radial difference is greater than maxDiff
74 raise RuntimeError(
"len(pair0)=%s != 2" % (len(pair0),))
76 raise RuntimeError(
"len(pair1)=%s != 2" % (len(pair1),))
78 pairDiff = [float(pair1[i] - pair0[i])
for i
in range(2)]
79 measDiff = math.hypot(*pairDiff)
80 if measDiff > maxDiff:
81 testCase.fail(
"%s: measured radial distance = %s > maxDiff = %s" % (msg, measDiff, maxDiff))
83 @lsst.utils.tests.inTestCase
85 """!Assert that two boxes (Box2D or Box2I) are nearly equal
87 @warning Does not compare types, just compares values.
89 @param[in] testCase unittest.TestCase instance the test is part of;
90 an object supporting one method: fail(self, msgStr)
93 @param[in] maxDiff maximum radial separation between the min points and max points
94 @param[in] msg exception message prefix; details of the error are appended after ": "
96 @throw AssertionError if the radial difference of the min points or max points is greater than maxDiff
def assertAnglesNearlyEqual
Assert that two angles are nearly equal, ignoring wrap differences by default.
def assertPairsNearlyEqual
Assert that two planar pairs (e.g.
def assertBoxesNearlyEqual
Assert that two boxes (Box2D or Box2I) are nearly equal.