Gaudi Framework, version v23r9

Home   Generated: Thu Jul 18 2013
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Classes | Functions
run_qmtest Namespace Reference

Classes

class  Options
 

Functions

def parseOptions
 
def main
 

Function Documentation

def run_qmtest.main (   argv = None)

Definition at line 67 of file run_qmtest.py.

67 
68 def main(argv = None):
69  opts = parseOptions(argv)
70 
71  print "==========> Running tests for package %s" % opts.package
72 
73  # create the destination directory if necessary
74  if opts.output:
75  results_dest_dir = os.path.realpath(os.path.join(opts.qmtest_dir, os.path.dirname(opts.output)))
76  if not os.path.exists(results_dest_dir):
77  print "==========> Creating '%s'" % results_dest_dir
78  os.makedirs(results_dest_dir, 0755)
79 
80  print "==========> Entering '%s'" % opts.qmtest_dir
81  os.chdir(opts.qmtest_dir)
82 
83  qmtest_cmd = ["qmtest"]
84 
85  if not os.path.isdir("QMTest"):
86  # If the test-db directory is not initialized, we have to initialize it
87  try:
88  os.mkdir("QMTest")
89  except OSError:
90  # we cannot create the directory... we need a temporary test database
91  from tempfile import mkdtemp
92  from shutil import copytree
93  # the extra level is needed because of a limitation in copytree
94  tdb = os.path.join(mkdtemp("GaudiTest"), "qmtest")
95  copytree(".", tdb)
96  os.chmod(tdb, 0700) # This is needed because copytree will copy also the restrictive permissions
97  qmtest_cmd += ["--tdb", tdb]
98  print "==========> Initializing QMTest database"
99  os.system(" ".join(qmtest_cmd + ["create-tdb"]))
100 
101  if opts.html_output:
102  opts.qmtest_args.insert(0, '''--result-stream "GaudiTest.HTMLResultStream(dir='%s')"'''
103  % opts.html_output.replace("\\","\\\\"))
104 
105  # prepare the qmtest command
106  cmd = " ".join(qmtest_cmd + ["run"] + opts.qmtest_args)
107 
108  if not opts.have_user_options:
109  # If there are no user options, we should check for a default test suite
110  # to run.
111  # The suite to run is the first one available in the list passed via
112  # the environment variable GAUDI_QMTEST_DEFAULT_SUITE (comma-separated list)
113  # or the suite with the same name as the package.
114  # If none of them is present, no argument is passed to qmtest, so all the tests
115  # are run.
116  suites = []
117  if "GAUDI_QMTEST_DEFAULT_SUITE" in os.environ:
118  suites.extend([s.strip().lower()
119  for s in os.environ["GAUDI_QMTEST_DEFAULT_SUITE"].split(",")])
120  suites.append(opts.package.lower())
121  for s in suites:
122  if os.path.exists("%s.qms" % s):
123  cmd += " %s" % s
124  break
125 
126  if opts.dry_run:
127  print "==========> Would run '%s'"%cmd
128  else:
129  print "==========> Running '%s'"%cmd
130  os.system(cmd)
131 
132  # drop the temporary test DB if needed
133  if "--tdb" in qmtest_cmd:
134  from shutil import rmtree
135  def onerror(func, path, exc_info):
136  """
137  Change the permissions and try again to remove a file or a dir.
138  Ignore failures.
139  """
140  if func in [os.remove, os.rmdir]:
141  # change permissions and try again
142  try:
143  os.chmod(path, 0600)
144  os.chmod(os.path.dirname(path), 0700)
145  func(path)
146  except os.error:
147  pass
148  rmtree(os.path.dirname(qmtest_cmd[-1]), onerror = onerror)
149 
150 # Note: the return code of qmtest is not propagated to avoid that
# CMT stops if we have a non-PASS tests (e.g. UNTESTED).
def run_qmtest.parseOptions (   argv = None)

Definition at line 13 of file run_qmtest.py.

13 
14 def parseOptions(argv = None):
15  if argv is None:
16  argv = sys.argv[1:]
17  # Defaults
18  opts = Options()
19  opts.package = "Unknown"
20  opts.qmtest_args = []
21  opts.have_user_options = False
22  opts.output = os.path.normpath(os.path.expandvars(os.environ["QMTESTRESULTS"]))
23  opts.qmtest_dir = os.path.normpath(os.path.expandvars(os.environ["QMTESTLOCALDIR"]))
24  opts.dry_run = False
25  if "GAUDI_QMTEST_HTML_OUTPUT" in os.environ:
26  opts.html_output = os.path.normpath(os.path.expandvars(os.environ.get("GAUDI_QMTEST_HTML_OUTPUT")))
27  else:
28  opts.html_output = None
29 
30  # First argument is the package name:
31  if argv:
32  opts.package = argv.pop(0)
33 
34  # If the use specifies a directory where to collect all the results
35  # (e.g. because running from a read-only location) we must use it
36  if "QMTESTRESULTSDIR" in os.environ:
37  opts.output = os.path.normpath(os.path.expandvars(os.environ["QMTESTRESULTSDIR"]))
38  opts.output = os.path.join(opts.output,
39  "%s.%s.qmr" % (opts.package, os.environ.get("CMTCONFIG", "noConfig")))
40 
41  # Do we have user options?
42  opts.have_user_options = len(argv)
43  # Scan the user options (if any) to look for options we must intercept
44  while argv:
45  o = argv.pop(0)
46  if o in ['-o','--output']:
47  # make the path absolute
48  opts.output = os.path.realpath(argv.pop(0))
49  opts.have_user_options -= 2
50  elif o in ["--no-output"]:
51  opts.output = None
52  opts.have_user_options -= 1
53  elif o in ["--dry-run"]:
54  opts.dry_run = True
55  opts.have_user_options -= 1
56  elif o in ["--html-output"]:
57  opts.html_output = os.path.realpath(argv.pop(0))
58  opts.have_user_options -= 2
59  else:
60  opts.qmtest_args.append(o)
61  # Add the option for the output to the qmtest_args
62  if opts.output:
63  opts.qmtest_args = ["-o", opts.output] + opts.qmtest_args
64  else:
65  opts.qmtest_args.insert(0, "--no-output")
66  return opts

Generated at Thu Jul 18 2013 12:18:16 for Gaudi Framework, version v23r9 by Doxygen version 1.8.2 written by Dimitri van Heesch, © 1997-2004