LSSTApplications  11.0-13-gbb96280,12.1.rc1,12.1.rc1+1,12.1.rc1+2,12.1.rc1+5,12.1.rc1+8,12.1.rc1-1-g06d7636+1,12.1.rc1-1-g253890b+5,12.1.rc1-1-g3d31b68+7,12.1.rc1-1-g3db6b75+1,12.1.rc1-1-g5c1385a+3,12.1.rc1-1-g83b2247,12.1.rc1-1-g90cb4cf+6,12.1.rc1-1-g91da24b+3,12.1.rc1-2-g3521f8a,12.1.rc1-2-g39433dd+4,12.1.rc1-2-g486411b+2,12.1.rc1-2-g4c2be76,12.1.rc1-2-gc9c0491,12.1.rc1-2-gda2cd4f+6,12.1.rc1-3-g3391c73+2,12.1.rc1-3-g8c1bd6c+1,12.1.rc1-3-gcf4b6cb+2,12.1.rc1-4-g057223e+1,12.1.rc1-4-g19ed13b+2,12.1.rc1-4-g30492a7
LSSTDataManagementBasePackage
Classes | Functions | Variables
lsst.utils.tests Namespace Reference

Classes

class  MemoryTestCase
 Check for memory leaks since memId0 was allocated. More...
 
class  ExecutablesTestCase
 Test that executables can be run and return good status. More...
 
class  TestCase
 Subclass of unittest.TestCase that adds some custom assertions for convenience. More...
 

Functions

def _get_open_files
 
def init
 
def run
 Exit with the status code resulting from running the provided test suite. More...
 
def sort_tests
 Go through the supplied sequence of test suites and sort them to ensure that MemoryTestCases are at the end of the test list. More...
 
def suiteClassWrapper
 
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 assertFloatsAlmostEqual
 Highly-configurable floating point comparisons for scalars and arrays. More...
 
def assertFloatsNotEqual
 
def assertFloatsEqual
 
def assertClose
 
def assertNotClose
 

Variables

 psutil = None
 
 dafBase = None
 
int memId0 = 0
 
int nleakPrintMax = 20
 
tuple open_files = set()
 

Function Documentation

def lsst.utils.tests._get_open_files ( )
private
Return a set containing the list of open files.

Definition at line 61 of file tests.py.

61 
62 def _get_open_files():
63  """Return a set containing the list of open files."""
64  if psutil is None:
65  return set()
66  return set(p.path for p in psutil.Process().open_files())
67 
tuple open_files
Definition: tests.py:58
def _get_open_files
Definition: tests.py:61
def lsst.utils.tests.assertClose (   args,
  kwargs 
)

Definition at line 665 of file tests.py.

666 def assertClose(*args, **kwargs):
667  warnings.warn("assertClose is deprecated; please use TestCase.assertFloatsAlmostEqual",
668  DeprecationWarning)
669  return assertFloatsAlmostEqual(*args, **kwargs)
670 
671 
@inTestCase
def assertFloatsAlmostEqual
Highly-configurable floating point comparisons for scalars and arrays.
Definition: tests.py:543
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
[in]testCaseunittest.TestCase instance the test is part of
[in]lhsLHS value(s) to compare; may be a scalar or array-like of any dimension
[in]rhsRHS value(s) to compare; may be a scalar or array-like of any dimension
[in]rtolRelative tolerance for comparison; defaults to double-precision epsilon.
[in]atolAbsolute tolerance for comparison; defaults to double-precision epsilon.
[in]relToValue to which comparison with rtol is relative.
[in]printFailuresUpon failure, print all inequal elements as part of the message.
[in]plotOnFailureUpon failure, plot the originals and their residual with matplotlib. Only 2-d arrays are supported.
[in]plotFileNameFilename to save the plot to. If None, the plot will be displayed in a a window.
[in]invertIf True, invert the comparison and fail only if any elements are equal. Used to implement assertFloatsNotEqual, which should generally be used instead for clarity.
[in]msgString to append to the error message when assert fails.

Definition at line 543 of file tests.py.

