LSSTApplications
19.0.0-14-gb0260a2+72efe9b372,20.0.0+7927753e06,20.0.0+8829bf0056,20.0.0+995114c5d2,20.0.0+b6f4b2abd1,20.0.0+bddc4f4cbe,20.0.0-1-g253301a+8829bf0056,20.0.0-1-g2b7511a+0d71a2d77f,20.0.0-1-g5b95a8c+7461dd0434,20.0.0-12-g321c96ea+23efe4bbff,20.0.0-16-gfab17e72e+fdf35455f6,20.0.0-2-g0070d88+ba3ffc8f0b,20.0.0-2-g4dae9ad+ee58a624b3,20.0.0-2-g61b8584+5d3db074ba,20.0.0-2-gb780d76+d529cf1a41,20.0.0-2-ged6426c+226a441f5f,20.0.0-2-gf072044+8829bf0056,20.0.0-2-gf1f7952+ee58a624b3,20.0.0-20-geae50cf+e37fec0aee,20.0.0-25-g3dcad98+544a109665,20.0.0-25-g5eafb0f+ee58a624b3,20.0.0-27-g64178ef+f1f297b00a,20.0.0-3-g4cc78c6+e0676b0dc8,20.0.0-3-g8f21e14+4fd2c12c9a,20.0.0-3-gbd60e8c+187b78b4b8,20.0.0-3-gbecbe05+48431fa087,20.0.0-38-ge4adf513+a12e1f8e37,20.0.0-4-g97dc21a+544a109665,20.0.0-4-gb4befbc+087873070b,20.0.0-4-gf910f65+5d3db074ba,20.0.0-5-gdfe0fee+199202a608,20.0.0-5-gfbfe500+d529cf1a41,20.0.0-6-g64f541c+d529cf1a41,20.0.0-6-g9a5b7a1+a1cd37312e,20.0.0-68-ga3f3dda+5fca18c6a4,20.0.0-9-g4aef684+e18322736b,w.2020.45
LSSTDataManagementBasePackage
|
Classes | |
class | ExecutablesTestCase |
class | MemoryTestCase |
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 | |
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 | ( | ) |