| # Gaudi Framework, version v23r0 |

Home |  | Generated: Mon Jan 30 2012

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.

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

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

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines