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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2344 - (show annotations)
Mon Mar 30 02:13:58 2009 UTC (10 years, 5 months ago) by jfenwick
File MIME type: text/x-python
File size: 3403 byte(s)
Change __url__ to launchpad site

1
2 ########################################################
3 #
4 # Copyright (c) 2003-2008 by University of Queensland
5 # Earth Systems Science Computational Center (ESSCC)
6 # http://www.uq.edu.au/esscc
7 #
8 # Primary Business: Queensland, Australia
9 # Licensed under the Open Software License version 3.0
10 # http://www.opensource.org/licenses/osl-3.0.php
11 #
12 ########################################################
13
14 __copyright__="""Copyright (c) 2003-2008 by University of Queensland
15 Earth Systems Science Computational Center (ESSCC)
16 http://www.uq.edu.au/esscc
17 Primary Business: Queensland, Australia"""
18 __license__="""Licensed under the Open Software License version 3.0
19 http://www.opensource.org/licenses/osl-3.0.php"""
20 __url__="https://launchpad.net/escript-finley"
21
22 from esys.pyvisi import Scene
23 from esys.pyvisi.constant import *
24 import unittest, os, sys
25 from stat import ST_SIZE
26 from esys.escript import getMPISizeWorld
27
28 try:
29 PYVISI_WORKDIR=os.environ['PYVISI_WORKDIR']
30 except KeyError:
31 PYVISI_WORKDIR='.'
32 try:
33 PYVISI_TEST_DATA_ROOT=os.environ['PYVISI_TEST_DATA_ROOT']
34 except KeyError:
35 PYVISI_TEST_DATA_ROOT='.'
36
37 PYVISI_TEST_SCENE_IMAGES_PATH = os.path.join(PYVISI_WORKDIR, \
38 "data_sample_images", "scene")
39
40 MIN_IMAGE_SIZE = 100
41 X_SIZE = 400
42 Y_SIZE = 400
43 JPG_RENDERER = Renderer.OFFLINE_JPG
44
45 class TestScene:
46 def render(self, file):
47 self.scene.render(image_name = \
48 os.path.join(PYVISI_TEST_SCENE_IMAGES_PATH, file))
49
50 self.failUnless(os.stat(os.path.join(PYVISI_TEST_SCENE_IMAGES_PATH, \
51 file))[ST_SIZE] > MIN_IMAGE_SIZE)
52
53 def setBackground(self, c):
54 self.scene.setBackground(color = c)
55
56 class TestSceneInit(unittest.TestCase):
57 def testInit(self):
58 if getMPISizeWorld() == 1:
59 scene= Scene(renderer = JPG_RENDERER, num_viewport = 1,x_size = X_SIZE, y_size = Y_SIZE)
60 else:
61 self.failUnlessRaises(ValueError,Scene,renderer = JPG_RENDERER, num_viewport = 1,x_size = X_SIZE, y_size = Y_SIZE)
62
63
64 class TestSceneOneViewport(unittest.TestCase, TestScene):
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 def tearDown(self):
71 del self.scene
72
73 def testRender(self):
74 file = "TestSceneOneViewport_testRender.jpg"
75 self.render(file)
76
77 def testSetBackground(self):
78 self.setBackground(Color.GREEN)
79 file = "TestSceneOneViewport_testSetBackground.jpg"
80 self.render(file)
81
82 class TestSceneFourViewports(unittest.TestCase, TestScene):
83 def setUp(self):
84 self.scene = \
85 Scene(renderer = JPG_RENDERER, num_viewport = 4, x_size = 800,
86 y_size = 800)
87
88 def tearDown(self):
89 del self.scene
90
91 def testRender(self):
92 file = "TestSceneFourViewport_testRender.jpg"
93 self.render(file)
94
95
96 ###############################################################################
97
98
99 if __name__ == '__main__':
100 suite = unittest.TestSuite()
101 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestSceneInit))
102 if getMPISizeWorld() == 1:
103 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestSceneOneViewport))
104 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestSceneFourViewports))
105 else:
106 print "some tests in run_scene.py are not executed as more than one processor is used."
107 s=unittest.TextTestRunner(verbosity=2).run(suite)
108 if not s.wasSuccessful(): sys.exit(1)
109 print "all done."
110

  ViewVC Help
Powered by ViewVC 1.1.26