/[escript]/trunk/pyvisi/test/python/run_contour_with_lazy_evaluation.py
ViewVC logotype

Contents of /trunk/pyvisi/test/python/run_contour_with_lazy_evaluation.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1376 - (show annotations)
Wed Jan 9 01:38:18 2008 UTC (11 years, 6 months ago) by gross
File MIME type: text/x-python
File size: 3831 byte(s)
inserted sys.exit(1) into the tests so scons can detect the failure of the test. 
A similar statement has been removed from an earlier as it produces problems on 64bit Linux. Previously exit(0) was called in case of success but now this is not done in order to avoid a fatal end of the program. in the case of an error in the test there could be a fatal error so but I guess that this not really a problem.

PS: the fact that signal 0 was returned even for the case of an error lead to the illusion that all tests have been completed successfully.


1 from esys.pyvisi import DataCollector, Scene, Contour, ContourOnPlaneCut
2 from esys.pyvisi import ContourOnPlaneClip, Camera
3 from esys.pyvisi.constant import *
4 import unittest, os
5 from stat import ST_SIZE
6
7 try:
8 PYVISI_WORKDIR=os.environ['PYVISI_WORKDIR']
9 except KeyError:
10 PYVISI_WORKDIR='.'
11 try:
12 PYVISI_TEST_DATA_ROOT=os.environ['PYVISI_TEST_DATA_ROOT']
13 except KeyError:
14 PYVISI_TEST_DATA_ROOT='.'
15
16 PYVISI_TEST_MESHES_PATH = os.path.join(PYVISI_TEST_DATA_ROOT, "data_meshes")
17 PYVISI_TEST_CONTOUR_IMAGES_PATH = os.path.join(PYVISI_WORKDIR, \
18 "data_sample_images", "contour")
19
20 MIN_IMAGE_SIZE = 100
21 FILE_3D = "interior_3D.xml"
22 X_SIZE = 400
23 Y_SIZE = 400
24 JPG_RENDERER = Renderer.OFFLINE_JPG
25
26 class TestContourWithLazyEvaluation:
27 def render(self, file):
28 self.scene.render(image_name = \
29 os.path.join(PYVISI_TEST_CONTOUR_IMAGES_PATH, file))
30
31 self.failUnless(os.stat(os.path.join(PYVISI_TEST_CONTOUR_IMAGES_PATH, \
32 file))[ST_SIZE] > MIN_IMAGE_SIZE)
33
34 class TestContourGenerate(unittest.TestCase, TestContourWithLazyEvaluation):
35 def tearDown(self):
36 del self.scene
37
38 def testContourGenerate(self):
39 s = Scene(renderer = JPG_RENDERER, num_viewport = 1, x_size = X_SIZE,
40 y_size = Y_SIZE)
41 self.scene = s
42
43 dc1 = DataCollector(source = Source.XML)
44
45 # Create one contour instance.
46 ctr1 = Contour(scene = s, data_collector = dc1,
47 viewport = Viewport.SOUTH_WEST, lut = Lut.COLOR, outline = True)
48 ctr1.generateContours(contours = 6, lower_range = 0, upper_range = 0.5)
49
50 cam1 = Camera(scene = s, viewport = Viewport.SOUTH_WEST)
51 cam1.elevation(angle = -40)
52
53 dc1.setFileName(file_name = os.path.join(PYVISI_TEST_MESHES_PATH, \
54 FILE_3D))
55 self.render("TestContourWithLazyEvaluation.jpg")
56
57
58 class TestContourOnPlaneCut(unittest.TestCase, TestContourWithLazyEvaluation):
59 def tearDown(self):
60 del self.scene
61
62 def testContourOnPlaneCut(self):
63 s = Scene(renderer = JPG_RENDERER, num_viewport = 1, x_size = X_SIZE,
64 y_size = Y_SIZE)
65 self.scene = s
66
67 dc1 = DataCollector(source = Source.XML)
68
69 # Create one contour on plane cut instance.
70 ctropc1 = ContourOnPlaneCut(scene = s, data_collector = dc1,
71 viewport = Viewport.SOUTH_WEST, lut = Lut.COLOR, outline = True)
72 ctropc1.setPlaneToXY(offset = 0.2)
73
74 c1 = Camera(scene = s, viewport = Viewport.SOUTH_WEST)
75 c1.elevation(angle = -45)
76
77 dc1.setFileName(file_name = os.path.join(PYVISI_TEST_MESHES_PATH, \
78 FILE_3D))
79 ctropc1.generateContours(contours = 8)
80
81 self.render("TestContourOnPlaneCutWithLazyEvaluation.jpg")
82
83 class TestContourOnPlaneClip(unittest.TestCase, TestContourWithLazyEvaluation):
84 def tearDown(self):
85 del self.scene
86
87 def testContourOnPlaneClip(self):
88 s = Scene(renderer = JPG_RENDERER, num_viewport = 1, x_size = X_SIZE,
89 y_size = Y_SIZE)
90 self.scene = s
91
92 dc1 = DataCollector(source = Source.XML)
93
94 # Create one contour on plance clip instance.
95 ctropc1 = ContourOnPlaneClip(scene = s, data_collector = dc1,
96 viewport = Viewport.SOUTH_WEST, lut = Lut.COLOR,
97 outline = True)
98 ctropc1.setPlaneToXY()
99 ctropc1.rotateY(angle = 10)
100 ctropc1.generateContours(contours = 8)
101
102 c1 = Camera(scene = s, viewport = Viewport.SOUTH_WEST)
103 c1.elevation(angle = -40)
104
105 dc1.setFileName(file_name = os.path.join(PYVISI_TEST_MESHES_PATH,
106 FILE_3D))
107 self.render("TestContourOnPlaneClipWithLazyEvaluation.jpg")
108
109
110 ##############################################################################
111
112
113 if __name__ == '__main__':
114 suite = unittest.TestSuite()
115 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestContourGenerate))
116 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestContourOnPlaneCut))
117 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestContourOnPlaneClip))
118 s=unittest.TextTestRunner(verbosity=2).run(suite)
119 if not s.wasSuccessful(): sys.exit(1)
120

  ViewVC Help
Powered by ViewVC 1.1.26