| # Gaudi Framework, version v25r0 |

Home |  | Generated: Mon Feb 17 2014

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- Namespace List
- Namespace Members

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 75 of file run_qmtest.py.

75
76 def main(argv = None):
77 opts = parseOptions(argv)
78
79 print "==========> Running tests for package %s" % opts.package
80
81 # create the destination directory if necessary
82 if opts.output:
83 results_dest_dir = os.path.realpath(os.path.join(opts.qmtest_dir, os.path.dirname(opts.output)))
84 if not os.path.exists(results_dest_dir):
85 print "==========> Creating '%s'" % results_dest_dir
86 os.makedirs(results_dest_dir, 0755)
87
88 print "==========> Entering '%s'" % opts.qmtest_dir
89 os.chdir(opts.qmtest_dir)
90
91 qmtest_cmd = ["qmtest"]
92
93 if not os.path.isdir("QMTest"):
94 # If the test-db directory is not initialized, we have to initialize it
95 try:
96 os.mkdir("QMTest")
97 except OSError:
98 # we cannot create the directory... we need a temporary test database
99 from tempfile import mkdtemp
100 from shutil import copytree
101 # the extra level is needed because of a limitation in copytree
102 tdb = os.path.join(mkdtemp("GaudiTest"), "qmtest")
103 copytree(".", tdb)
104 os.chmod(tdb, 0700) # This is needed because copytree will copy also the restrictive permissions
105 qmtest_cmd += ["--tdb", tdb]
106 print "==========> Initializing QMTest database"
107 os.system(" ".join(qmtest_cmd + ["create-tdb"]))
108
109 if opts.xml_output:
110 opts.qmtest_args.insert(0, '''--result-stream "GaudiTest.XMLResultStream(dir='%s',prefix='%s_')"'''
111 % (opts.xml_output.replace("\\","\\\\"), opts.package))
112
113 if opts.html_output:
114 opts.qmtest_args.insert(0, '''--result-stream "GaudiTest.HTMLResultStream(dir='%s')"'''
115 % opts.html_output.replace("\\","\\\\"))
116
117 # prepare the qmtest command
118 cmd = " ".join(qmtest_cmd + ["run"] + opts.qmtest_args)
119
120 if not opts.have_user_options:
121 # If there are no user options, we should check for a default test suite
122 # to run.
123 # The suite to run is the first one available in the list passed via
124 # the environment variable GAUDI_QMTEST_DEFAULT_SUITE (comma-separated list)
125 # or the suite with the same name as the package.
126 # If none of them is present, no argument is passed to qmtest, so all the tests
127 # are run.
128 suites = []
129 if "GAUDI_QMTEST_DEFAULT_SUITE" in os.environ:
130 suites.extend([s.strip().lower()
131 for s in os.environ["GAUDI_QMTEST_DEFAULT_SUITE"].split(",")])
132 suites.append(opts.package.lower())
133 for s in suites:
134 if os.path.exists("%s.qms" % s):
135 cmd += " %s" % s
136 break
137
138 if opts.dry_run:
139 print "==========> Would run '%s'"%cmd
140 else:
141 print "==========> Running '%s'"%cmd
142 os.system(cmd)
143
144 # drop the temporary test DB if needed
145 if "--tdb" in qmtest_cmd:
146 from shutil import rmtree
147 def onerror(func, path, exc_info):
148 """
149 Change the permissions and try again to remove a file or a dir.
150 Ignore failures.
151 """
152 if func in [os.remove, os.rmdir]:
153 # change permissions and try again
154 try:
155 os.chmod(path, 0600)
156 os.chmod(os.path.dirname(path), 0700)
157 func(path)
158 except os.error:
159 pass
160 rmtree(os.path.dirname(qmtest_cmd[-1]), onerror = onerror)
161
162 # 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 if "GAUDI_QMTEST_XML_OUTPUT" in os.environ:
30 opts.xml_output = os.path.normpath(os.path.expandvars(os.environ.get("GAUDI_QMTEST_XML_OUTPUT")))
31 else:
32 opts.xml_output = None
33
34 # First argument is the package name:
35 if argv:
36 opts.package = argv.pop(0)
37
38 # If the use specifies a directory where to collect all the results
39 # (e.g. because running from a read-only location) we must use it
40 if "QMTESTRESULTSDIR" in os.environ:
41 opts.output = os.path.normpath(os.path.expandvars(os.environ["QMTESTRESULTSDIR"]))
42 opts.output = os.path.join(opts.output,
43 "%s.%s.qmr" % (opts.package, os.environ.get("CMTCONFIG", "noConfig")))
44
45 # Do we have user options?
46 opts.have_user_options = len(argv)
47 # Scan the user options (if any) to look for options we must intercept
48 while argv:
49 o = argv.pop(0)
50 if o in ['-o','--output']:
51 # make the path absolute
52 opts.output = os.path.realpath(argv.pop(0))
53 opts.have_user_options -= 2
54 elif o in ["--no-output"]:
55 opts.output = None
56 opts.have_user_options -= 1
57 elif o in ["--dry-run"]:
58 opts.dry_run = True
59 opts.have_user_options -= 1
60 elif o in ["--html-output"]:
61 opts.html_output = os.path.realpath(argv.pop(0))
62 opts.have_user_options -= 2
63 # Add xml output option
64 elif o in ["--xml-output"]:
65 opts.xml_output = os.path.realpath(argv.pop(0))
66 opts.have_user_options -= 2
67 else:
68 opts.qmtest_args.append(o)
69 # Add the option for the output to the qmtest_args
70 if opts.output:
71 opts.qmtest_args = ["-o", opts.output] + opts.qmtest_args
72 else:
73 opts.qmtest_args.insert(0, "--no-output")
74 return opts