544  plotFileName=None, invert=False, msg=None):
545  """!Highly-configurable floating point comparisons for scalars and arrays.
546 
547  The test assertion will fail if all elements lhs and rhs are not equal to within the tolerances
548  specified by rtol and atol. More precisely, the comparison is:
549 
550  abs(lhs - rhs) <= relTo*rtol OR abs(lhs - rhs) <= atol
551 
552  If rtol or atol is None, that term in the comparison is not performed at all.
553 
554  When not specified, relTo is the elementwise maximum of the absolute values of lhs and rhs. If
555  set manually, it should usually be set to either lhs or rhs, or a scalar value typical of what
556  is expected.
557 
558  @param[in] testCase unittest.TestCase instance the test is part of
559  @param[in] lhs LHS value(s) to compare; may be a scalar or array-like of any dimension
560  @param[in] rhs RHS value(s) to compare; may be a scalar or array-like of any dimension
561  @param[in] rtol Relative tolerance for comparison; defaults to double-precision epsilon.
562  @param[in] atol Absolute tolerance for comparison; defaults to double-precision epsilon.
563  @param[in] relTo Value to which comparison with rtol is relative.
564  @param[in] printFailures Upon failure, print all inequal elements as part of the message.
565  @param[in] plotOnFailure Upon failure, plot the originals and their residual with matplotlib.
566  Only 2-d arrays are supported.
567  @param[in] plotFileName Filename to save the plot to. If None, the plot will be displayed in a
568  a window.
569  @param[in] invert If True, invert the comparison and fail only if any elements *are* equal.
570  Used to implement assertFloatsNotEqual, which should generally be used instead
571  for clarity.
572  @param[in] msg String to append to the error message when assert fails.
573  """
574  if not numpy.isfinite(lhs).all():
575  testCase.fail("Non-finite values in lhs")
576  if not numpy.isfinite(rhs).all():
577  testCase.fail("Non-finite values in rhs")
578  diff = lhs - rhs
579  absDiff = numpy.abs(lhs - rhs)
580  if rtol is not None:
581  if relTo is None:
582  relTo = numpy.maximum(numpy.abs(lhs), numpy.abs(rhs))
583  else:
584  relTo = numpy.abs(relTo)
585  bad = absDiff > rtol*relTo
586  if atol is not None:
587  bad = numpy.logical_and(bad, absDiff > atol)
588  else:
589  if atol is None:
590  raise ValueError("rtol and atol cannot both be None")
591  bad = absDiff > atol
592  failed = numpy.any(bad)
593  if invert:
594  failed = not failed
595  bad = numpy.logical_not(bad)
596  cmpStr = "=="
597  failStr = "are the same"
598  else:
599  cmpStr = "!="
600  failStr = "differ"
601  errMsg = []
602  if failed:
603  if numpy.isscalar(bad):
604  if rtol is None:
605  errMsg = ["%s %s %s; diff=%s with atol=%s"
606  % (lhs, cmpStr, rhs, absDiff, atol)]
607  elif atol is None:
608  errMsg = ["%s %s %s; diff=%s/%s=%s with rtol=%s"
609  % (lhs, cmpStr, rhs, absDiff, relTo, absDiff/relTo, rtol)]
610  else:
611  errMsg = ["%s %s %s; diff=%s/%s=%s with rtol=%s, atol=%s"
612  % (lhs, cmpStr, rhs, absDiff, relTo, absDiff/relTo, rtol, atol)]
613  else:
614  errMsg = ["%d/%d elements %s with rtol=%s, atol=%s"
615  % (bad.sum(), bad.size, failStr, rtol, atol)]
616  if plotOnFailure:
617  if len(lhs.shape) != 2 or len(rhs.shape) != 2:
618  raise ValueError("plotOnFailure is only valid for 2-d arrays")
619  try:
620  plotImageDiff(lhs, rhs, bad, diff=diff, plotFileName=plotFileName)
621  except ImportError:
622  errMsg.append("Failure plot requested but matplotlib could not be imported.")
623  if printFailures:
624  # Make sure everything is an array if any of them are, so we can treat
625  # them the same (diff and absDiff are arrays if either rhs or lhs is),
626  # and we don't get here if neither is.
627  if numpy.isscalar(relTo):
628  relTo = numpy.ones(bad.shape, dtype=float) * relTo
629  if numpy.isscalar(lhs):
630  lhs = numpy.ones(bad.shape, dtype=float) * lhs
631  if numpy.isscalar(rhs):
632  rhs = numpy.ones(bad.shape, dtype=float) * rhs
633  if rtol is None:
634  for a, b, diff in zip(lhs[bad], rhs[bad], absDiff[bad]):
635  errMsg.append("%s %s %s (diff=%s)" % (a, cmpStr, b, diff))
636  else:
637  for a, b, diff, rel in zip(lhs[bad], rhs[bad], absDiff[bad], relTo[bad]):
638  errMsg.append("%s %s %s (diff=%s/%s=%s)" % (a, cmpStr, b, diff, rel, diff/rel))
639 
640  if msg is not None:
641  errMsg.append(msg)
642  testCase.assertFalse(failed, msg="\n".join(errMsg))
643 
644 
@inTestCase
bool all(CoordinateExpr< N > const &expr)
Return true if all elements are true.
def plotImageDiff
Plot the comparison of two 2-d NumPy arrays.
Definition: tests.py:484
def lsst.utils.tests.assertFloatsEqual (   testCase,
  lhs,
  rhs,
  kwargs 
)
Assert that lhs == rhs (both numeric types, whether scalar or array).

