LSSTApplications  1.1.2+25,10.0+13,10.0+132,10.0+133,10.0+224,10.0+41,10.0+8,10.0-1-g0f53050+14,10.0-1-g4b7b172+19,10.0-1-g61a5bae+98,10.0-1-g7408a83+3,10.0-1-gc1e0f5a+19,10.0-1-gdb4482e+14,10.0-11-g3947115+2,10.0-12-g8719d8b+2,10.0-15-ga3f480f+1,10.0-2-g4f67435,10.0-2-gcb4bc6c+26,10.0-28-gf7f57a9+1,10.0-3-g1bbe32c+14,10.0-3-g5b46d21,10.0-4-g027f45f+5,10.0-4-g86f66b5+2,10.0-4-gc4fccf3+24,10.0-40-g4349866+2,10.0-5-g766159b,10.0-5-gca2295e+25,10.0-6-g462a451+1
LSSTDataManagementBasePackage
Public Member Functions | Public Attributes | Private Attributes | Static Private Attributes | List of all members
lsst.sconsUtils.tests.Control Class Reference

A class to control unit tests. More...

Inheritance diagram for lsst.sconsUtils.tests.Control:

Public Member Functions

def __init__
 Create an object to run tests. More...
 
def args
 
def ignore
 
def messages
 
def run
 

Public Attributes

 runExamples
 

Private Attributes

 _env
 
 _tmpDir
 
 _cwd
 
 _verbose
 
 _info
 
 _args
 

Static Private Attributes

string _IGNORE = "IGNORE"
 
string _EXPECT_FAILURE = "EXPECT_FAILURE"
 

Detailed Description

A class to control unit tests.

This class is unchanged from previous versions of sconsUtils, but it will now generally be called via scripts.BasicSConscript.tests().

Definition at line 17 of file tests.py.

Constructor & Destructor Documentation

def lsst.sconsUtils.tests.Control.__init__ (   self,
  env,
  ignoreList = None,
  expectedFailures = None,
  args = None,
  tmpDir = ".tests",
  verbose = False 
)

Create an object to run tests.

Parameters
envAn SCons Environment (almost always lsst.sconsUtils.env).
ignoreListA list of tests that should NOT be run — useful in conjunction with glob patterns. If a file is listed as "@fileName", the @ is stripped and we don't bother to check if fileName exists (useful for machine-generated files).
expectedFaluresA dictionary; the keys are tests that are known to fail; the values are strings to print.
argsA dictionary with testnames as keys, and argument strings as values. As scons always runs from the top-level directory, tests has to fiddle with paths. If an argument is a file this is done automatically; if it's e.g. just a basename then you have to tell tests that it's really (part of a) filename by prefixing the name by "file:".
tmpDirThe location of the test outputs.
verboseHow chatty you want the test code to be.
1  tests = lsst.tests.Control(
2  env,
3  args={
4  "MaskIO_1" : "data/871034p_1_MI_msk.fits",
5  "MaskedImage_1" : "file:data/871034p_1_MI foo",
6  },
7  ignoreList=["Measure_1"],
8  expectedFailures={"BBox_1": "Problem with single-pixel BBox"}
9 )

Definition at line 52 of file tests.py.

52 
53  tmpDir=".tests", verbose=False):
54  env.AppendENVPath('PYTHONPATH', os.environ['PYTHONPATH'])
55 
56  self._env = env
57 
58  self._tmpDir = tmpDir
59  self._cwd = os.path.abspath(os.path.curdir)
60 
61  self._verbose = verbose
62 
63  self._info = {} # information about processing targets
64  if ignoreList:
65  for f in ignoreList:
66  if re.search(r"^@", f): # @dfilename => don't complain if filename doesn't exist
67  f = f[1:]
68  else:
69  if not os.path.exists(f):
70  state.log.warn("You're ignoring a non-existent file, %s" % f)
71  self._info[f] = (self._IGNORE, None)
72 
73  if expectedFailures:
74  for f in expectedFailures.keys():
75  self._info[f] = (self._EXPECT_FAILURE, expectedFailures[f])
76 
77  if args:
78  self._args = args # arguments for tests
79  else:
80  self._args = {}
81 
82  self.runExamples = True # should I run the examples?
83  try:
84  self.runExamples = (os.stat(self._tmpDir).st_mode & 0700) != 0 # file is user read/write/executable
85  except OSError:
86  pass
87 
88  if not self.runExamples:
89  print >> sys.stderr, "Not running examples; \"chmod 755 %s\" to run them again" % self._tmpDir

Member Function Documentation

def lsst.sconsUtils.tests.Control.args (   self,
  test 
)

