Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added test for script() with .py extension #2144

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ include(ExternalProject)
include(cdat_pkg)
# CONDA Options
set(CONDA_ENVIRONMENT_NAME ${cdat_VERSION} CACHE STRING "Name of conda environment we want to build CDAT in")
set(CONDA_CHANNEL_UVCDAT uvcdat CACHE STRING "channels to use (if more than one use '-c' between channels e.g. uvcdat/label/nightly -c uvcdat)")
set(CONDA_CHANNEL_UVCDAT "conda-forge -c uvcdat" CACHE STRING "channels to use (if more than one use '-c' between channels e.g. uvcdat/label/nightly -c uvcdat)")

execute_process(COMMAND
"${GIT_EXECUTABLE}" symbolic-ref --short HEAD
Expand Down
6 changes: 6 additions & 0 deletions testing/vcs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1197,6 +1197,12 @@ cdat_add_test(test_vcs_textextents
${BASELINE_DIR}/test_textextents.png
)

cdat_add_test(test_script_for_py
"${PYTHON_EXECUTABLE}"
${cdat_SOURCE_DIR}/testing/vcs/test_script_for_py.py
)




add_subdirectory(vtk_ui)
Expand Down
117 changes: 117 additions & 0 deletions testing/vcs/test_script_for_py.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
import vcs, sys, os

def attrCompare(old_dict, new_dict):
if old_dict.keys() != new_dict.keys():
return (False, "keys mismatch")
for key in old_dict.keys():
if old_dict[key] == new_dict[key]:
continue
elif type(old_dict[key]) is tuple:
l = list(old_dict[key])
if l == new_dict[key]:
continue
else:
return (False, key + "not equal.")
return (True, "All values equal")

# graphics method list
gms = ["boxfill", "meshfill", "isofill", "vector", "isoline", "1d", "taylordiagram", "3d_scalar", "3d_dual_scalar",
"3d_vector"]
for obj in gms:
s = vcs.creategraphicsmethod(obj, 'default', 'test_%s' % obj)
s_dict = vcs.dumpToDict(s)[0]
scr = obj + "_script.py"
try:
s.script(scr)
except:
print "Python script creation broke on " + obj + ".script()"
sys.exit(1)
else:
# script was written successfully, now test for accuracy when it's run
# remove the object, or scriptrun() will just use the same thing
vcs.removeobject(s)
try:
vcs.scriptrun(scr) # test to see that scriptrun actually runs
except:
print "Scriptrun broke on " + obj
os.remove(scr)
sys.exit(1)
else:
# script has both written and run without failure, just need to check for accuracy
try:
new_s = vcs.getgraphicsmethod(obj, "test_%s" % obj)
except:
print "Scriptrun failed: test_%s does not exist" %obj
sys.exit(1)
else:
new_s_dict = vcs.dumpToDict(new_s)[0]
comp = attrCompare(s_dict, new_s_dict)
if not comp[0]:
print "Scriptrun failed: " + comp[1]
sys.exit(1)
if os.path.exists(scr):
os.remove(scr)


# text objects
tt = vcs.createtexttable('test_tt')
to = vcs.createtextorientation('test_tto')
tcs = vcs.listelements('textcombined')
if len(tcs) == 0:
tc = vcs.createtext(Tt_name="testtext", Tt_source=tt.name, To_name="testtext", To_source=to.name)
else:
tc = vcs.gettext(tcs[0])

# other secondaries
fa = vcs.createfillarea('test_fillarea')
ma = vcs.createmarker('test_marker')
li = vcs.createline('test_line')
secondaries = [tt, to, tc, fa, ma, li]
for sec in secondaries:
scr = sec.s_name + '_script.py'
old_dict = vcs.dumpToDict(sec)[0]
try:
sec.script(scr)
except:
print "Python script creation broke on " + sec.s_name + ".script()"
sys.exit(1)
else:
vcs.removeobject(sec)
try:
vcs.scriptrun(scr) # test to see that scriptrun actually runs
except:
print "Scriptrun broke on " + sec.s_name
os.remove(scr)
sys.exit(1)
else:
if sec.s_name == 'To':
getfunc = vcs.gettextorientation
elif sec.s_name == 'Tt':
getfunc = vcs.gettexttable
elif sec.s_name == 'Tc':
getfunc = (vcs.gettext, "testtext", "testtext")
elif sec.s_name == 'Tm':
getfunc = vcs.getmarker
elif sec.s_name == 'Tf':
getfunc = vcs.getfillarea
else:
getfunc = vcs.getline
# script has both written and run without failure, just need to check for accuracy
try:
if type(getfunc) is tuple:
new_sec = getfunc[0](getfunc[1], getfunc[2])
else:
new_sec = getfunc(sec.name)
except:
print "Scriptrun failed: %s does not exist" % sec.name
sys.exit(1)
else:
new_dict = vcs.dumpToDict(new_sec)[0]
comp = attrCompare(old_dict, new_dict)
if comp[0]:
print comp[1] + " for " + sec.s_name
else:
print "Scriptrun failed: " + comp[1]
sys.exit(1)
if os.path.exists(scr):
os.remove(scr)