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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 637 - (show annotations)
Thu Mar 23 10:55:31 2006 UTC (14 years, 8 months ago) by gross
File MIME type: text/x-python
File size: 6521 byte(s)
more copyright statements added
1 """
2 Class and functions for testing the Scene class
3
4 @var __author__: name of author
5 @var __license__: licence agreement
6 @var __copyright__: copyrights
7 @var __url__: url entry point on documentation
8 @var __version__: version
9 @var __date__: date of the version
10 """
11
12 __copyright__=""" Copyright (c) 2006 by ACcESS MNRF
13 http://www.access.edu.au
14 Primary Business: Queensland, Australia"""
15 __license__="""Licensed under the Open Software License version 3.0
16 http://www.opensource.org/licenses/osl-3.0.php"""
17 __author__="Paul Cochrane"
18 __url__="http://www.iservo.edu.au/esys"
19 __version__="$Revision$"
20 __date__="$Date$"
21
22
23 import unittest
24 import sys,os,string
25 here = os.getcwd() + '/../../'
26 sys.path.append(here)
27 import pyvisi # this should import all of the pyvisi stuff needed
28
29
30 class TestScene(unittest.TestCase):
31 """
32 The main test class
33 """
34
35 def setUp(self):
36 self.scene = pyvisi.Scene()
37
38 def testInit(self):
39 """
40 Check initialisation
41 """
42 # check that we get a Scene object
43 classStr = self.scene.__class__.__name__
44 self.assertEqual('Scene', classStr)
45
46 # check default values of xSize and ySize
47 self.assertEqual(640, self.scene.xSize)
48 self.assertEqual(480, self.scene.ySize)
49
50 # check that we get a renderer
51 classStr = self.scene.renderer.__class__.__name__
52 self.assertEqual('Renderer', classStr)
53
54 def testAdd(self):
55 """
56 Test adding an item to the scene
57 """
58 # if no object passed, should barf with TypeError, or ValueError
59 self.assertRaises((TypeError,ValueError), self.scene.add)
60
61 # calling this at the base level should fail
62 self.assertRaises(NotImplementedError, self.scene.add, "")
63
64 def testDelete(self):
65 """
66 Test deleting an item from the scene
67 """
68 # if no object passed, should barf with TypeError, or ValueError
69 self.assertRaises((TypeError,ValueError), self.scene.delete)
70
71 # calling this at the base level should fail
72 self.assertRaises(NotImplementedError, self.scene.delete, "")
73
74 def testPlace(self):
75 """
76 Test placing an item within the scene
77 """
78 # if no object passed, should barf with TypeError, or ValueError
79 self.assertRaises((TypeError,ValueError), self.scene.place)
80
81 # calling this at the base level should fail
82 self.assertRaises(NotImplementedError, self.scene.place, "")
83
84 def testRenderArguments(self):
85 """
86 Test the arguments passed to the render method
87 """
88 self.assertRaises(ValueError, self.scene.render, pause="")
89 self.assertRaises(ValueError, self.scene.render, interactive="")
90
91 def testSaveArguments(self):
92 """
93 Test the arguments passed to the save method
94 """
95 self.assertRaises(TypeError, self.scene.save)
96 self.assertRaises(ValueError, self.scene.save, fname="", format="")
97 self.assertRaises((TypeError, ValueError), self.scene.save, fname="")
98 self.assertRaises((TypeError, ValueError), self.scene.save, format="")
99 self.assertRaises((TypeError, ValueError), \
100 self.scene.save, fname="moo.file")
101 self.assertRaises((TypeError, ValueError), \
102 self.scene.save, format="myformat")
103
104 # need to barf if this method is used from the base pyvisi class
105 self.assertRaises(NotImplementedError, \
106 self.scene.save, fname="moo.file", format="myformat")
107
108 def testSetBackgroundColor(self):
109 """
110 Test setting the scene's background colour
111 """
112 self.assertRaises(NotImplementedError, self.scene.setBackgroundColor)
113
114 def testGetBackgroundColor(self):
115 """
116 Test getting the scene's background colour
117 """
118 self.assertRaises(NotImplementedError, self.scene.getBackgroundColor)
119
120 def testGetSize(self):
121 """
122 Test getting the size of the scene dimensions
123 """
124 self.assertEqual((640,480), self.scene.getSize())
125
126 def testSetSize(self):
127 """
128 Test setting the size of the scene dimensions
129 """
130 self.scene.setSize(123, 456)
131 self.assertEqual((123, 456), self.scene.getSize())
132
133 def testRendererCommand(self):
134 """
135 Test the renderer command
136 """
137 inCommand = "mooo"
138 outCommand = inCommand + '\n'
139 self.scene.rendererCommand(inCommand)
140 self.assertEqual(self.scene.renderer.getEvalStack(), outCommand)
141
142 def testExactlyNoArguments(self):
143 """
144 Test methods that do not take an argument at all
145 """
146 self.assertRaises(TypeError, self.scene.getBackgroundColor, "")
147 self.assertRaises(TypeError, self.scene.getSize, "")
148
149 def testExactlyOneArgument(self):
150 """
151 Test methods that take exactly one argument
152 """
153 self.assertRaises(TypeError, self.scene.add)
154 self.assertRaises(TypeError, self.scene.add, "", "")
155 self.assertRaises(TypeError, self.scene.delete)
156 self.assertRaises(TypeError, self.scene.delete, "", "")
157 self.assertRaises(TypeError, self.scene.place)
158 self.assertRaises(TypeError, self.scene.place, "", "")
159 self.assertRaises(TypeError, self.scene.rendererCommand)
160 self.assertRaises(TypeError, self.scene.rendererCommand, "", "")
161
162 def testExactlyTwoArguments(self):
163 """
164 Test methods that take exactly two arguments
165 """
166 # scene.setSize()
167 self.assertRaises(TypeError, self.scene.setSize)
168 self.assertRaises(TypeError, self.scene.setSize, 1)
169 self.assertRaises(TypeError, self.scene.setSize, 1, 2, 3)
170
171 # scene.save()
172 self.assertRaises(TypeError, self.scene.save)
173 self.assertRaises(TypeError, self.scene.save, "1")
174 self.assertRaises(TypeError, self.scene.save, "1", "2", "3")
175
176 def testIntegerArguments(self):
177 """
178 Test methods that take integer arguments
179 """
180 self.assertRaises(AssertionError, self.scene.setSize, "moo", "baa")
181
182 def testStringArguments(self):
183 """
184 Test methods that take string arguments
185 """
186 self.assertRaises(AssertionError, self.scene.save, 1, 2)
187 self.assertRaises(AssertionError, self.scene.rendererCommand, 1)
188
189 if __name__ == '__main__':
190 unittest.main()
191
192 # vim: expandtab shiftwidth=4:

  ViewVC Help
Powered by ViewVC 1.1.26