See assertClose (called with rtol=atol=0) for more information.

Definition at line 655 of file tests.py.

656 def assertFloatsEqual(testCase, lhs, rhs, **kwargs):
657  """
658  Assert that lhs == rhs (both numeric types, whether scalar or array).
659 
660  See assertClose (called with rtol=atol=0) for more information.
661  """
662  return assertFloatsAlmostEqual(testCase, lhs, rhs, rtol=0, atol=0, **kwargs)
663 
664 
@inTestCase
def assertFloatsAlmostEqual
Highly-configurable floating point comparisons for scalars and arrays.
Definition: tests.py:543
def assertFloatsEqual
Definition: tests.py:655
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 assertClose for more information.

Definition at line 645 of file tests.py.

646 def assertFloatsNotEqual(testCase, lhs, rhs, **kwds):
647  """
648  Fail a test if the given floating point values are equal to within the given tolerances.
649 
650  See assertClose for more information.
651  """
652  return assertFloatsAlmostEqual(testCase, lhs, rhs, invert=True, **kwds)
653 
654 
@inTestCase
def assertFloatsNotEqual
Definition: tests.py:645
def assertFloatsAlmostEqual
Highly-configurable floating point comparisons for scalars and arrays.
Definition: tests.py:543
def lsst.utils.tests.assertNotClose (   args,
  kwargs 
)

Definition at line 672 of file tests.py.

673 def assertNotClose(*args, **kwargs):
674  warnings.warn("assertNotClose is deprecated; please use TestCase.assertFloatsNotEqual",
675  DeprecationWarning)
676  return assertFloatsNotEqual(*args, **kwargs)
def assertFloatsNotEqual
Definition: tests.py:645
def assertNotClose
Definition: tests.py:672
def lsst.utils.tests.assertRaisesLsstCpp (   testcase,
  excClass,
  callableObj,
  args,
  kwargs 
)

Definition at line 444 of file tests.py.

445 def assertRaisesLsstCpp(testcase, excClass, callableObj, *args, **kwargs):
446  warnings.warn("assertRaisesLsstCpp is deprecated; please just use TestCase.assertRaises",
447  DeprecationWarning)
448  return testcase.assertRaises(excClass, callableObj, *args, **kwargs)
449 
450 # -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
def assertRaisesLsstCpp
Definition: tests.py:444
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 454 of file tests.py.

455 def debugger(*exceptions):
456  """!Decorator to enter the debugger when there's an uncaught exception
457 
458  To use, just slap a "@debugger()" on your function.
459 
460  You may provide specific exception classes to catch as arguments to
461  the decorator function, e.g., "@debugger(RuntimeError, NotImplementedError)".
462  This defaults to just 'AssertionError', for use on unittest.TestCase methods.
463 
464  Code provided by "Rosh Oxymoron" on StackOverflow:
465  http://stackoverflow.com/questions/4398967/python-unit-testing-automatically-running-the-debugger-when-a-test-fails
466  """
467  if not exceptions:
468  exceptions = (AssertionError, )
469 
470  def decorator(f):
471  @functools.wraps(f)
472  def wrapper(*args, **kwargs):
473  try:
474  return f(*args, **kwargs)
475  except exceptions:
476  import sys
477  import pdb
478  pdb.post_mortem(sys.exc_info()[2])
479  return wrapper
480  return decorator
481 
482 # -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
483 
def debugger
Decorator to enter the debugger when there&#39;s an uncaught exception.
Definition: tests.py:454
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 338 of file tests.py.

