/usr/lib/python3/dist-packages/pyutilib/th/runtests.py is in python3-pyutilib 5.3.5-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 | # _________________________________________________________________________
#
# PyUtilib: A Python utility library.
# Copyright (c) 2008 Sandia Corporation.
# This software is distributed under the BSD License.
# Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
# the U.S. Government retains certain rights in this software.
# _________________________________________________________________________
import sys
try:
import nose
import nose.plugins
except ImportError:
print("This testing utility requires the 'nose' Python testing tool")
sys.exit(1)
try:
import nosexunit
import nosexunit.plugin
nose_xunit_installed=True
except ImportError:
nose_xunit_installed=False
try:
import coverage
import nose.plugins.cover
coverage_installed=True
except ImportError:
coverage_installed=False
import re
import logging
import os
import os.path
import glob
import copy
from optparse import OptionParser
# Ignore exceptions that occur during a logging statement
logging.raiseExceptions=0
class UnwantedPackagePlugin(nose.plugins.Plugin):
enabled=True
name="unwanted-package"
def __init__(self,unwanted):
self.unwanted=unwanted
def configure(self, options, conf):
pass
def wantDirectory(self, dirname):
want=None
if os.path.basename(dirname) in self.unwanted:
want=False
return want
def generate_options(package, packages, subpackages, filter, options, testdir, xunitdir, dirname):
if not type(packages) is list:
tmp = [packages]
else:
tmp = packages
newargs=[]
if options.xunit:
newargs = ['--with-xunit', '--xunit-file',xunitdir+os.sep+'TEST-'+package+'.xml']
#if coverage_installed:
#newargs = newargs + ['--source-folder', '.']
if coverage_installed:
newargs = newargs + ['--with-coverage', '--cover-erase', '--cover-inclusive', '--cover-package',package]
if options.filtering or options.filtering_all:
for item in filter:
newargs.append('--cover-filter='+item)
if len(tmp) > 0:
for item in subpackages:
if not item in tmp:
newargs.append('--cover-filter='+package+'.'+item)
if options.verbose:
newargs = newargs + ['--verbosity=3']
newargs = newargs + ['--where',dirname]
return newargs
def main(argv, package, subpackages, filter, testdir, dirname="test"):
parser = OptionParser()
parser.add_option("--no-xunit",
help="Disable generation of XUnit XML summary",
action="store_false",
dest="xunit",
default=True)
parser.add_option("-v","--verbose",
help="Provide verbose output",
action="store_true",
dest="verbose",
default=False)
parser.add_option("-f","--filter",
help="Enable filtering of coverage tests with a customized nose installation",
action="store_true",
dest="filtering",
default=False)
parser.add_option("-F","--filter-all",
help="Apply nose to all packages, filtering each coverage test",
action="store_true",
dest="filtering_all",
default=False)
parser.usage="runtests [options] <package> [...]"
parser.description="A utility to run Pyomo tests. A particular feature of this tool is the ability to filter coverage information, using a customized installation of the nose utility."
parser.epilog="""The customized nose utility that supports filtering can be obtained from Bill Hart (wehart@sandia.gov)."""
#
# Process argv list
#
(options, args) = parser.parse_args(args=argv)
#
# Preprocess arguments, to eliminate trailing '/' or '\\' characters, which a user
# might add using tab completion.
#
for i in range(0,len(args)):
if args[i][-1] == os.sep:
args[i] = args[i][:-1]
#
# Verify that the arguments are valid subpackages
#
unwanted=copy.copy(subpackages)
for arg in args[1:]:
if not arg in subpackages:
print("ERROR: no subpackage '"+arg)
sys.exit(1)
unwanted.remove(arg)
if unwanted == subpackages:
unwanted=[]
#
# Remove coverage files from previous 'runtests' executions
#
coverage_file = testdir+os.sep+dirname+os.sep+".coverage"
if os.path.exists(coverage_file):
os.remove(coverage_file)
os.environ["COVERAGE_FILE"] = coverage_file
#for file in glob.glob("*/.coverage"):
#os.remove(file)
#for file in glob.glob("*/*/.coverage"):
#os.remove(file)
#
# Remove XML files from previous 'runtests' executions
#
xunitdir = testdir+os.sep+dirname+os.sep+"xunit"
if os.path.exists(xunitdir):
for file in glob.glob(xunitdir+os.sep+"TEST*.xml"):
os.remove(file)
else:
os.mkdir(xunitdir)
plugins = [UnwantedPackagePlugin(unwanted)]
#if nose_xunit_installed and options.xunit:
#plugins.append(nosexunit.plugin.NoseXUnit())
#if coverage_installed:
#plugins.append(nose.plugins.cover.Coverage())
#plugins.append(nose.plugins.xunit.Xunit())
if not options.filtering_all:
newargs = ['runtests'] + generate_options(package, args[1:], subpackages, filter, options, testdir, xunitdir, dirname) + args[1:]
os.chdir(testdir)
if options.verbose:
print("Nose Arguments:", newargs)
print("Test Dir:", testdir)
if len(args) > 1:
print("Test Packages:",)
for arg in args[1:]:
print(arg,)
print("")
if len(unwanted) > 1:
print("Ignored Packages:",unwanted)
sys.argv=newargs
nose.run(argv=newargs, addplugins=plugins)
else:
if len(args[1:]) == 0:
arglist = subpackages
else:
arglist = args[1:]
for arg in arglist:
newargs = ['runtests'] + generate_options(arg,options) + [arg]
print("Package Coverage Tests: "+arg)
tmp = sys.stdout
os.chdir(testdir)
if options.verbose:
print("Nose Arguments:", newargs)
print("Test Dir:", testdir)
if len(args) > 1:
print("Test Packages:",)
for arg in args[1:]:
print(arg,)
print("")
if len(unwanted) > 1:
print("Ignored Packages:",unwanted)
nose.run(argv=newargs, addplugins=plugins)
sys.stdout = tmp
#
# Rename xUnit files and insert the package information
#
if os.path.exists(xunitdir):
p = re.compile('^.*TEST-(.+)\.xml')
for file in glob.glob(xunitdir+os.sep+"TEST-*.xml"):
oldname = p.match(file).group(1)
if oldname == "test":
suffix=""
else:
suffix="."+oldname
FILE = open(file,"r")
text0 = "".join(FILE.readlines())
FILE.close()
ptmp = re.compile("testsuite name=\"nosetests\"")
text1 = ptmp.sub("testsuite name=\""+package+"\"", text0)
#ptmp = re.compile("classname=\""+oldname)
#text2 = ptmp.sub("classname=\""+package+suffix, text1)
#FILE = open(xunitdir+os.sep+"TEST-"+package+suffix+".xml","w")
FILE = open(file,"w")
FILE.write(text1)
FILE.close()
#os.remove(file)
|