lsst.utils
15.0-3-g9103c06+11
|
Classes | |
class | ExecutablesTestCase |
class | MemoryTestCase |
class | TestCase |
Functions | |
def | init () |
def | run (suite, exit=True) |
def | sort_tests (tests) |
def | suiteClassWrapper (tests) |
def | findFileFromRoot (ifile) |
def | getTempFilePath (ext, expectOutput=True) |
def | inTestCase (func) |
def | assertRaisesLsstCpp (testcase, excClass, callableObj, args, kwargs) |
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 | assertClose (args, kwargs) |
def | assertNotClose (args, kwargs) |
Variables | |
psutil = None | |
dafBase = None | |
int | memId0 = 0 |
int | nleakPrintMax = 20 |
open_files = set() | |
def lsst.utils.tests.assertClose | ( | args, | |
kwargs | |||
) |
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` or None Relative tolerance for comparison; defaults to double-precision epsilon. atol : `float` or None Absolute tolerance for comparison; defaults to double-precision epsilon. relTo : `float` Value to which comparison with rtol is relative. printFailures : `bool` Upon failure, print all inequal elements as part of the message. plotOnFailure : `bool` Upon failure, plot the originals and their residual with matplotlib. Only 2-d arrays are supported. plotFileName : `str` Filename to save the plot to. If None, the plot will be displayed in a window. invert : `bool` 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. msg : `str` String to append to the error message when assert fails.
def lsst.utils.tests.assertFloatsEqual | ( | testCase, | |
lhs, | |||
rhs, | |||
kwargs | |||
) |
def lsst.utils.tests.assertFloatsNotEqual | ( | testCase, | |
lhs, | |||
rhs, | |||
kwds | |||
) |
def lsst.utils.tests.assertNotClose | ( | args, | |
kwargs | |||
) |
def lsst.utils.tests.assertRaisesLsstCpp | ( | testcase, | |
excClass, | |||
callableObj, | |||
args, | |||
kwargs | |||
) |
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
def lsst.utils.tests.findFileFromRoot | ( | ifile | ) |
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` 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) ...
def lsst.utils.tests.inTestCase | ( | func | ) |
def lsst.utils.tests.plotImageDiff | ( | lhs, | |
rhs, | |||
bad = None , |
|||
diff = None , |
|||
plotFileName = None |
|||
) |
Plot the comparison of two 2-d NumPy arrays. NOTE: 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 utils). 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.
def lsst.utils.tests.run | ( | suite, | |
exit = True |
|||
) |
def lsst.utils.tests.sort_tests | ( | tests | ) |