LSST Applications
21.0.0-142-gef555c1e+42c9bccae2,22.0.0+052faf71bd,22.0.0+1c4650f311,22.0.0+40ce427c77,22.0.0+5b6c068b1a,22.0.0+7589c3a021,22.0.0+81ed51be6d,22.0.1-1-g7d6de66+6cae67f2c6,22.0.1-1-g87000a6+314cd8b7ea,22.0.1-1-g8760c09+052faf71bd,22.0.1-1-g8e32f31+5b6c068b1a,22.0.1-10-g779eefa+a163f08322,22.0.1-12-g3bd7ecb+bbeacc25a9,22.0.1-15-g63cc0c1+2a7037787d,22.0.1-17-ge5a99e88+3d2c1afe2e,22.0.1-19-g88addfe+6cae67f2c6,22.0.1-2-g1cb3e5b+84de06d286,22.0.1-2-g8ef0a89+6cae67f2c6,22.0.1-2-g92698f7+1c4650f311,22.0.1-2-ga9b0f51+052faf71bd,22.0.1-2-gb66926d+5b6c068b1a,22.0.1-2-gcb770ba+0723a13595,22.0.1-2-ge470956+ff9f1dc8d5,22.0.1-22-g608e23ac+2ac85e833c,22.0.1-29-g184b6e44e+8b185d4e2d,22.0.1-3-g59f966b+11ba4df19d,22.0.1-3-g8c1d971+f90df4c6d0,22.0.1-3-g997b569+d69a7aa2f8,22.0.1-3-gaaec9c0+4d194bf81c,22.0.1-4-g1930a60+283d9d2f1a,22.0.1-4-g5b7b756+c1283a92b8,22.0.1-4-g8623105+6cae67f2c6,22.0.1-7-gba73697+283d9d2f1a,22.0.1-8-g47d23f5+43acea82f3,master-g5f2689bdc5+40ce427c77,w.2021.38
LSST Data Management Base Package
|
Classes | |
class | MemoryTestCase |
class | ExecutablesTestCase |
class | TestCase |
Functions | |
def | init () |
def | sort_tests (tests) |
def | suiteClassWrapper (tests) |
def | getTempFilePath (ext, expectOutput=True) |
def | inTestCase (func) |
def | debugger (*exceptions) |
def | plotImageDiff (lhs, rhs, bad=None, diff=None, plotFileName=None) |
def | assertFloatsAlmostEqual (testCase, lhs, rhs, rtol=sys.float_info.epsilon, atol=sys.float_info.epsilon, relTo=None, printFailures=True, plotOnFailure=False, plotFileName=None, invert=False, msg=None, ignoreNaNs=False) |
def | assertFloatsNotEqual (testCase, lhs, rhs, **kwds) |
def | assertFloatsEqual (testCase, lhs, rhs, **kwargs) |
def | classParameters (**settings) |
def | methodParameters (**settings) |
def | classParametersProduct (**settings) |
def | methodParametersProduct (**settings) |
def | temporaryDirectory () |
Variables | |
open_files = set() | |
def lsst.utils.tests.assertFloatsAlmostEqual | ( | testCase, | |
lhs, | |||
rhs, | |||
rtol = sys.float_info.epsilon , |
|||
atol = sys.float_info.epsilon , |
|||
relTo = None , |
|||
printFailures = True , |
|||
plotOnFailure = False , |
|||
plotFileName = None , |
|||
invert = False , |
|||
msg = None , |
|||
ignoreNaNs = False |
|||
) |
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 `~lsst.utils.tests.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. Raises ------ AssertionError The values are not almost equal.
Definition at line 523 of file tests.py.
def lsst.utils.tests.assertFloatsEqual | ( | testCase, | |
lhs, | |||
rhs, | |||
** | kwargs | ||
) |
Assert that lhs == rhs (both numeric types, whether scalar or array). See `~lsst.utils.tests.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.
Definition at line 708 of file tests.py.
def lsst.utils.tests.assertFloatsNotEqual | ( | testCase, | |
lhs, | |||
rhs, | |||
** | kwds | ||
) |
Fail a test if the given floating point values are equal to within the given tolerances. See `~lsst.utils.tests.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.
Definition at line 681 of file tests.py.
def lsst.utils.tests.classParameters | ( | ** | settings | ) |
Class decorator for generating unit tests This decorator generates classes with class variables according to the supplied ``settings``. Parameters ---------- **settings : `dict` (`str`: iterable) The lists of test parameters to set as class variables in turn. Each should be an iterable of the same length. Examples -------- :: @classParameters(foo=[1, 2], bar=[3, 4]) class MyTestCase(unittest.TestCase): ... will generate two classes, as if you wrote:: class MyTestCase_1_3(unittest.TestCase): foo = 1 bar = 3 ... class MyTestCase_2_4(unittest.TestCase): foo = 2 bar = 4 ... Note that the values are embedded in the class name.
Definition at line 766 of file tests.py.
def lsst.utils.tests.classParametersProduct | ( | ** | settings | ) |
Class decorator for generating unit tests This decorator generates classes with class variables according to the cartesian product of the supplied ``settings``. Parameters ---------- **settings : `dict` (`str`: iterable) The lists of test parameters to set as class variables in turn. Each should be an iterable. Examples -------- :: @classParametersProduct(foo=[1, 2], bar=[3, 4]) class MyTestCase(unittest.TestCase): ... will generate four classes, as if you wrote:: class MyTestCase_1_3(unittest.TestCase): foo = 1 bar = 3 ... class MyTestCase_1_4(unittest.TestCase): foo = 1 bar = 4 ... class MyTestCase_2_3(unittest.TestCase): foo = 2 bar = 3 ... class MyTestCase_2_4(unittest.TestCase): foo = 2 bar = 4 ... Note that the values are embedded in the class name.
Definition at line 876 of file tests.py.
def lsst.utils.tests.debugger | ( | * | exceptions | ) |
Decorator to enter the debugger when there's an uncaught exception To use, just slap a ``@debugger()`` on your function. You may provide specific exception classes to catch as arguments to the decorator function, e.g., ``@debugger(RuntimeError, NotImplementedError)``. This defaults to just `AssertionError`, for use on `unittest.TestCase` methods. Code provided by "Rosh Oxymoron" on StackOverflow: http://stackoverflow.com/questions/4398967/python-unit-testing-automatically-running-the-debugger-when-a-test-fails Notes ----- Consider using ``pytest --pdb`` instead of this decorator.
def lsst.utils.tests.getTempFilePath | ( | ext, | |
expectOutput = True |
|||
) |
Return a path suitable for a temporary file and try to delete the file on success If the with block completes successfully then the file is deleted, if possible; failure results in a printed warning. If a file is remains when it should not, a RuntimeError exception is raised. This exception is also raised if a file is not present on context manager exit when one is expected to exist. If the block exits with an exception the file if left on disk so it can be examined. The file name has a random component such that nested context managers can be used with the same file suffix. Parameters ---------- ext : `str` File name extension, e.g. ``.fits``. expectOutput : `bool`, optional If `True`, a file should be created within the context manager. If `False`, a file should not be present when the context manager exits. Returns ------- `str` Path for a temporary file. The path is a combination of the caller's file path and the name of the top-level function Notes ----- :: # file tests/testFoo.py import unittest import lsst.utils.tests class FooTestCase(unittest.TestCase): def testBasics(self): self.runTest() def runTest(self): with lsst.utils.tests.getTempFilePath(".fits") as tmpFile: # if tests/.tests exists then # tmpFile = "tests/.tests/testFoo_testBasics.fits" # otherwise tmpFile = "testFoo_testBasics.fits" ... # at the end of this "with" block the path tmpFile will be # deleted, but only if the file exists and the "with" # block terminated normally (rather than with an exception) ...
Definition at line 311 of file tests.py.
def lsst.utils.tests.init | ( | ) |
def lsst.utils.tests.inTestCase | ( | func | ) |
def lsst.utils.tests.methodParameters | ( | ** | settings | ) |
Method decorator for unit tests This decorator iterates over the supplied settings, using ``TestCase.subTest`` to communicate the values in the event of a failure. Parameters ---------- **settings : `dict` (`str`: iterable) The lists of test parameters. Each should be an iterable of the same length. Examples -------- :: @methodParameters(foo=[1, 2], bar=[3, 4]) def testSomething(self, foo, bar): ... will run:: testSomething(foo=1, bar=3) testSomething(foo=2, bar=4)
Definition at line 810 of file tests.py.
def lsst.utils.tests.methodParametersProduct | ( | ** | settings | ) |
Method decorator for unit tests This decorator iterates over the cartesian product of the supplied settings, using ``TestCase.subTest`` to communicate the values in the event of a failure. Parameters ---------- **settings : `dict` (`str`: iterable) The parameter combinations to test. Each should be an iterable. Example ------- @methodParametersProduct(foo=[1, 2], bar=["black", "white"]) def testSomething(self, foo, bar): ... will run: testSomething(foo=1, bar="black") testSomething(foo=1, bar="white") testSomething(foo=2, bar="black") testSomething(foo=2, bar="white")
Definition at line 923 of file tests.py.
def lsst.utils.tests.plotImageDiff | ( | lhs, | |
rhs, | |||
bad = None , |
|||
diff = None , |
|||
plotFileName = None |
|||
) |
Plot the comparison of two 2-d NumPy arrays. Parameters ---------- lhs : `numpy.ndarray` LHS values to compare; a 2-d NumPy array rhs : `numpy.ndarray` RHS values to compare; a 2-d NumPy array bad : `numpy.ndarray` A 2-d boolean NumPy array of values to emphasize in the plots diff : `numpy.ndarray` difference array; a 2-d NumPy array, or None to show lhs-rhs plotFileName : `str` Filename to save the plot to. If None, the plot will be displayed in a window. Notes ----- This method uses `matplotlib` and imports it internally; it should be wrapped in a try/except block within packages that do not depend on `matplotlib` (including `~lsst.utils`).
Definition at line 458 of file tests.py.
def lsst.utils.tests.sort_tests | ( | tests | ) |
Sort supplied test suites such that MemoryTestCases are at the end. `lsst.utils.tests.MemoryTestCase` tests should always run after any other tests in the module. Parameters ---------- tests : sequence Sequence of test suites. Returns ------- suite : `unittest.TestSuite` A combined `~unittest.TestSuite` with `~lsst.utils.tests.MemoryTestCase` at the end.
Definition at line 67 of file tests.py.
def lsst.utils.tests.temporaryDirectory | ( | ) |