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

Contents of /trunk/pyvisi/test/python/run_camera.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: 3059 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, Camera, GlobalPosition, Map
2 from esys.pyvisi.constant import *
3 import unittest, os, gc
4 from stat import ST_SIZE
5
6 try:
7 PYVISI_WORKDIR=os.environ['PYVISI_WORKDIR']
8 except KeyError:
9 PYVISI_WORKDIR='.'
10 try:
11 PYVISI_TEST_DATA_ROOT=os.environ['PYVISI_TEST_DATA_ROOT']
12 except KeyError:
13 PYVISI_TEST_DATA_ROOT='.'
14
15 PYVISI_TEST_MESHES_PATH = os.path.join(PYVISI_TEST_DATA_ROOT, "data_meshes")
16 PYVISI_TEST_CAMERA_IMAGES_PATH = os.path.join(PYVISI_WORKDIR, \
17 "data_sample_images", "camera")
18
19 MIN_IMAGE_SIZE = 100
20 FILE_2D = "interior_2D.xml"
21 FILE_3D = "interior_3D.xml"
22 X_SIZE = 400
23 Y_SIZE = 400
24 JPG_RENDERER = Renderer.OFFLINE_JPG
25
26 class TestCamera:
27 def render(self, file):
28 self.scene.render(image_name = \
29 os.path.join(PYVISI_TEST_CAMERA_IMAGES_PATH, file))
30
31 self.failUnless(os.stat(os.path.join(PYVISI_TEST_CAMERA_IMAGES_PATH,\
32 file))[ST_SIZE] > MIN_IMAGE_SIZE)
33
34 class TestCamera2D(unittest.TestCase, TestCamera):
35 def setUp(self):
36 self.scene = \
37 Scene(renderer = JPG_RENDERER, num_viewport = 1,
38 x_size = X_SIZE, y_size = Y_SIZE)
39
40 self.data_collector = DataCollector(source = Source.XML)
41 self.data_collector.setFileName(file_name = \
42 os.path.join(PYVISI_TEST_MESHES_PATH, FILE_2D))
43
44 self.map = Map(scene = self.scene,
45 data_collector = self.data_collector,
46 viewport = Viewport.SOUTH_WEST, lut = Lut.COLOR,
47 cell_to_point = False, outline = True)
48
49 self.camera = Camera(scene = self.scene, viewport = Viewport.SOUTH_WEST)
50
51 def tearDown(self):
52 del self.scene
53 del self.data_collector
54 del self.map
55 del self.camera
56
57 def test2D(self):
58 self.camera.azimuth(20)
59 self.camera.elevation(40)
60 self.camera.roll(30)
61 self.camera.dolly(1.5)
62 self.render("TestCamera2D_test2D.jpg")
63
64 class TestCamera3D(unittest.TestCase, TestCamera):
65 def setUp(self):
66 self.scene = \
67 Scene(renderer = JPG_RENDERER, num_viewport = 1,
68 x_size = X_SIZE, y_size = Y_SIZE)
69
70 self.data_collector = DataCollector(source = Source.XML)
71 self.data_collector.setFileName(file_name = \
72 os.path.join(PYVISI_TEST_MESHES_PATH, FILE_3D))
73
74 self.map = Map(scene = self.scene,
75 data_collector = self.data_collector,
76 viewport = Viewport.SOUTH_WEST, lut = Lut.COLOR,
77 cell_to_point = False, outline = True)
78
79 self.camera = Camera(scene = self.scene,
80 viewport = Viewport.SOUTH_WEST)
81
82 def tearDown(self):
83 del self.scene
84 del self.data_collector
85 del self.map
86 del self.camera
87
88 def test3D(self):
89 self.camera.setFocalPoint(GlobalPosition(1, 1, 0.3))
90 self.camera.setPosition(GlobalPosition(1, 1, 7))
91 self.camera.isometricView()
92 self.render("TestCamera3D_test3D.jpg")
93
94
95 ##############################################################################
96
97
98 if __name__ == '__main__':
99 suite = unittest.TestSuite()
100 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestCamera2D))
101 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestCamera3D))
102 s=unittest.TextTestRunner(verbosity=2).run(suite)
103 if not s.wasSuccessful(): sys.exit(1)
104

  ViewVC Help
Powered by ViewVC 1.1.26