339 def findFileFromRoot(ifile):
340  """!Find file which is specified as a path relative to the toplevel directory;
341  we start in $cwd and walk up until we find the file (or throw IOError if it doesn't exist)
342 
343  This is useful for running tests that may be run from _dir_/tests or _dir_"""
344 
345  if os.path.isfile(ifile):
346  return ifile
347 
348  ofile = None
349  file = ifile
350  while file != "":
351  dirname, basename = os.path.split(file)
352  if ofile:
353  ofile = os.path.join(basename, ofile)
354  else:
355  ofile = basename
356 
357  if os.path.isfile(ofile):
358  return ofile
359 
360  file = dirname
361 
362  raise IOError("Can't find %s" % ifile)
363 
364 # -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
365 
366 
@contextmanager
def findFileFromRoot
Find file which is specified as a path relative to the toplevel directory; we start in $cwd and walk ...
Definition: tests.py:338
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.

Parameters
[in]extfile name extension, e.g. ".fits"
Returns
path for a temporary file. The path is a combination of the caller's file path and the name of the top-level function, as per this simple example:
1 # file tests/testFoo.py
2 import unittest
3 import lsst.utils.tests
4 class FooTestCase(unittest.TestCase):
5  def testBasics(self):
6  self.runTest()
7 
8  def runTest(self):
9  with lsst.utils.tests.getTempFilePath(".fits") as tmpFile:
10  # if tests/.tests exists then tmpFile = "tests/.tests/testFoo_testBasics.fits"
11  # otherwise tmpFile = "testFoo_testBasics.fits"
12  ...
13  # at the end of this "with" block the path tmpFile will be deleted, but only if
14  # the file exists and the "with" block terminated normally (rather than with an exception)
15 ...

Definition at line 367 of file tests.py.

368 def getTempFilePath(ext):
369  """!Return a path suitable for a temporary file and try to delete the file on success
370 
371  If the with block completes successfully then the file is deleted, if possible;
372  failure results in a printed warning.
373  If the block exits with an exception the file if left on disk so it can be examined.
374 
375  @param[in] ext file name extension, e.g. ".fits"
376  @return path for a temporary file. The path is a combination of the caller's file path
377  and the name of the top-level function, as per this simple example:
378  @code
379  # file tests/testFoo.py
380  import unittest
381  import lsst.utils.tests
382  class FooTestCase(unittest.TestCase):
383  def testBasics(self):
384  self.runTest()
385 
386  def runTest(self):
387  with lsst.utils.tests.getTempFilePath(".fits") as tmpFile:
388  # if tests/.tests exists then tmpFile = "tests/.tests/testFoo_testBasics.fits"
389  # otherwise tmpFile = "testFoo_testBasics.fits"
390  ...
391  # at the end of this "with" block the path tmpFile will be deleted, but only if
392  # the file exists and the "with" block terminated normally (rather than with an exception)
393  ...
394  @endcode
395  """
396  stack = inspect.stack()
397  # get name of first function in the file
398  for i in range(2, len(stack)):
399  frameInfo = inspect.getframeinfo(stack[i][0])
400  if i == 2:
401  callerFilePath = frameInfo.filename
402  callerFuncName = frameInfo.function
403  elif callerFilePath == frameInfo.filename:
404  # this function called the previous function
405  callerFuncName = frameInfo.function
406  else:
407  break
408 
409  callerDir, callerFileNameWithExt = os.path.split(callerFilePath)
410  callerFileName = os.path.splitext(callerFileNameWithExt)[0]
411  outDir = os.path.join(callerDir, ".tests")
412  if not os.path.isdir(outDir):
413  outDir = ""
414  outName = "%s_%s%s" % (callerFileName, callerFuncName, ext)
415  outPath = os.path.join(outDir, outName)
416  yield outPath
417  if os.path.isfile(outPath):
418  try:
419  os.remove(outPath)
420  except OSError as e:
421  print("Warning: could not remove file %r: %s" % (outPath, e))
422  else:
423  print("Warning: could not find file %r" % (outPath,))
424 
425 # -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
426 
def getTempFilePath
Return a path suitable for a temporary file and try to delete the file on success.
Definition: tests.py:367
def lsst.utils.tests.init ( )
Initialize the memory tester and configure a default log.

