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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1376 - (show annotations)
Wed Jan 9 01:38:18 2008 UTC (11 years, 7 months ago) by gross
File MIME type: text/x-python
File size: 2328 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, Map, Image, Image, ImageReader
2 from esys.pyvisi import GlobalPosition
3 from esys.pyvisi.constant import *
4 import unittest, os
5 from stat import ST_SIZE
6
7 try:
8 PYVISI_WORKDIR=os.environ['PYVISI_WORKDIR']
9 except KeyError:
10 PYVISI_WORKDIR='.'
11 try:
12 PYVISI_TEST_DATA_ROOT=os.environ['PYVISI_TEST_DATA_ROOT']
13 except KeyError:
14 PYVISI_TEST_DATA_ROOT='.'
15
16 PYVISI_TEST_MESHES_PATH = os.path.join(PYVISI_TEST_DATA_ROOT, "data_meshes")
17 PYVISI_TEST_IMAGE_IMAGES_PATH = os.path.join(PYVISI_WORKDIR, \
18 "data_sample_images", "image")
19
20 MIN_IMAGE_SIZE = 100
21 FILE_3D = "interior_3D.xml"
22 IMAGE = "flinders.jpg"
23 X_SIZE = 400
24 Y_SIZE = 400
25 JPG_RENDERER = Renderer.OFFLINE_JPG
26
27 class TestImage:
28 def render(self, file):
29 self.scene.render(image_name = \
30 os.path.join(PYVISI_TEST_IMAGE_IMAGES_PATH, file))
31
32 self.failUnless(os.stat(os.path.join(PYVISI_TEST_IMAGE_IMAGES_PATH, \
33 file))[ST_SIZE] > MIN_IMAGE_SIZE)
34
35 class TestImageOnAMap(unittest.TestCase, TestImage):
36 def setUp(self):
37 self.scene = \
38 Scene(renderer = JPG_RENDERER, num_viewport = 1,
39 x_size = X_SIZE, y_size = Y_SIZE)
40
41 self.data_collector = DataCollector(source = Source.XML)
42 self.data_collector.setFileName(file_name = \
43 os.path.join(PYVISI_TEST_MESHES_PATH, FILE_3D))
44
45 self.map = Map(scene = self.scene,
46 data_collector = self.data_collector,
47 viewport = Viewport.SOUTH_WEST, lut = Lut.COLOR,
48 cell_to_point = False, outline = True)
49
50 self.image_reader = ImageReader(ImageFormat.JPG)
51 self.image_reader.setImageName(os.path.join(PYVISI_TEST_MESHES_PATH,\
52 IMAGE))
53
54 self.image = Image(scene = self.scene, image_reader = self.image_reader)
55
56 def tearDown(self):
57 del self.scene
58 del self.data_collector
59 del self.map
60 del self.image
61 del self.image_reader
62
63 def testImage(self):
64 self.image.translate(0, 0, -1)
65 self.image.setPoint1(GlobalPosition(2, 0, 0))
66 self.image.setPoint2(GlobalPosition(0, 2, 0))
67 self.image.setOpacity(0.6)
68 self.render("TestImage.jpg")
69
70
71 ###############################################################################
72
73
74 if __name__ == '__main__':
75 suite = unittest.TestSuite()
76 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestImageOnAMap))
77 s=unittest.TextTestRunner(verbosity=2).run(suite)
78 if not s.wasSuccessful(): sys.exit(1)
79

  ViewVC Help
Powered by ViewVC 1.1.26