LSSTApplications
10.0-2-g4f67435,11.0.rc2+1,11.0.rc2+12,11.0.rc2+3,11.0.rc2+4,11.0.rc2+5,11.0.rc2+6,11.0.rc2+7,11.0.rc2+8
LSSTDataManagementBasePackage
|
Classes | |
class | MemoryTestCase |
Check for memory leaks since memId0 was allocated. More... | |
class | TestCase |
Subclass of unittest.TestCase that adds some custom assertions for convenience. More... | |
Functions | |
def | init |
def | run |
Exit with the status code resulting from running the provided test suite. More... | |
def | findFileFromRoot |
Find file which is specified as a path relative to the toplevel directory; we start in $cwd and walk up until we find the file (or throw IOError if it doesn't exist) More... | |
def | getTempFilePath |
Return a path suitable for a temporary file and try to delete the file on success. More... | |
def | inTestCase |
A decorator to add a free function to our custom TestCase class, while also making it available as a free function. More... | |
def | assertRaisesLsstCpp |
def | debugger |
Decorator to enter the debugger when there's an uncaught exception. More... | |
def | plotImageDiff |
Plot the comparison of two 2-d NumPy arrays. More... | |
def | assertClose |
Highly-configurable floating point comparisons for scalars and arrays. More... | |
def | assertNotClose |
Fail a test if the given floating point values are completely equal to within the given tolerances. More... | |
Variables | |
dafBase = None | |
int | memId0 = 0 |
int | nleakPrintMax = 20 |
def lsst.utils.tests.assertClose | ( | testCase, | |
lhs, | |||
rhs, | |||
rtol = sys.float_info.epsilon , |
|||
atol = sys.float_info.epsilon , |
|||
relTo = None , |
|||
printFailures = True , |
|||
plotOnFailure = False , |
|||
plotFileName = None , |
|||
invert = 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.
[in] | testCase | unittest.TestCase instance the test is part of |
[in] | lhs | LHS value(s) to compare; may be a scalar or a numpy array of any dimension |
[in] | rhs | RHS value(s) to compare; may be a scalar or a numpy array of any dimension |
[in] | rtol | Relative tolerance for comparison; defaults to double-precision epsilon. |
[in] | atol | Absolute tolerance for comparison; defaults to double-precision epsilon. |
[in] | relTo | Value to which comparison with rtol is relative. |
[in] | printFailures | Upon failure, print all inequal elements as part of the message. |
[in] | plotOnFailure | Upon failure, plot the originals and their residual with matplotlib. Only 2-d arrays are supported. |
[in] | plotFileName | Filename to save the plot to. If None, the plot will be displayed in a a window. |
[in] | invert | If True, invert the comparison and fail only if any elements are equal. Used to implement assertNotClose, which should generally be used instead for clarity. |
Definition at line 285 of file tests.py.
def lsst.utils.tests.assertNotClose | ( | testCase, | |
lhs, | |||
rhs, | |||
kwds | |||
) |
Fail a test if the given floating point values are completely equal to within the given tolerances.
See assertClose for more information.
Definition at line 371 of file tests.py.
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
Definition at line 202 of file tests.py.
def lsst.utils.tests.findFileFromRoot | ( | ifile | ) |
Find file which is specified as a path relative to the toplevel directory; we start in $cwd and walk up until we find the file (or throw IOError if it doesn't exist)
This is useful for running tests that may be run from dir/tests or dir
Definition at line 92 of file tests.py.
def lsst.utils.tests.getTempFilePath | ( | ext | ) |
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 the block exits with an exception the file if left on disk so it can be examined.
[in] | ext | file name extension, e.g. ".fits" |
Definition at line 120 of file tests.py.
def lsst.utils.tests.inTestCase | ( | func | ) |
A decorator to add a free function to our custom TestCase class, while also making it available as a free function.
Definition at line 184 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.
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).
[in] | lhs | LHS values to compare; a 2-d NumPy array |
[in] | rhs | RHS values to compare; a 2-d NumPy array |
[in] | bad | A 2-d boolean NumPy array of values to emphasize in the plots |
[in] | diff | difference array; a 2-d NumPy array, or None to show lhs-rhs |
[in] | plotFileName | Filename to save the plot to. If None, the plot will be displayed in a a window. |
Definition at line 229 of file tests.py.
def lsst.utils.tests.run | ( | suite, | |
exit = True |
|||
) |
Exit with the status code resulting from running the provided test suite.
Definition at line 51 of file tests.py.