Definition at line 68 of file tests.py.

68 
69 def init():
70  """Initialize the memory tester and configure a default log."""
71  global memId0
72  global open_files
73  if dafBase:
74  memId0 = dafBase.Citizen_getNextMemId() # used by MemoryTestCase
75  # Reset the list of open files
76  open_files = _get_open_files()
77  # Setup a default configuration for log used in the test framework
78  lsst.log.configure_prop("""
79 log4j.rootLogger=INFO, A1
80 log4j.appender.A1=ConsoleAppender
81 log4j.appender.A1.Target=System.err
82 log4j.appender.A1.layout=PatternLayout
83 log4j.appender.A1.layout.ConversionPattern=%-5p %c: %m%n
84 """)
85 
def _get_open_files
Definition: tests.py:61
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 433 of file tests.py.

434 def inTestCase(func):
435  """!A decorator to add a free function to our custom TestCase class, while also
436  making it available as a free function.
437  """
438  setattr(TestCase, func.__name__, func)
439  return func
440 
441 # -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
442 
443 
@inTestCase
def inTestCase
A decorator to add a free function to our custom TestCase class, while also making it available as a ...
Definition: tests.py:433
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
[in]lhsLHS values to compare; a 2-d NumPy array
[in]rhsRHS values to compare; a 2-d NumPy array
[in]badA 2-d boolean NumPy array of values to emphasize in the plots
[in]diffdifference array; a 2-d NumPy array, or None to show lhs-rhs
[in]plotFileNameFilename to save the plot to. If None, the plot will be displayed in a a window.

Definition at line 484 of file tests.py.

485 def plotImageDiff(lhs, rhs, bad=None, diff=None, plotFileName=None):
486  """!Plot the comparison of two 2-d NumPy arrays.
487 
488  NOTE: this method uses matplotlib and imports it internally; it should be
489  wrapped in a try/except block within packages that do not depend on
490  matplotlib (including utils).
491 
492  @param[in] lhs LHS values to compare; a 2-d NumPy array
493  @param[in] rhs RHS values to compare; a 2-d NumPy array
494  @param[in] bad A 2-d boolean NumPy array of values to emphasize in the plots
495  @param[in] diff difference array; a 2-d NumPy array, or None to show lhs-rhs
496  @param[in] plotFileName Filename to save the plot to. If None, the plot will be displayed in a
497  a window.
498  """
499  from matplotlib import pyplot
500  if diff is None:
501  diff = lhs - rhs
502  pyplot.figure()
503  if bad is not None:
504  # make an rgba image that's red and transparent where not bad
505  badImage = numpy.zeros(bad.shape + (4,), dtype=numpy.uint8)
506  badImage[:, :, 0] = 255
507  badImage[:, :, 1] = 0
508  badImage[:, :, 2] = 0
509  badImage[:, :, 3] = 255*bad
510  vmin1 = numpy.minimum(numpy.min(lhs), numpy.min(rhs))
511  vmax1 = numpy.maximum(numpy.max(lhs), numpy.max(rhs))
512  vmin2 = numpy.min(diff)
513  vmax2 = numpy.max(diff)
514  for n, (image, title) in enumerate([(lhs, "lhs"), (rhs, "rhs"), (diff, "diff")]):
515  pyplot.subplot(2, 3, n + 1)
516  im1 = pyplot.imshow(image, cmap=pyplot.cm.gray, interpolation='nearest', origin='lower',
517  vmin=vmin1, vmax=vmax1)
518  if bad is not None:
519  pyplot.imshow(badImage, alpha=0.2, interpolation='nearest', origin='lower')
520  pyplot.axis("off")
521  pyplot.title(title)
522  pyplot.subplot(2, 3, n + 4)
523  im2 = pyplot.imshow(image, cmap=pyplot.cm.gray, interpolation='nearest', origin='lower',
524  vmin=vmin2, vmax=vmax2)
525  if bad is not None:
526  pyplot.imshow(badImage, alpha=0.2, interpolation='nearest', origin='lower')
527  pyplot.axis("off")
528  pyplot.title(title)
529  pyplot.subplots_adjust(left=0.05, bottom=0.05, top=0.92, right=0.75, wspace=0.05, hspace=0.05)
530  cax1 = pyplot.axes([0.8, 0.55, 0.05, 0.4])
531  pyplot.colorbar(im1, cax=cax1)
532  cax2 = pyplot.axes([0.8, 0.05, 0.05, 0.4])
533  pyplot.colorbar(im2, cax=cax2)
534  if plotFileName:
535  pyplot.savefig(plotFileName)
536  else:
537  pyplot.show()
538 
539 
@inTestCase
def plotImageDiff
Plot the comparison of two 2-d NumPy arrays.
Definition: tests.py:484
def lsst.utils.tests.run (   suite,
  exit = True 
)

