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

Contents of /trunk/pyvisi/test/python/run_map_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: 7159 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 # Import the necessary modules
2 from esys.pyvisi import DataCollector, Scene, Map, MapOnPlaneCut, MapOnPlaneClip
3 from esys.pyvisi import Camera, MapOnScalarClip, MapOnScalarClipWithRotation
4 from esys.pyvisi.constant import *
5 import unittest, os
6 from stat import ST_SIZE
7
8 try:
9 PYVISI_WORKDIR=os.environ['PYVISI_WORKDIR']
10 except KeyError:
11 PYVISI_WORKDIR='.'
12 try:
13 PYVISI_TEST_DATA_ROOT=os.environ['PYVISI_TEST_DATA_ROOT']
14 except KeyError:
15 PYVISI_TEST_DATA_ROOT='.'
16
17 PYVISI_TEST_MESHES_PATH = os.path.join(PYVISI_TEST_DATA_ROOT, "data_meshes")
18 PYVISI_TEST_MAP_IMAGES_PATH = os.path.join(PYVISI_WORKDIR, \
19 "data_sample_images", "map")
20
21 MIN_IMAGE_SIZE = 100
22 FILE_3D_1 = "results.xml"
23 FILE_3D_2 = "interior_3D.xml"
24 FILE_2D_ROTATION = "without_st.0700.xml"
25 X_SIZE = 400
26 Y_SIZE = 400
27
28 JPG_RENDERER = Renderer.OFFLINE_JPG
29 SCALAR_FIELD_POINT_DATA_1 = "scalar1"
30 SCALAR_FIELD_POINT_DATA_2 = "scalar2"
31
32 class TestMapWithLazyEvaluation:
33 def render(self, file):
34 self.scene.render(image_name = \
35 os.path.join(PYVISI_TEST_MAP_IMAGES_PATH, file))
36
37 self.failUnless(os.stat(os.path.join(PYVISI_TEST_MAP_IMAGES_PATH, \
38 file))[ST_SIZE] > MIN_IMAGE_SIZE)
39
40 class TestMapLazy(unittest.TestCase, TestMapWithLazyEvaluation):
41 def tearDown(self):
42 del self.scene
43
44 def testMapLazy(self):
45
46 # Create a scene with four viewports.
47 s = Scene(renderer = JPG_RENDERER, num_viewport = 4, x_size = X_SIZE,
48 y_size = Y_SIZE)
49 self.scene = s
50
51 dc1 = DataCollector(source = Source.XML)
52 dc1.setActiveScalar(scalar = SCALAR_FIELD_POINT_DATA_1)
53
54 dc2 = DataCollector(source = Source.XML)
55 dc2.setFileName(file_name = os.path.join(PYVISI_TEST_MESHES_PATH, \
56 FILE_3D_1))
57 dc2.setActiveScalar(scalar = SCALAR_FIELD_POINT_DATA_2)
58
59 # Create a map instance for the first viewport.
60 m1 = Map(scene = s, data_collector = dc1,
61 viewport = Viewport.SOUTH_WEST, lut = Lut.COLOR, outline = True)
62
63 # Create a map instance for the second viewport.
64 m2 = Map(scene = s, data_collector = dc2,
65 viewport = Viewport.NORTH_WEST, lut = Lut.COLOR, outline = True)
66 m2.setColor(color = Color.BLUE)
67
68 # Create a map instance for the third viewport.
69 m3 = Map(scene = s, data_collector = dc1,
70 viewport = Viewport.NORTH_EAST, lut = Lut.COLOR, outline = True)
71
72 # Create a map instance the fourth viewport.
73 m4 = Map(scene = s, data_collector = dc2,
74 viewport = Viewport.SOUTH_EAST, lut = Lut.COLOR, outline = True)
75
76 dc1.setFileName(file_name = os.path.join(PYVISI_TEST_MESHES_PATH, \
77 FILE_3D_1))
78 m1.setRepresentationToWireframe()
79 m4.setOpacity(opacity = 0.5)
80
81 self.render("TestMapWithLazyEvaluation.jpg")
82
83 class TestMapOnPlaneCutLazy(unittest.TestCase, TestMapWithLazyEvaluation):
84 def tearDown(self):
85 del self.scene
86
87 def testMapOnPlaneCutLazy(self):
88 s = Scene(renderer = JPG_RENDERER, num_viewport = 4, x_size = X_SIZE,
89 y_size = Y_SIZE)
90 self.scene = s
91
92 # Create two data collector instances for two different sources.
93 dc1 = DataCollector(source = Source.XML)
94
95 # Create a map on plane cut instance for the first viewport.
96 mopc1 = MapOnPlaneCut(scene = s, data_collector = dc1,
97 viewport = Viewport.SOUTH_WEST)
98 mopc1.setPlaneToYZ(offset = 1.5)
99
100 c1 = Camera(scene = s, viewport = Viewport.SOUTH_WEST)
101 c1.isometricView()
102
103 # Create three map on plane cut instances for the second viewport.
104 mopc2_1 = MapOnPlaneCut(scene = s, data_collector = dc1,
105 viewport = Viewport.NORTH_WEST)
106
107 mopc2_2 = MapOnPlaneCut(scene = s, data_collector = dc1,
108 viewport = Viewport.NORTH_WEST)
109
110 mopc2_3 = MapOnPlaneCut(scene = s, data_collector = dc1,
111 viewport = Viewport.NORTH_WEST)
112 mopc2_3.setPlaneToXY()
113 mopc2_3.translate(0,0,0.5)
114
115 c2 = Camera(scene = s, viewport = Viewport.NORTH_WEST)
116 c2.isometricView()
117
118 mopc2_1.setPlaneToYZ(offset = 1.5)
119 mopc2_2.setPlaneToXZ(offset = 1.5)
120 dc1.setFileName(file_name = os.path.join(PYVISI_TEST_MESHES_PATH, \
121 FILE_3D_2))
122
123 self.render("TestMapOnPlaneCutWithLazyEvaluation.jpg")
124
125
126 class TestMapOnPlaneClipLazy(unittest.TestCase, TestMapWithLazyEvaluation):
127 def tearDown(self):
128 del self.scene
129
130 def testMapOnPlaneClipLazy(self):
131 s = Scene(renderer = JPG_RENDERER, num_viewport = 1, x_size = X_SIZE,
132 y_size = Y_SIZE)
133 self.scene = s
134
135 dc1 = DataCollector(source = Source.XML)
136
137 # Create three map on clip instances.
138 mopc1_1 = MapOnPlaneClip(scene = s, data_collector = dc1,
139 viewport = Viewport.SOUTH_WEST)
140 mopc1_1.setPlaneToXY()
141 mopc1_1.rotateX(angle = 5)
142
143 mopc1_2 = MapOnPlaneClip(scene = s, data_collector = dc1,
144 viewport = Viewport.SOUTH_WEST)
145
146 mopc1_3 = MapOnPlaneClip(scene = s, data_collector = dc1,
147 viewport = Viewport.SOUTH_WEST)
148 mopc1_3.setPlaneToXZ()
149 mopc1_3.rotateX(angle = -40)
150 mopc1_3.translate(x_offset = 0, y_offset = 2.2, z_offset = 0)
151
152 c1 = Camera(scene = s, viewport = Viewport.SOUTH_WEST)
153 c1.isometricView()
154
155 mopc1_2.setPlaneToYZ(offset = 2.5)
156 mopc1_2.setOpacity(opacity = 0.5)
157 dc1.setFileName(file_name = os.path.join(PYVISI_TEST_MESHES_PATH, \
158 FILE_3D_2))
159
160 self.render("TestMapOnPlaneClipWithLazyEvaluation.jpg")
161
162
163 class TestMapOnScalarClipLazy(unittest.TestCase, TestMapWithLazyEvaluation):
164 def tearDown(self):
165 del self.scene
166
167 def testMapOnScalarClipLazy(self):
168 s = Scene(renderer = JPG_RENDERER, num_viewport = 1, x_size = X_SIZE,
169 y_size = Y_SIZE)
170 self.scene = s
171
172 dc1 = DataCollector(source = Source.XML)
173
174 # Create a map on scalar clip instance.
175 mosc1_1 = MapOnScalarClip(scene = s, data_collector = dc1,
176 lut = Lut.GREY_SCALE)
177
178 c1 = Camera(scene = s, viewport = Viewport.SOUTH_WEST)
179 c1.isometricView()
180
181 dc1.setFileName(file_name = os.path.join(PYVISI_TEST_MESHES_PATH, \
182 FILE_3D_2))
183 self.render("TestMapOnScalarClipWithLazyEvaluation.jpg")
184
185 class TestMapOnScalarClipWithRotationLazy(unittest.TestCase,
186 TestMapWithLazyEvaluation):
187
188 def tearDown(self):
189 del self.scene
190
191 def testMapOnScalarClipWithRotationLazy(self):
192 s = Scene(renderer = JPG_RENDERER, num_viewport = 1, x_size = X_SIZE,
193 y_size = Y_SIZE)
194 self.scene = s
195
196 dc1 = DataCollector(source = Source.XML)
197
198 # Create a map on scalar clip instance.
199 mosc1_1 = MapOnScalarClipWithRotation(scene = s, data_collector = dc1,
200 lut = Lut.GREY_SCALE)
201 mosc1_1.setAngle(200)
202
203 c1 = Camera(scene = s, viewport = Viewport.SOUTH_WEST)
204 c1.isometricView()
205
206 dc1.setFileName(file_name = os.path.join(PYVISI_TEST_MESHES_PATH, \
207 FILE_2D_ROTATION))
208 self.render("TestMapOnScalarClipWithRotationWithLazyEvaluation.jpg")
209
210
211
212
213
214 ##############################################################################
215 if __name__ == '__main__':
216 suite = unittest.TestSuite()
217 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestMapLazy))
218 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestMapOnPlaneCutLazy))
219 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestMapOnPlaneClipLazy))
220 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestMapOnScalarClipLazy))
221 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestMapOnScalarClipWithRotationLazy))
222 s=unittest.TextTestRunner(verbosity=2).run(suite)
223 if not s.wasSuccessful(): sys.exit(1)
224

  ViewVC Help
Powered by ViewVC 1.1.26