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
|
#!/usr/bin/env python
# This is the script that runs a testing python script.
# The script to be run must be the first argument.
import sys
if len(sys.argv) < 2:
print("Usage %s <test script> [<addition arguments>]" % sys.argv[0])
sys.exit(1)
for i in range(2, len(sys.argv)):
if sys.argv[i] == '-A' and i < len(sys.argv)-1:
sys.path = sys.path + [sys.argv[i+1]]
import vtk
import math
#these are the modules that define methods/variables
#used by many scripts. We just include them always
from backdrop import *
from mccases import *
import expr
import catch
import info
import file
from vtk.util.colors import *
#implementation for lindex.
def lindex(list, index):
if type(list) == type("string"):
return list.split()[index]
return list[index]
#gets with no varName (returns the read string)
def gets(file):
line = file.readline()
if line[-1] == "\n":
line = line[:-1]
return line
def gets(file, varName, global_vars):
line = gets(file)
ret = len(line)
global_vars[varName] = line
return ret
def tcl_platform(what):
if what != "platform":
raise ValueError("Only platform supported as yet!")
plat = sys.platform
if plat[:5] == "linux":
return "unix"
return plat
def get_variable_name(*args):
var_name = ""
for arg in args:
if arg == "":
continue
# it is essential to qualify the scope of type since
# some test define type variable which messes up the
# bultin call.
if __builtins__.type(arg) == __builtins__.type("string"):
var_name += arg
else:
var_name += repr(arg)
return var_name
#init Tk
try:
import Tkinter
pythonTk = Tkinter.Tk()
pythonTk.withdraw()
except:
pythonTk = None
pass #no hassles if Tk is not present.
# setup some common things for testing
rtTempObject = vtk.vtkObject()
rtExMath = vtk.vtkMath()
rtExMath.RandomSeed(6)
# create the testing class to do the work
rtTester = vtk.vtkTesting()
for arg in sys.argv[2:]:
rtTester.AddArgument(arg)
VTK_DATA_ROOT = rtTester.GetDataRoot()
# load in the script
test_script = sys.argv[1]
# set the default threshold, the Tcl script may change this
threshold = -1
# we pass the locals over so that the test script has access to
# all the locals we have defined here.
exec(compile(open(test_script).read(), test_script, 'exec'), globals(), locals())
local_variables_dict = locals()
if "iren" in local_variables_dict:
renWin.Render()
if pythonTk:
# run the event loop quickly to map any tkwidget windows
pythonTk.update()
rtResult = 0
if rtTester.IsValidImageSpecified() != 0:
# look for a renderWindow ImageWindow or ImageViewer
# first check for some common names
if "renWin" in local_variables_dict:
rtTester.SetRenderWindow(renWin)
if threshold == -1:
threshold = 10
else:
if threshold == -1:
threshold = 5
if "viewer" in local_variables_dict:
rtTester.SetRenderWindow(viewer.GetRenderWindow())
viewer.Render()
elif "imgWin" in local_variables_dict:
rtTester.SetRenderWindow(imgWin)
imgWin.Render()
rtResult = rtTester.RegressionTest(threshold)
if rtTester.IsInteractiveModeSpecified() != 0:
if "iren" in local_variables_dict:
iren.Start()
if rtResult == 0:
sys.exit(1)
sys.exit(0)
|