LSST Applications
21.0.0+04719a4bac,21.0.0-1-ga51b5d4+f5e6047307,21.0.0-11-g2b59f77+a9c1acf22d,21.0.0-11-ga42c5b2+86977b0b17,21.0.0-12-gf4ce030+76814010d2,21.0.0-13-g1721dae+760e7a6536,21.0.0-13-g3a573fe+768d78a30a,21.0.0-15-g5a7caf0+f21cbc5713,21.0.0-16-g0fb55c1+b60e2d390c,21.0.0-19-g4cded4ca+71a93a33c0,21.0.0-2-g103fe59+bb20972958,21.0.0-2-g45278ab+04719a4bac,21.0.0-2-g5242d73+3ad5d60fb1,21.0.0-2-g7f82c8f+8babb168e8,21.0.0-2-g8f08a60+06509c8b61,21.0.0-2-g8faa9b5+616205b9df,21.0.0-2-ga326454+8babb168e8,21.0.0-2-gde069b7+5e4aea9c2f,21.0.0-2-gecfae73+1d3a86e577,21.0.0-2-gfc62afb+3ad5d60fb1,21.0.0-25-g1d57be3cd+e73869a214,21.0.0-3-g357aad2+ed88757d29,21.0.0-3-g4a4ce7f+3ad5d60fb1,21.0.0-3-g4be5c26+3ad5d60fb1,21.0.0-3-g65f322c+e0b24896a3,21.0.0-3-g7d9da8d+616205b9df,21.0.0-3-ge02ed75+a9c1acf22d,21.0.0-4-g591bb35+a9c1acf22d,21.0.0-4-g65b4814+b60e2d390c,21.0.0-4-gccdca77+0de219a2bc,21.0.0-4-ge8a399c+6c55c39e83,21.0.0-5-gd00fb1e+05fce91b99,21.0.0-6-gc675373+3ad5d60fb1,21.0.0-64-g1122c245+4fb2b8f86e,21.0.0-7-g04766d7+cd19d05db2,21.0.0-7-gdf92d54+04719a4bac,21.0.0-8-g5674e7b+d1bd76f71f,master-gac4afde19b+a9c1acf22d,w.2021.13
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) |
def | assertFloatsNotEqual (testCase, lhs, rhs, **kwds) |
def | assertFloatsEqual (testCase, lhs, rhs, **kwargs) |
def | classParameters (**settings) |
def | methodParameters (**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 |
|||
) |
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. msg : `str`, optional String to append to the error message when assert fails. Raises ------ AssertionError The values are not almost equal.
Definition at line 522 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 679 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 652 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 737 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 310 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 781 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 457 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 66 of file tests.py.
def lsst.utils.tests.temporaryDirectory | ( | ) |