Exit with the status code resulting from running the provided test suite.

Definition at line 86 of file tests.py.

86 
87 def run(suite, exit=True):
88  """!Exit with the status code resulting from running the provided test suite"""
89 
90  if unittest.TextTestRunner().run(suite).wasSuccessful():
91  status = 0
92  else:
93  status = 1
94 
95  if exit:
96  sys.exit(status)
97  else:
98  return status
99 
def run
Exit with the status code resulting from running the provided test suite.
Definition: tests.py:86
def lsst.utils.tests.sort_tests (   tests)

Go through the supplied sequence of test suites and sort them to ensure that MemoryTestCases are at the end of the test list.

Returns a combined TestSuite.

Definition at line 100 of file tests.py.

101 def sort_tests(tests):
102  """!Go through the supplied sequence of test suites and sort them to ensure that
103  MemoryTestCases are at the end of the test list. Returns a combined
104  TestSuite."""
105 
106  suite = unittest.TestSuite()
107  memtests = []
108  for test_suite in tests:
109  try:
110  # Just test the first test method in the suite for MemoryTestCase
111  # Use loop rather than next as it is possible for a test class
112  # to not have any test methods and the Python community prefers
113  # for loops over catching a StopIteration exception.
114  bases = None
115  for method in test_suite:
116  bases = inspect.getmro(method.__class__)
117  break
118  if bases is not None and MemoryTestCase in bases:
119  memtests.append(test_suite)
120  else:
121  suite.addTests(test_suite)
122  except TypeError:
123  if isinstance(test_suite, MemoryTestCase):
124  memtests.append(test_suite)
125  else:
126  suite.addTest(test_suite)
127  suite.addTests(memtests)
128  return suite
129 
def sort_tests
Go through the supplied sequence of test suites and sort them to ensure that MemoryTestCases are at t...
Definition: tests.py:100
def lsst.utils.tests.suiteClassWrapper (   tests)

Definition at line 130 of file tests.py.

131 def suiteClassWrapper(tests):
132  return unittest.TestSuite(sort_tests(tests))
133 
134 # Replace the suiteClass callable in the defaultTestLoader
135 # so that we can reorder the test ordering. This will have
136 # no effect if no memory test cases are found.
137 unittest.defaultTestLoader.suiteClass = suiteClassWrapper
138 
139 # -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
140 
def sort_tests
Go through the supplied sequence of test suites and sort them to ensure that MemoryTestCases are at t...
Definition: tests.py:100
def suiteClassWrapper
Definition: tests.py:130

Variable Documentation

lsst.utils.tests.dafBase = None

Definition at line 49 of file tests.py.

int lsst.utils.tests.memId0 = 0

Definition at line 54 of file tests.py.

int lsst.utils.tests.nleakPrintMax = 20

Definition at line 55 of file tests.py.

tuple lsst.utils.tests.open_files = set()

Definition at line 58 of file tests.py.

lsst.utils.tests.psutil = None

Definition at line 44 of file tests.py.