Definition at line 90 of file tests.py.

90 
91  def args(self, test):
92  try:
93  return self._args[test]
94  except KeyError:
95  return ""
def lsst.sconsUtils.tests.Control.ignore (   self,
  test 
)

Definition at line 96 of file tests.py.

96 
97  def ignore(self, test):
98  if \
99  not re.search(r"\.py$", test) and \
100  len(self._env.Glob(test)) == 0: # we don't know how to build it
101  return True
102 
103  ignoreFile = self._info.has_key(test) and self._info[test][0] == self._IGNORE
104 
105  if self._verbose and ignoreFile:
106  print >> sys.stderr, "Skipping", test
107 
108  return ignoreFile
def lsst.sconsUtils.tests.Control.messages (   self,
  test 
)
Return the messages to be used in case of success/failure; the logicals
(note that they are strings) tell whether the test is expected to pass

Definition at line 109 of file tests.py.

110  def messages(self, test):
111  """Return the messages to be used in case of success/failure; the logicals
112  (note that they are strings) tell whether the test is expected to pass"""
113 
114  if self._info.has_key(test) and self._info[test][0] == self._EXPECT_FAILURE:
115  msg = self._info[test][1]
116  return "false", "Passed, but should have failed: %s" % msg, \
117  "true", "Failed as expected: %s" % msg
118  else:
119  return "true", "passed", \
120  "false", "failed"
def lsst.sconsUtils.tests.Control.run (   self,
  fileGlob 
)

Definition at line 121 of file tests.py.

122  def run(self, fileGlob):
123  if not isinstance(fileGlob, basestring): # env.Glob() returns an scons Node
124  fileGlob = str(fileGlob)
125  targets = []
126  if not self.runExamples:
127  return targets
128  for f in glob.glob(fileGlob):
129  interpreter = "" # interpreter to run test, if needed
130 
131  if re.search(r"\.cc", f): # look for executable
132  f = os.path.splitext(f)[0]
133  else:
134  interpreter = "python"
135 
136  if self.ignore(f):
137  continue
138 
139  target = os.path.join(self._tmpDir, f)
140 
141  args = []
142  for a in self.args(f).split(" "):
143  # if a is a file, make it an absolute name as scons runs from the root directory
144  filePrefix = "file:"
145  if re.search(r"^" + filePrefix, a): # they explicitly said that this was a file
146  a = os.path.join(self._cwd, a[len(filePrefix):])
147  else:
148  try: # see if it's a file
149  os.stat(a)
150  a = os.path.join(self._cwd, a)
151  except OSError:
152  pass
153 
154  args += [a]
155 
156  (should_pass, passedMsg, should_fail, failedMsg) = self.messages(f)
157 
158  expandedArgs = " ".join(args)
159  result = self._env.Command(target, f, """
160  @rm -f ${TARGET}.failed;
161  @printf "%%s" 'running ${SOURCES}... ';
162  @echo $SOURCES %s > $TARGET; echo >> $TARGET;
163  @if %s $SOURCES %s >> $TARGET 2>&1; then \
164  if ! %s; then mv $TARGET ${TARGET}.failed; fi; \
165  echo "%s"; \
166  else \
167  if ! %s; then mv $TARGET ${TARGET}.failed; fi; \
168  echo "%s"; \
169  fi;
170  """ % (expandedArgs, interpreter, expandedArgs, should_pass, passedMsg, should_fail, failedMsg))
171 
172  targets.extend(result)
173 
174  self._env.Alias(os.path.basename(target), target)
175 
176  self._env.Clean(target, self._tmpDir)
177 
178  return targets

Member Data Documentation

lsst.sconsUtils.tests.Control._args
private

Definition at line 77 of file tests.py.

lsst.sconsUtils.tests.Control._cwd
private

Definition at line 58 of file tests.py.

lsst.sconsUtils.tests.Control._env
private

Definition at line 55 of file tests.py.

string lsst.sconsUtils.tests.Control._EXPECT_FAILURE = "EXPECT_FAILURE"
staticprivate

Definition at line 19 of file tests.py.

string lsst.sconsUtils.tests.Control._IGNORE = "IGNORE"
staticprivate

Definition at line 18 of file tests.py.

lsst.sconsUtils.tests.Control._info
private

Definition at line 62 of file tests.py.

lsst.sconsUtils.tests.Control._tmpDir
private

Definition at line 57 of file tests.py.

lsst.sconsUtils.tests.Control._verbose
private

Definition at line 60 of file tests.py.

lsst.sconsUtils.tests.Control.runExamples

Definition at line 81 of file tests.py.


The documentation for this class was generated from the following file: