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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 696 - (show annotations)
Thu Mar 30 12:45:13 2006 UTC (14 years, 8 months ago) by gross
File MIME type: text/x-python
File size: 16052 byte(s)
pyvisi builds now
1 """
2 Class and functions for testing the pyvisi framework
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 from esys.pyvisi import * # this should import all of the pyvisi stuff needed
25
26 class TestAxes(unittest.TestCase):
27 """
28 The main test class
29 """
30
31 def testAxesBases(self):
32 bases = "%s" % Axes.__bases__
33 self.assertEqual(bases, '<class \'esys.pyvisi.scene.Plot\'>')
34
35 class TestCamera(unittest.TestCase):
36 """
37 The main test class
38 """
39
40 def testAddCamera(self):
41 scene = Scene()
42 camera = scene.addCamera()
43 self.assertEqual(camera.__class__.__name__, 'Camera')
44
45 def testOnlyOneCamera(self):
46 # there should only be one camera object
47 scene = Scene()
48 camera = scene.addCamera()
49 self.assertEqual(camera._cameraCount,1)
50 self.assertRaises(somekindoferror, scene.addCamera())
51
52
53 class TestImage(unittest.TestCase):
54 """
55 The main test class
56 """
57
58 def testExactlyOneArg(self):
59 """
60 Tests that Image class is passed exactly one argument
61 """
62 # this tests for no args passed
63 self.assertRaises(TypeError, Image.__init__)
64 # this tests for two args passed
65 self.assertRaises(TypeError, Image.__init__, 'one', 'two')
66
67 class TestItem(unittest.TestCase):
68 """
69 The main test class
70 """
71
72 def testFunction(self):
73 """
74 A test function
75 """
76 self.assertEqual()
77 self.assertRaises()
78 self.assert_()
79
80
81 class TestPlane(unittest.TestCase):
82 """
83 The main test class
84 """
85
86 def testFunction(self):
87 """
88 A test function
89 """
90 self.assertEqual()
91 self.assertRaises()
92 self.assert_()
93
94
95
96 class TestPlot(unittest.TestCase):
97 """
98 The main test class
99 """
100
101 def testArrowPlotBases(self):
102 bases = "%s" % ArrowPlot.__bases__
103 self.assertEqual(bases, '<class \'esys.pyvisi.scene.Plot\'>')
104
105 def testArrowPlotSetData(self):
106 scene = Scene()
107 plot = scene.addArrowPlot()
108 data = Finley.Brick(3,5,7).Nodes().getX() # old esys!!
109 self.assert_(plot.setData(data),msg="Failed to set data in ArrowPlot")
110
111 def testContourPlotBases(self):
112 bases = "%s" % ContourPlot.__bases__
113 self.assertEqual(bases, '<class \'esys.pyvisi.scene.Plot\'>')
114
115 def testLinePlotBases(self):
116 bases = "%s" % LinePlot.__bases__
117 self.assertEqual(bases, '<class \'esys.pyvisi.scene.Plot\'>')
118
119
120 class TestRenderer(unittest.TestCase):
121 """
122 Test the renderer object at the base esys.pyvisi level
123 """
124
125 def setUp(self):
126 self.ren = Renderer()
127
128 def testInit(self):
129 """
130 Tests initialisation of the Renderer object
131 """
132 classStr = self.ren.__class__.__name__
133 self.assertEqual('Renderer', classStr)
134
135 def testExactlyOneArgument(self):
136 """
137 Check that method only accepts one argument
138 """
139 # check setRenderWindowHeight
140 self.assertRaises(TypeError, self.ren.setRenderWindowHeight)
141 self.assertRaises(TypeError, self.ren.setRenderWindowHeight, 10, 20)
142
143 # check setRenderWindowWidth
144 self.assertRaises(TypeError, self.ren.setRenderWindowWidth)
145 self.assertRaises(TypeError, self.ren.setRenderWindowWidth, 10, 20)
146
147 # check addToEvalStack
148 self.assertRaises(TypeError, self.ren.addToEvalStack)
149 self.assertRaises(TypeError, self.ren.addToEvalStack, "moo", "baa")
150
151 # check addToInitStack
152 self.assertRaises(TypeError, self.ren.addToInitStack)
153 self.assertRaises(TypeError, self.ren.addToInitStack, "moo", "baa")
154
155 def testExactlyTwoArguments(self):
156 """
157 Check that method only accepts two arguments
158 """
159 self.assertRaises(TypeError, \
160 self.ren.setRenderWindowDimensions)
161 self.assertRaises(TypeError, \
162 self.ren.setRenderWindowDimensions, 12)
163 self.assertRaises(TypeError, \
164 self.ren.setRenderWindowDimensions, 12, 14, 16)
165
166 def testRenderWindowDefaultDims(self):
167 """
168 Check render window default width and height
169 """
170 self.assertEqual(640, self.ren.renderWindowWidth) # width
171 self.assertEqual(480, self.ren.renderWindowHeight) # height
172
173 def testGetRenderWindowWidth(self):
174 """
175 Check getting the render window width
176 """
177 width = self.ren.getRenderWindowWidth()
178 self.assertEqual(self.ren.renderWindowWidth, width)
179
180 def testSetRenderWindowWidth(self):
181 """
182 Test setting the render window width
183 """
184 width = 720
185 self.ren.setRenderWindowWidth(width)
186 self.assertEqual(self.ren.getRenderWindowWidth(), width)
187
188 def testGetRenderWindowHeight(self):
189 """
190 Check getting the render window height
191 """
192 height = self.ren.getRenderWindowHeight()
193 self.assertEqual(self.ren.renderWindowHeight, height)
194
195 def testSetRenderWindowHeight(self):
196 """
197 Test setting the render window height
198 """
199 height = 593
200 self.ren.setRenderWindowHeight(height)
201 self.assertEqual(self.ren.getRenderWindowHeight(), height)
202
203 def testGetRenderWindowDimensions(self):
204 """
205 Test getting the render window width and height
206 """
207 (width, height) = self.ren.getRenderWindowDimensions()
208 self.assertEqual((640,480), (width, height))
209
210 def testSetRenderWindowDimensions(self):
211 """
212 Test setting the render window width and height
213 """
214 width = 123
215 height = 456
216 self.ren.setRenderWindowDimensions(width, height)
217 self.assertEqual(self.ren.getRenderWindowDimensions(), (width,height))
218
219 def testIntegerArgsToSet(self):
220 """
221 Test setting of integer arguments
222 """
223 self.assertRaises(AssertionError, \
224 self.ren.setRenderWindowWidth, "moo")
225 self.assertRaises(AssertionError, \
226 self.ren.setRenderWindowHeight, "moo")
227 self.assertRaises(AssertionError, \
228 self.ren.setRenderWindowDimensions, "moo", "baa")
229
230 def testStringArgsToSet(self):
231 """
232 Test setting of string arguments
233 """
234 self.assertRaises(AssertionError, self.ren.addToEvalStack, 10)
235 self.assertRaises(AssertionError, self.ren.addToInitStack, 10)
236
237 def testGetEvalStack(self):
238 """
239 Test getting the evaluation stack
240 """
241 # it should be the null string on initialisation
242 self.assertEqual("", self.ren.getEvalStack())
243
244 def testAddToEvalStack(self):
245 """
246 Test adding a string to the evaluation stack
247 """
248 inString = "my string"
249 outString = inString + '\n'
250 self.ren.addToEvalStack(inString)
251 self.assertEqual(self.ren.getEvalStack(), outString)
252
253 def testGetInitStack(self):
254 """
255 Test getting the initialisation stack
256 """
257 # should be the null string initially
258 self.assertEqual("", self.ren.getInitStack())
259
260 def testAddToInitStack(self):
261 """
262 Test adding a string to the initialisation stack
263 """
264 inString = "my string"
265 outString = inString + '\n'
266 self.ren.addToInitStack(inString)
267 self.assertEqual(self.ren.getInitStack(), outString)
268
269 def testResetEvalStack(self):
270 """
271 Test resetting the evaluation stack
272 """
273 # set the stack to something
274 inString = "my string"
275 self.ren.addToEvalStack(inString)
276 # reset the stack
277 self.ren.resetEvalStack()
278 # now check that it's the null string again
279 self.assertEqual("", self.ren.getEvalStack())
280
281 def testResetInitStack(self):
282 """
283 Test resetting the initialisation stack
284 """
285 # set the stack to something
286 inString = "my string"
287 self.ren.addToInitStack(inString)
288 # reset the stack
289 self.ren.resetInitStack()
290 # now check that it's the null string again
291 self.assertEqual("", self.ren.getInitStack())
292
293
294 class TestScene(unittest.TestCase):
295 """
296 The main test class
297 """
298
299 def setUp(self):
300 self.scene = Scene()
301
302 def testInit(self):
303 """
304 Check initialisation
305 """
306 # check that we get a Scene object
307 classStr = self.scene.__class__.__name__
308 self.assertEqual('Scene', classStr)
309
310 # check default values of xSize and ySize
311 self.assertEqual(640, self.scene.xSize)
312 self.assertEqual(480, self.scene.ySize)
313
314 # check that we get a renderer
315 classStr = self.scene.renderer.__class__.__name__
316 self.assertEqual('Renderer', classStr)
317
318 def testAdd(self):
319 """
320 Test adding an item to the scene
321 """
322 # if no object passed, should barf with TypeError, or ValueError
323 self.assertRaises((TypeError,ValueError), self.scene.add)
324
325 # calling this at the base level should fail
326 self.assertRaises(NotImplementedError, self.scene.add, "")
327
328 def testDelete(self):
329 """
330 Test deleting an item from the scene
331 """
332 # if no object passed, should barf with TypeError, or ValueError
333 self.assertRaises((TypeError,ValueError), self.scene.delete)
334
335 # calling this at the base level should fail
336 self.assertRaises(NotImplementedError, self.scene.delete, "")
337
338 def testPlace(self):
339 """
340 Test placing an item within the scene
341 """
342 # if no object passed, should barf with TypeError, or ValueError
343 self.assertRaises((TypeError,ValueError), self.scene.place)
344
345 # calling this at the base level should fail
346 self.assertRaises(NotImplementedError, self.scene.place, "")
347
348 def testRenderArguments(self):
349 """
350 Test the arguments passed to the render method
351 """
352 self.assertRaises(ValueError, self.scene.render, pause="")
353 self.assertRaises(ValueError, self.scene.render, interactive="")
354
355 def testSaveArguments(self):
356 """
357 Test the arguments passed to the save method
358 """
359 self.assertRaises(TypeError, self.scene.save)
360 self.assertRaises(ValueError, self.scene.save, fname="", format="")
361 self.assertRaises((TypeError, ValueError), self.scene.save, fname="")
362 self.assertRaises((TypeError, ValueError), self.scene.save, format="")
363 self.assertRaises((TypeError, ValueError), \
364 self.scene.save, fname="moo.file")
365 self.assertRaises((TypeError, ValueError), \
366 self.scene.save, format="myformat")
367
368 # need to barf if this method is used from the base pyvisi class
369 self.assertRaises(NotImplementedError, \
370 self.scene.save, fname="moo.file", format="myformat")
371
372 def testSetBackgroundColor(self):
373 """
374 Test setting the scene's background colour
375 """
376 self.assertRaises(NotImplementedError, self.scene.setBackgroundColor)
377
378 def testGetBackgroundColor(self):
379 """
380 Test getting the scene's background colour
381 """
382 self.assertRaises(NotImplementedError, self.scene.getBackgroundColor)
383
384 def testGetSize(self):
385 """
386 Test getting the size of the scene dimensions
387 """
388 self.assertEqual((640,480), self.scene.getSize())
389
390 def testSetSize(self):
391 """
392 Test setting the size of the scene dimensions
393 """
394 self.scene.setSize(123, 456)
395 self.assertEqual((123, 456), self.scene.getSize())
396
397 def testRendererCommand(self):
398 """
399 Test the renderer command
400 """
401 inCommand = "mooo"
402 outCommand = inCommand + '\n'
403 self.scene.rendererCommand(inCommand)
404 self.assertEqual(self.scene.renderer.getEvalStack(), outCommand)
405
406 def testExactlyNoArguments(self):
407 """
408 Test methods that do not take an argument at all
409 """
410 self.assertRaises(TypeError, self.scene.getBackgroundColor, "")
411 self.assertRaises(TypeError, self.scene.getSize, "")
412
413 def testExactlyOneArgument(self):
414 """
415 Test methods that take exactly one argument
416 """
417 self.assertRaises(TypeError, self.scene.add)
418 self.assertRaises(TypeError, self.scene.add, "", "")
419 self.assertRaises(TypeError, self.scene.delete)
420 self.assertRaises(TypeError, self.scene.delete, "", "")
421 self.assertRaises(TypeError, self.scene.place)
422 self.assertRaises(TypeError, self.scene.place, "", "")
423 self.assertRaises(TypeError, self.scene.rendererCommand)
424 self.assertRaises(TypeError, self.scene.rendererCommand, "", "")
425
426 def testExactlyTwoArguments(self):
427 """
428 Test methods that take exactly two arguments
429 """
430 # scene.setSize()
431 self.assertRaises(TypeError, self.scene.setSize)
432 self.assertRaises(TypeError, self.scene.setSize, 1)
433 self.assertRaises(TypeError, self.scene.setSize, 1, 2, 3)
434
435 # scene.save()
436 self.assertRaises(TypeError, self.scene.save)
437 self.assertRaises(TypeError, self.scene.save, "1")
438 self.assertRaises(TypeError, self.scene.save, "1", "2", "3")
439
440 def testIntegerArguments(self):
441 """
442 Test methods that take integer arguments
443 """
444 self.assertRaises(AssertionError, self.scene.setSize, "moo", "baa")
445
446 def testStringArguments(self):
447 """
448 Test methods that take string arguments
449 """
450 self.assertRaises(AssertionError, self.scene.save, 1, 2)
451 self.assertRaises(AssertionError, self.scene.rendererCommand, 1)
452
453 class TestText(unittest.TestCase):
454 """
455 The main test class
456 """
457
458 def testAddText(self):
459 scene = Scene()
460 text = scene.addText()
461 self.assertEqual(text.__class__.__name__, 'Text')
462
463 def testTextFontAttr(self):
464 # make sure the font attribute exists and is text
465 scene = Scene()
466 text = scene.addText()
467 self.assert_(text.font.isalpha(), \
468 msg='Text font attribute is not text')
469
470 def testTextChangeFont(self):
471 # now try and set the font to something, and see if that works
472 scene = Scene()
473 text = scene.addText()
474 text.font = "Helvetica"
475 self.assertEqual('Helvetica', text.font)
476 self.assertNotEqual('Times', text.font)
477
478 def testTextNotAlphaNum(self):
479 # text to see if when we set the font to alphanumeric that it barfs
480 scene = Scene()
481 text = scene.addText()
482 text.font = "Times2"
483 self.assert_(not text.font.isalpha(), \
484 msg='Text font attribute is supposed to be text not alphanum')
485
486
487
488
489 if __name__ == '__main__':
490 suite = unittest.TestSuite()
491 suite.addTest(unittest.makeSuite(TestAxes))
492 suite.addTest(unittest.makeSuite(TestCamera))
493 suite.addTest(unittest.makeSuite(TestImage))
494 suite.addTest(unittest.makeSuite(TestItem))
495 suite.addTest(unittest.makeSuite(TestPlane))
496 suite.addTest(unittest.makeSuite(TestPlot))
497 suite.addTest(unittest.makeSuite(TestRenderer))
498 suite.addTest(unittest.makeSuite(TestScene))
499 suite.addTest(unittest.makeSuite(TestText))
500 unittest.TextTestRunner(verbosity=2).run(suite).wasSuccessful()

  ViewVC Help
Powered by ViewVC 1.1.26