| # Gaudi Framework, version v21r11 |

Home |  | Generated: 30 Sep 2010

# 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.

    00067                      :
    00068     opts = parseOptions(argv)
    00069
    00070     print "==========> Running tests for package %s" % opts.package
    00071
    00072     # create the destination directory if necessary
    00073     if opts.output:
    00074         results_dest_dir = os.path.realpath(os.path.join(opts.qmtest_dir, os.path.dirname(opts.output)))
    00075         if not os.path.exists(results_dest_dir):
    00076             print "==========> Creating '%s'" % results_dest_dir
    00077             os.makedirs(results_dest_dir, 0755)
    00078
    00079     print "==========> Entering '%s'" % opts.qmtest_dir
    00080     os.chdir(opts.qmtest_dir)
    00081
    00082     qmtest_cmd = ["qmtest"]
    00083
    00084     if not os.path.isdir("QMTest"):
    00085         # If the test-db directory is not initialized, we have to initialize it
    00086         try:
    00087             os.mkdir("QMTest")
    00088         except OSError:
    00089             # we cannot create the directory... we need a temporary test database
    00090             from tempfile import mkdtemp
    00091             from shutil import copytree
    00092             # the extra level is needed because of a limitation in copytree
    00093             tdb = os.path.join(mkdtemp("GaudiTest"), "qmtest")
    00094             copytree(".", tdb)
    00095             os.chmod(tdb, 0700) # This is needed because copytree will copy also the restrictive permissions
    00096             qmtest_cmd += ["--tdb", tdb]
    00097         print "==========> Initializing QMTest database"
    00098         os.system(" ".join(qmtest_cmd + ["create-tdb"]))
    00099
    00100     if opts.html_output:
    00101         opts.qmtest_args.insert(0, """--result-stream 'GaudiTest.HTMLResultStream(dir="%s")'""" % opts.html_output)
    00102
    00103     # prepare the qmtest command
    00104     cmd = " ".join(qmtest_cmd + ["run"] + opts.qmtest_args)
    00105
    00106     if not opts.have_user_options:
    00107         # If there are no user options, we should check for a default test suite
    00108         # to run.
    00109         # The suite to run is the first one available in the list passed via
    00110         # the environment variable GAUDI_QMTEST_DEFAULT_SUITE (comma-separated list)
    00111         # or the suite with the same name as the package.
    00112         # If none of them is present, no argument is passed to qmtest, so all the tests
    00113         # are run.
    00114         suites = []
    00115         if "GAUDI_QMTEST_DEFAULT_SUITE" in os.environ:
    00116             suites.extend([s.strip().lower()
    00117                            for s in os.environ["GAUDI_QMTEST_DEFAULT_SUITE"].split(",")])
    00118         suites.append(opts.package.lower())
    00119         for s in suites:
    00120             if os.path.exists("%s.qms" % s):
    00121                 cmd += " %s" % s
    00122                 break
    00123
    00124     if opts.dry_run:
    00125         print "==========> Would run '%s'"%cmd
    00126     else:
    00127         print "==========> Running '%s'"%cmd
    00128         os.system(cmd)
    00129
    00130     # drop the temporary test DB if needed
    00131     if "--tdb" in qmtest_cmd:
    00132         from shutil import rmtree
    00133         def onerror(func, path, exc_info):
    00134             """
    00135             Change the permissions and try again to remove a file or a dir.
    00136             Ignore failures.
    00137             """
    00138             if func in [os.remove, os.rmdir]:
    00139                 # change permissions and try again
    00140                 try:
    00141                     os.chmod(path, 0600)
    00142                     os.chmod(os.path.dirname(path), 0700)
    00143                     func(path)
    00144                 except os.error:
    00145                     pass
    00146         rmtree(os.path.dirname(qmtest_cmd[-1]), onerror = onerror)
    00147
    00148 # Note: the return code of qmtest is not propagated to avoid that
    00149 #       CMT stops if we have a non-PASS tests (e.g. UNTESTED).
    if __name__ == '__main__':

def run_qmtest::parseOptions | ( |  | argv = `None` | ) |

Definition at line 13 of file run_qmtest.py.

    00013                              :
    00014     if argv is None:
    00015         argv = sys.argv[1:]
    00016     # Defaults
    00017     opts = Options()
    00018     opts.package = "Unknown"
    00019     opts.qmtest_args = []
    00020     opts.have_user_options = False
    00021     opts.output = os.path.normpath(os.path.expandvars(os.environ["QMTESTRESULTS"]))
    00022     opts.qmtest_dir = os.path.normpath(os.path.expandvars(os.environ["QMTESTLOCALDIR"]))
    00023     opts.dry_run = False
    00024     if "GAUDI_QMTEST_HTML_OUTPUT" in os.environ:
    00025         opts.html_output = os.path.normpath(os.path.expandvars(os.environ.get("GAUDI_QMTEST_HTML_OUTPUT")))
    00026     else:
    00027         opts.html_output = None
    00028
    00029     # First argument is the package name:
    00030     if argv:
    00031         opts.package = argv.pop(0)
    00032
    00033     # If the use specifies a directory where to collect all the results
    00034     # (e.g. because running from a read-only location) we must use it
    00035     if "QMTESTRESULTSDIR" in os.environ:
    00036         opts.output = os.path.normpath(os.path.expandvars(os.environ["QMTESTRESULTSDIR"]))
    00037         opts.output = os.path.join(opts.output,
    00038                                    "%s.%s.qmr" % (opts.package, os.environ.get("CMTCONFIG", "noConfig")))
    00039
    00040     # Do we have user options?
    00041     opts.have_user_options = len(argv)
    00042     # Scan the user options (if any) to look for options we must intercept
    00043     while argv:
    00044         o = argv.pop(0)
    00045         if o in ['-o','--output']:
    00046             # make the path absolute
    00047             opts.output = os.path.realpath(argv.pop(0))
    00048             opts.have_user_options -= 2
    00049         elif o in ["--no-output"]:
    00050             opts.output = None
    00051             opts.have_user_options -= 1
    00052         elif o in ["--dry-run"]:
    00053             opts.dry_run = True
    00054             opts.have_user_options -= 1
    00055         elif o in ["--html-output"]:
    00056             opts.html_output = os.path.realpath(argv.pop(0))
    00057             opts.have_user_options -= 2
    00058         else:
    00059             opts.qmtest_args.append(o)
    00060     # Add the option for the output to the qmtest_args
    00061     if opts.output:
    00062         opts.qmtest_args = ["-o", opts.output] + opts.qmtest_args
    00063     else:
    00064         opts.qmtest_args.insert(0, "--no-output")
    00065     return opts
    00066
    def main(argv = None):