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

Contents of /trunk/pyvisi/test/python/run_light.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: 3052 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, Light, GlobalPosition, Map
2 from esys.pyvisi.constant import *
3 import unittest, os
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_LIGHT_IMAGES_PATH = os.path.join(PYVISI_WORKDIR, \
17 "data_sample_images", "light")
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 TestLight:
27 def render(self, file):
28 self.scene.render(image_name = \
29 os.path.join(PYVISI_TEST_LIGHT_IMAGES_PATH, file))
30
31 self.failUnless(os.stat(os.path.join(PYVISI_TEST_LIGHT_IMAGES_PATH, \
32 file))[ST_SIZE] > MIN_IMAGE_SIZE)
33
34 class TestLight2D(unittest.TestCase, TestLight):
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.light = Light(scene = self.scene,
50 viewport = Viewport.SOUTH_WEST)
51
52 def tearDown(self):
53 del self.scene
54 del self.data_collector
55 del self.map
56 del self.light
57
58 def test2D(self):
59 self.light.setColor(Color.BLUE)
60 self.light.setFocalPoint(GlobalPosition(0.2, 1, 0.4))
61 self.light.setPosition(GlobalPosition(0.2, 1, 5))
62 self.light.setIntensity(2)
63 self.render("TestLight2D_test2D.jpg")
64
65 class TestLight3D(unittest.TestCase, TestLight):
66 def setUp(self):
67 self.scene = \
68 Scene(renderer = JPG_RENDERER, num_viewport = 1,
69 x_size = X_SIZE, y_size = Y_SIZE)
70
71 self.data_collector = DataCollector(source = Source.XML)
72 self.data_collector.setFileName(file_name = \
73 os.path.join(PYVISI_TEST_MESHES_PATH, FILE_3D))
74
75 self.map = Map(scene = self.scene,
76 data_collector = self.data_collector,
77 viewport = Viewport.SOUTH_WEST, lut = Lut.COLOR,
78 cell_to_point = False, outline = True)
79
80 self.light = Light(scene = self.scene,
81 viewport = Viewport.SOUTH_WEST)
82
83 def tearDown(self):
84 del self.scene
85 del self.data_collector
86 del self.map
87 del self.light
88
89 def test3D(self):
90 self.light.setColor(Color.RED)
91 self.light.setAngle(20, 50)
92 self.light.setIntensity(1)
93 self.render("TestLight3D_test3D.jpg")
94
95
96 ##############################################################################
97
98
99 if __name__ == '__main__':
100 suite = unittest.TestSuite()
101 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestLight2D))
102 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestLight3D))
103 s=unittest.TextTestRunner(verbosity=2).run(suite)
104 if not s.wasSuccessful(): sys.exit(1)
105

  ViewVC Help
Powered by ViewVC 1.1.26