Testing.py 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685
  1. """ This module attempts to make it easy to create VTK-Python
  2. unittests. The module uses unittest for the test interface. For more
  3. documentation on what unittests are and how to use them, please read
  4. these:
  5. http://www.python.org/doc/current/lib/module-unittest.html
  6. http://www.diveintopython.org/roman_divein.html
  7. This VTK-Python test module supports image based tests with multiple
  8. images per test suite and multiple images per individual test as well.
  9. It also prints information appropriate for CDash
  10. (http://open.kitware.com/).
  11. This module defines several useful classes and functions to make
  12. writing tests easy. The most important of these are:
  13. class vtkTest:
  14. Subclass this for your tests. It also has a few useful internal
  15. functions that can be used to do some simple blackbox testing.
  16. compareImage(renwin, img_fname, threshold=0.15):
  17. Compares renwin with image and generates image if it does not
  18. exist. The threshold determines how closely the images must match.
  19. The function also handles multiple images and finds the best
  20. matching image.
  21. compareImageWithSavedImage(src_img, img_fname, threshold=0.15):
  22. Compares given source image (in the form of a vtkImageData) with
  23. saved image and generates the image if it does not exist. The
  24. threshold determines how closely the images must match. The
  25. function also handles multiple images and finds the best matching
  26. image.
  27. getAbsImagePath(img_basename):
  28. Returns the full path to the image given the basic image name.
  29. main(cases):
  30. Does the testing given a list of tuples containing test classes and
  31. the starting string of the functions used for testing.
  32. interact():
  33. Interacts with the user if necessary. The behavior of this is
  34. rather trivial and works best when using Tkinter. It does not do
  35. anything by default and stops to interact with the user when given
  36. the appropriate command line arguments.
  37. isInteractive():
  38. If interact() is not good enough, use this to find if the mode is
  39. interactive or not and do whatever is necessary to generate an
  40. interactive view.
  41. Examples:
  42. The best way to learn on how to use this module is to look at a few
  43. examples. The end of this file contains a trivial example. Please
  44. also look at the following examples:
  45. Rendering/Testing/Python/TestTkRenderWidget.py,
  46. Rendering/Testing/Python/TestTkRenderWindowInteractor.py
  47. Created: September, 2002
  48. Prabhu Ramachandran <prabhu@aero.iitb.ac.in>
  49. """
  50. from __future__ import absolute_import
  51. import sys, os, time
  52. import os.path
  53. import unittest, getopt
  54. from vtkmodules.vtkCommonCore import vtkCommand, vtkDebugLeaks
  55. from vtkmodules.vtkCommonSystem import vtkTimerLog
  56. from vtkmodules.vtkIOImage import vtkPNGReader, vtkPNGWriter
  57. from vtkmodules.vtkImagingCore import vtkImageDifference, vtkImageShiftScale
  58. from vtkmodules.vtkRenderingCore import vtkWindowToImageFilter
  59. from . import BlackBox
  60. # location of the VTK data files. Set via command line args or
  61. # environment variable.
  62. VTK_DATA_ROOT = ""
  63. # a list of paths to specific input data files
  64. VTK_DATA_PATHS = []
  65. # location of the VTK baseline images. Set via command line args or
  66. # environment variable.
  67. VTK_BASELINE_ROOT = ""
  68. # location of the VTK difference images for failed tests. Set via
  69. # command line args or environment variable.
  70. VTK_TEMP_DIR = ""
  71. # a list of paths to validated output files
  72. VTK_BASELINE_PATHS = []
  73. # Verbosity of the test messages (used by unittest)
  74. _VERBOSE = 0
  75. # Determines if it is necessary to interact with the user. If zero
  76. # don't interact if 1 interact. Set via command line args
  77. _INTERACT = 0
  78. # This will be set to 1 when the image test will not be performed.
  79. # This option is used internally by the script and set via command
  80. # line arguments.
  81. _NO_IMAGE = 0
  82. def skip():
  83. '''Cause the test to be skipped due to insufficient requirements.'''
  84. sys.exit(125)
  85. class vtkTest(unittest.TestCase):
  86. """A simple default VTK test class that defines a few useful
  87. blackbox tests that can be readily used. Derive your test cases
  88. from this class and use the following if you'd like to.
  89. Note: Unittest instantiates this class (or your subclass) each
  90. time it tests a method. So if you do not want that to happen when
  91. generating VTK pipelines you should create the pipeline in the
  92. class definition as done below for _blackbox.
  93. """
  94. _blackbox = BlackBox.Tester(debug=0)
  95. # Due to what seems to be a bug in python some objects leak.
  96. # Avoid the exit-with-error in vtkDebugLeaks.
  97. dl = vtkDebugLeaks()
  98. dl.SetExitError(0)
  99. dl = None
  100. def _testParse(self, obj):
  101. """Does a blackbox test by attempting to parse the class for
  102. its various methods using vtkMethodParser. This is a useful
  103. test because it gets all the methods of the vtkObject, parses
  104. them and sorts them into different classes of objects."""
  105. self._blackbox.testParse(obj)
  106. def _testGetSet(self, obj, excluded_methods=[]):
  107. """Checks the Get/Set method pairs by setting the value using
  108. the current state and making sure that it equals the value it
  109. was originally. This effectively calls _testParse
  110. internally. """
  111. self._blackbox.testGetSet(obj, excluded_methods)
  112. def _testBoolean(self, obj, excluded_methods=[]):
  113. """Checks the Boolean methods by setting the value on and off
  114. and making sure that the GetMethod returns the set value.
  115. This effectively calls _testParse internally. """
  116. self._blackbox.testBoolean(obj, excluded_methods)
  117. def pathToData(self, filename):
  118. """Given a filename with no path (i.e., no leading directories
  119. prepended), return the full path to a file as specified on the
  120. command line with a '-D' option.
  121. As an example, if a test is run with "-D /path/to/grid.vtu"
  122. then calling
  123. self.pathToData('grid.vtu')
  124. in your test will return "/path/to/grid.vtu". This is
  125. useful in combination with ExternalData, where data may be
  126. staged by CTest to a user-configured directory at build time.
  127. In order for this method to work, you must specify
  128. the JUST_VALID option for your test in CMake.
  129. """
  130. global VTK_DATA_PATHS
  131. if not filename:
  132. return VTK_DATA_PATHS
  133. for path in VTK_DATA_PATHS:
  134. if filename == os.path.split(path)[-1]:
  135. return path
  136. return filename
  137. def pathToValidatedOutput(self, filename):
  138. """Given a filename with no path (i.e., no leading directories
  139. prepended), return the full path to a file as specified on the
  140. command line with a '-V' option.
  141. As an example, if a test is run with
  142. "-V /path/to/validImage.png" then calling
  143. self.pathToData('validImage.png')
  144. in your test will return "/path/to/validImage.png". This is
  145. useful in combination with ExternalData, where data may be
  146. staged by CTest to a user-configured directory at build time.
  147. In order for this method to work, you must specify
  148. the JUST_VALID option for your test in CMake.
  149. """
  150. global VTK_BASELINE_PATHS
  151. if not filename:
  152. return VTK_BASELINE_PATHS
  153. for path in VTK_BASELINE_PATHS:
  154. if filename == os.path.split(path)[-1]:
  155. return path
  156. return filename
  157. def prepareTestImage(self, interactor, **kwargs):
  158. import time
  159. startTime = time.time()
  160. events = []
  161. def onKeyPress(caller, eventId):
  162. print('key is "' + caller.GetKeySym() + '"')
  163. events.append((time.time() - startTime, eventId, caller.GetKeySym()))
  164. def onButton(caller, eventId):
  165. events.append((time.time() - startTime, eventId))
  166. def onMovement(caller, eventId):
  167. events.append((time.time() - startTime, eventId, caller.GetEventPosition()))
  168. interactor.AddObserver(vtkCommand.KeyPressEvent, onKeyPress)
  169. interactor.AddObserver(vtkCommand.LeftButtonPressEvent, onButton)
  170. interactor.AddObserver(vtkCommand.LeftButtonReleaseEvent, onButton)
  171. interactor.AddObserver(vtkCommand.MouseMoveEvent, onMovement)
  172. interactor.Start()
  173. rw = interactor.GetRenderWindow()
  174. baseline = 'baselineFilename'
  175. if 'filename' in kwargs:
  176. # Render an image and save it to the given filename
  177. w2if = vtkWindowToImageFilter()
  178. w2if.ReadFrontBufferOff()
  179. w2if.SetInput(rw)
  180. w2if.Update()
  181. baselineWithPath = kwargs['filename']
  182. baseline = os.path.split(baselineWithPath)[-1]
  183. pngw = vtkPNGWriter()
  184. pngw.SetFileName(baselineWithPath)
  185. pngw.SetInputConnection(w2if.GetOutputPort())
  186. try:
  187. pngw.Write()
  188. except RuntimeError:
  189. w2if.ReadFrontBufferOn()
  190. pngw.Write()
  191. rsz = rw.GetSize()
  192. rrc = rw.GetRenderers()
  193. rrs = [rrc.GetItemAsObject(i) for i in range(rrc.GetNumberOfItems())]
  194. eye = [0,0,1]
  195. aim = [0,0,0]
  196. up = [0,1,0]
  197. if len(rrs) > 0:
  198. cam = rrs[0].GetActiveCamera()
  199. eye = cam.GetPosition()
  200. aim = cam.GetFocalPoint()
  201. up = cam.GetViewUp()
  202. print("""
  203. Replace prepareTestImage() in your script with the following to make a test:
  204. camera.SetPosition({eye[0]}, {eye[1]}, {eye[2]})
  205. camera.SetFocalPoint({aim[0]}, {aim[1]}, {aim[2]})
  206. camera.SetViewUp({up[0]}, {up[1]}, {up[2]})
  207. renwin.SetSize({rsz[0]}, {rsz[1]})
  208. self.assertImageMatch(renwin, '{baseline}')
  209. Be sure that "renwin" and "camera" are valid variables (or rename them in the
  210. snippet above) referencing the vtkRenderWindow and vtkCamera, respectively.
  211. """.format(eye=eye, aim=aim, up=up, rsz=rsz, baseline=baseline))
  212. return events
  213. def assertImageMatch(self, renwin, baseline, **kwargs):
  214. """Throw an error if a rendering in the render window does not match the baseline image.
  215. This method accepts a threshold keyword argument (with a default of 0.15)
  216. that specifies how different a baseline may be before causing a failure.
  217. """
  218. absoluteBaseline = baseline
  219. try:
  220. open(absoluteBaseline, 'r')
  221. except:
  222. absoluteBaseline = getAbsImagePath(baseline)
  223. compareImage(renwin, absoluteBaseline, **kwargs)
  224. def interact():
  225. """Interacts with the user if necessary. """
  226. global _INTERACT
  227. if _INTERACT:
  228. raw_input("\nPress Enter/Return to continue with the testing. --> ")
  229. def isInteractive():
  230. """Returns if the currently chosen mode is interactive or not
  231. based on command line options."""
  232. return _INTERACT
  233. def getAbsImagePath(img_basename):
  234. """Returns the full path to the image given the basic image
  235. name."""
  236. global VTK_BASELINE_ROOT
  237. return os.path.join(VTK_BASELINE_ROOT, img_basename)
  238. def _getTempImagePath(img_fname):
  239. x = os.path.join(VTK_TEMP_DIR, os.path.split(img_fname)[1])
  240. return os.path.abspath(x)
  241. def compareImageWithSavedImage(src_img, img_fname, threshold=0.15):
  242. """Compares a source image (src_img, which is a vtkImageData) with
  243. the saved image file whose name is given in the second argument.
  244. If the image file does not exist the image is generated and
  245. stored. If not the source image is compared to that of the
  246. figure. This function also handles multiple images and finds the
  247. best matching image.
  248. """
  249. global _NO_IMAGE
  250. if _NO_IMAGE:
  251. return
  252. f_base, f_ext = os.path.splitext(img_fname)
  253. if not os.path.isfile(img_fname):
  254. # generate the image
  255. pngw = vtkPNGWriter()
  256. pngw.SetFileName(_getTempImagePath(img_fname))
  257. pngw.SetInputConnection(src_img.GetOutputPort())
  258. pngw.Write()
  259. _printCDashImageNotFoundError(img_fname)
  260. msg = "Missing baseline image: " + img_fname + "\nTest image created: " + _getTempImagePath(img_fname)
  261. sys.tracebacklimit = 0
  262. raise RuntimeError(msg)
  263. pngr = vtkPNGReader()
  264. pngr.SetFileName(img_fname)
  265. pngr.Update()
  266. idiff = vtkImageDifference()
  267. idiff.SetInputConnection(src_img.GetOutputPort())
  268. idiff.SetImageConnection(pngr.GetOutputPort())
  269. idiff.Update()
  270. min_err = idiff.GetThresholdedError()
  271. img_err = min_err
  272. err_index = 0
  273. count = 0
  274. if min_err > threshold:
  275. count = 1
  276. test_failed = 1
  277. err_index = -1
  278. while 1: # keep trying images till we get the best match.
  279. new_fname = f_base + "_%d.png"%count
  280. if not os.path.exists(new_fname):
  281. # no other image exists.
  282. break
  283. # since file exists check if it matches.
  284. pngr.SetFileName(new_fname)
  285. pngr.Update()
  286. idiff.Update()
  287. alt_err = idiff.GetThresholdedError()
  288. if alt_err < threshold:
  289. # matched,
  290. err_index = count
  291. test_failed = 0
  292. min_err = alt_err
  293. img_err = alt_err
  294. break
  295. else:
  296. if alt_err < min_err:
  297. # image is a better match.
  298. err_index = count
  299. min_err = alt_err
  300. img_err = alt_err
  301. count = count + 1
  302. # closes while loop.
  303. if test_failed:
  304. _handleFailedImage(idiff, pngr, img_fname)
  305. # Print for CDash.
  306. _printCDashImageError(img_err, err_index, f_base)
  307. msg = "Failed image test: %f\n"%idiff.GetThresholdedError()
  308. sys.tracebacklimit = 0
  309. raise RuntimeError(msg)
  310. # output the image error even if a test passed
  311. _printCDashImageSuccess(img_err, err_index)
  312. def compareImage(renwin, img_fname, threshold=0.15):
  313. """Compares renwin's (a vtkRenderWindow) contents with the image
  314. file whose name is given in the second argument. If the image
  315. file does not exist the image is generated and stored. If not the
  316. image in the render window is compared to that of the figure.
  317. This function also handles multiple images and finds the best
  318. matching image. """
  319. global _NO_IMAGE
  320. if _NO_IMAGE:
  321. return
  322. w2if = vtkWindowToImageFilter()
  323. w2if.ReadFrontBufferOff()
  324. w2if.SetInput(renwin)
  325. w2if.Update()
  326. try:
  327. compareImageWithSavedImage(w2if, img_fname, threshold)
  328. except RuntimeError:
  329. w2if.ReadFrontBufferOn()
  330. compareImageWithSavedImage(w2if, img_fname, threshold)
  331. return
  332. def _printCDashImageError(img_err, err_index, img_base):
  333. """Prints the XML data necessary for CDash."""
  334. img_base = _getTempImagePath(img_base)
  335. print("Failed image test with error: %f"%img_err)
  336. print("<DartMeasurement name=\"ImageError\" type=\"numeric/double\"> "
  337. "%f </DartMeasurement>"%img_err)
  338. if err_index <= 0:
  339. print("<DartMeasurement name=\"BaselineImage\" type=\"text/string\">Standard</DartMeasurement>")
  340. else:
  341. print("<DartMeasurement name=\"BaselineImage\" type=\"numeric/integer\"> "
  342. "%d </DartMeasurement>"%err_index)
  343. print("<DartMeasurementFile name=\"TestImage\" type=\"image/png\"> "
  344. "%s </DartMeasurementFile>"%(img_base + '.png'))
  345. print("<DartMeasurementFile name=\"DifferenceImage\" type=\"image/png\"> "
  346. "%s </DartMeasurementFile>"%(img_base + '.diff.png'))
  347. print("<DartMeasurementFile name=\"ValidImage\" type=\"image/png\"> "
  348. "%s </DartMeasurementFile>"%(img_base + '.valid.png'))
  349. def _printCDashImageNotFoundError(img_fname):
  350. """Prints the XML data necessary for Dart when the baseline image is not found."""
  351. print("<DartMeasurement name=\"ImageNotFound\" type=\"text/string\">" + img_fname + "</DartMeasurement>")
  352. def _printCDashImageSuccess(img_err, err_index):
  353. "Prints XML data for Dart when image test succeeded."
  354. print("<DartMeasurement name=\"ImageError\" type=\"numeric/double\"> "
  355. "%f </DartMeasurement>"%img_err)
  356. if err_index <= 0:
  357. print("<DartMeasurement name=\"BaselineImage\" type=\"text/string\">Standard</DartMeasurement>")
  358. else:
  359. print("<DartMeasurement name=\"BaselineImage\" type=\"numeric/integer\"> "
  360. "%d </DartMeasurement>"%err_index)
  361. def _handleFailedImage(idiff, pngr, img_fname):
  362. """Writes all the necessary images when an image comparison
  363. failed."""
  364. f_base, f_ext = os.path.splitext(img_fname)
  365. # write the difference image gamma adjusted for the dashboard.
  366. gamma = vtkImageShiftScale()
  367. gamma.SetInputConnection(idiff.GetOutputPort())
  368. gamma.SetShift(0)
  369. gamma.SetScale(10)
  370. pngw = vtkPNGWriter()
  371. pngw.SetFileName(_getTempImagePath(f_base + ".diff.png"))
  372. pngw.SetInputConnection(gamma.GetOutputPort())
  373. pngw.Write()
  374. # Write out the image that was generated. Write it out as full so that
  375. # it may be used as a baseline image if the tester deems it valid.
  376. pngw.SetInputConnection(idiff.GetInputConnection(0,0))
  377. pngw.SetFileName(_getTempImagePath(f_base + ".png"))
  378. pngw.Write()
  379. # write out the valid image that matched.
  380. pngw.SetInputConnection(idiff.GetInputConnection(1,0))
  381. pngw.SetFileName(_getTempImagePath(f_base + ".valid.png"))
  382. pngw.Write()
  383. def main(cases):
  384. """ Pass a list of tuples containing test classes and the starting
  385. string of the functions used for testing.
  386. Example:
  387. main ([(vtkTestClass, 'test'), (vtkTestClass1, 'test')])
  388. """
  389. processCmdLine()
  390. timer = vtkTimerLog()
  391. s_time = timer.GetCPUTime()
  392. s_wall_time = time.time()
  393. # run the tests
  394. result = test(cases)
  395. tot_time = timer.GetCPUTime() - s_time
  396. tot_wall_time = float(time.time() - s_wall_time)
  397. # output measurements for CDash
  398. print("<DartMeasurement name=\"WallTime\" type=\"numeric/double\"> "
  399. " %f </DartMeasurement>"%tot_wall_time)
  400. print("<DartMeasurement name=\"CPUTime\" type=\"numeric/double\"> "
  401. " %f </DartMeasurement>"%tot_time)
  402. # Delete these to eliminate debug leaks warnings.
  403. del cases, timer
  404. if result.wasSuccessful():
  405. sys.exit(0)
  406. else:
  407. sys.exit(1)
  408. def test(cases):
  409. """ Pass a list of tuples containing test classes and the
  410. functions used for testing.
  411. It returns a unittest._TextTestResult object.
  412. Example:
  413. test = test_suite([(vtkTestClass, 'test'),
  414. (vtkTestClass1, 'test')])
  415. """
  416. # Make the test suites from the arguments.
  417. suites = []
  418. for case in cases:
  419. suites.append(unittest.makeSuite(case[0], case[1]))
  420. test_suite = unittest.TestSuite(suites)
  421. # Now run the tests.
  422. runner = unittest.TextTestRunner(verbosity=_VERBOSE)
  423. result = runner.run(test_suite)
  424. return result
  425. def usage():
  426. msg="""Usage:\nTestScript.py [options]\nWhere options are:\n
  427. -D /path/to/VTKData
  428. --data-dir /path/to/VTKData
  429. Directory containing VTK Data use for tests. If this option
  430. is not set via the command line the environment variable
  431. VTK_DATA_ROOT is used. If the environment variable is not
  432. set the value defaults to '../../../../../VTKData'.
  433. -B /path/to/valid/image_dir/
  434. --baseline-root /path/to/valid/image_dir/
  435. This is a path to the directory containing the valid images
  436. for comparison. If this option is not set via the command
  437. line the environment variable VTK_BASELINE_ROOT is used. If
  438. the environment variable is not set the value defaults to
  439. the same value set for -D (--data-dir).
  440. -T /path/to/valid/temporary_dir/
  441. --temp-dir /path/to/valid/temporary_dir/
  442. This is a path to the directory where the image differences
  443. are written. If this option is not set via the command line
  444. the environment variable VTK_TEMP_DIR is used. If the
  445. environment variable is not set the value defaults to
  446. '../../../../Testing/Temporary'.
  447. -V /path/to/validated/output.png
  448. --validated-output /path/to/valid/output.png
  449. This is a path to a file (usually but not always an image)
  450. which is compared to data generated by the test.
  451. -v level
  452. --verbose level
  453. Sets the verbosity of the test runner. Valid values are 0,
  454. 1, and 2 in increasing order of verbosity.
  455. -I
  456. --interact
  457. Interacts with the user when chosen. If this is not chosen
  458. the test will run and exit as soon as it is finished. When
  459. enabled, the behavior of this is rather trivial and works
  460. best when the test uses Tkinter.
  461. -n
  462. --no-image
  463. Does not do any image comparisons. This is useful if you
  464. want to run the test and not worry about test images or
  465. image failures etc.
  466. -h
  467. --help
  468. Prints this message.
  469. """
  470. return msg
  471. def parseCmdLine():
  472. arguments = sys.argv[1:]
  473. options = "B:D:T:V:v:hnI"
  474. long_options = ['baseline-root=', 'data-dir=', 'temp-dir=',
  475. 'validated-output=', 'verbose=', 'help',
  476. 'no-image', 'interact']
  477. try:
  478. opts, args = getopt.getopt(arguments, options, long_options)
  479. except getopt.error as msg:
  480. print(usage())
  481. print('-'*70)
  482. print(msg)
  483. sys.exit (1)
  484. return opts, args
  485. def processCmdLine():
  486. opts, args = parseCmdLine()
  487. global VTK_DATA_ROOT, VTK_BASELINE_ROOT, VTK_TEMP_DIR, VTK_BASELINE_PATHS
  488. global _VERBOSE, _NO_IMAGE, _INTERACT
  489. # setup defaults
  490. try:
  491. VTK_DATA_ROOT = os.environ['VTK_DATA_ROOT']
  492. except KeyError:
  493. VTK_DATA_ROOT = os.path.normpath("../../../../../VTKData")
  494. try:
  495. VTK_BASELINE_ROOT = os.environ['VTK_BASELINE_ROOT']
  496. except KeyError:
  497. pass
  498. try:
  499. VTK_TEMP_DIR = os.environ['VTK_TEMP_DIR']
  500. except KeyError:
  501. VTK_TEMP_DIR = os.path.normpath("../../../../Testing/Temporary")
  502. for o, a in opts:
  503. if o in ('-D', '--data-dir'):
  504. oa = os.path.abspath(a)
  505. if os.path.isfile(oa):
  506. VTK_DATA_PATHS.append(oa)
  507. else:
  508. VTK_DATA_ROOT = oa
  509. if o in ('-B', '--baseline-root'):
  510. VTK_BASELINE_ROOT = os.path.abspath(a)
  511. if o in ('-T', '--temp-dir'):
  512. VTK_TEMP_DIR = os.path.abspath(a)
  513. if o in ('-V', '--validated-output'):
  514. VTK_BASELINE_PATHS.append(os.path.abspath(a))
  515. if o in ('-n', '--no-image'):
  516. _NO_IMAGE = 1
  517. if o in ('-I', '--interact'):
  518. _INTERACT = 1
  519. if o in ('-v', '--verbose'):
  520. try:
  521. _VERBOSE = int(a)
  522. except:
  523. msg="Verbosity should be an integer. 0, 1, 2 are valid."
  524. print(msg)
  525. sys.exit(1)
  526. if o in ('-h', '--help'):
  527. print(usage())
  528. sys.exit()
  529. if not VTK_BASELINE_ROOT: # default value.
  530. VTK_BASELINE_ROOT = VTK_DATA_ROOT
  531. if __name__ == "__main__":
  532. ######################################################################
  533. # A Trivial test case to illustrate how this module works.
  534. class SampleTest(vtkTest):
  535. from vtkmodules.vtkRenderingCore import vtkActor
  536. obj = vtkActor()
  537. def testParse(self):
  538. "Test if class is parseable"
  539. self._testParse(self.obj)
  540. def testGetSet(self):
  541. "Testing Get/Set methods"
  542. self._testGetSet(self.obj)
  543. def testBoolean(self):
  544. "Testing Boolean methods"
  545. self._testBoolean(self.obj)
  546. # Test with the above trivial sample test.
  547. main( [ (SampleTest, 'test') ] )