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 1 commit
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
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
15 changes: 15 additions & 0 deletions testing/vcs/test_script_for_py.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import vcs

list=["boxfill","meshfill","isofill","textcombined","texttable","vector"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You shouldn't name things reserved words in python (list being the type of []). It technically works but is bad form, and will break things later down the road.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, you're missing a few:

"isoline", "1d", "taylordiagram", "3d_scalar", "3d_dual_scalar", "3d_vector"

Remove "textcombined" and "texttable"; these should be handled in a second loop, which will do secondary objects (marker, fillarea, colormap, line, textcombined, texttable, textorientation).

for obj in list:
s=''
tc=''
if obj == 'textcombined':
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's extract the secondary graphics methods to a separate loop. Also drop the below logic.

vcs.createtextcombined('EXAMPLE_tt', 'qa', 'EXAMPLE_tto', '7left')
tc="'EXAMPLE_tt','EXAMPLE_tto'"
code="s=vcs.get%s(%s)" % (obj, tc)
exec(code)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's bad form to use exec for... well, anything. I know it's sprinkled throughout the codebase, but you shouldn't pick up bad habits from that 😉

Instead, you can use this:

s = vcs.creategraphicsmethod(obj, 'test_%s' % obj)

which will let you generate an arbitrary graphics method.

try:
s.script(obj+"_script.py")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to delete the files after you generate them. Also, this only builds the script; for this to be a real test, it needs to validate correctness. That means running the scripts and seeing if the generated object matches the original.

except:
raise("Python script creation broke on "+obj+".script()")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't work, for a couple of reasons:

  • raise is a keyword, not a function. This is just a misleadingly worded version of raise "Python script creation broke on...".
  • You can only raise objects that derive from the BaseException class in python. This usually means something like: `raise ValueError("Python script creation broke on...").

Moreover, you should just print "Python script creation broke on..." and do sys.exit(1).