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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1158 - (hide annotations)
Tue May 22 04:24:01 2007 UTC (12 years, 3 months ago) by jongui
File MIME type: text/x-python
File size: 2396 byte(s)
Made some changes to fix the memory leak problem. However, the problem still persists for run_escript_with_lazy_evaluation.py, run_streamline.py and run_streamline_with_lazy_evaluation.py.

1 ksteube 1147 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 jongui 1148 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_REFERENCE_IMAGES_PATH = os.path.join(PYVISI_TEST_DATA_ROOT, \
18     "data_reference_images", "image")
19     PYVISI_TEST_IMAGE_IMAGES_PATH = os.path.join(PYVISI_WORKDIR, \
20     "data_sample_images", "image")
21    
22 ksteube 1147 MIN_IMAGE_SIZE = 100
23     FILE_3D = "interior_3D.xml"
24     IMAGE = "flinders.jpg"
25     X_SIZE = 400
26     Y_SIZE = 400
27     JPG_RENDERER = Renderer.OFFLINE_JPG
28    
29     class TestImage:
30     def render(self, file):
31     self.scene.render(image_name = \
32 jongui 1148 os.path.join(PYVISI_TEST_IMAGE_IMAGES_PATH, file))
33 ksteube 1147
34 jongui 1148 self.failUnless(os.stat(os.path.join(PYVISI_TEST_IMAGE_IMAGES_PATH, \
35     file))[ST_SIZE] > MIN_IMAGE_SIZE)
36 ksteube 1147
37     class TestImageOnAMap(unittest.TestCase, TestImage):
38     def setUp(self):
39     self.scene = \
40     Scene(renderer = JPG_RENDERER, num_viewport = 1,
41     x_size = X_SIZE, y_size = Y_SIZE)
42    
43     self.data_collector = DataCollector(source = Source.XML)
44     self.data_collector.setFileName(file_name = \
45 jongui 1148 os.path.join(PYVISI_TEST_MESHES_PATH, FILE_3D))
46 ksteube 1147
47     self.map = Map(scene = self.scene,
48     data_collector = self.data_collector,
49     viewport = Viewport.SOUTH_WEST, lut = Lut.COLOR,
50     cell_to_point = False, outline = True)
51    
52     self.image_reader = ImageReader(ImageFormat.JPG)
53 jongui 1148 self.image_reader.setImageName(os.path.join(PYVISI_TEST_MESHES_PATH,\
54     IMAGE))
55 ksteube 1147
56     self.image = Image(scene = self.scene, image_reader = self.image_reader)
57    
58 jongui 1158 def tearDown(self):
59     del self.scene
60     del self.data_collector
61     del self.map
62     del self.image
63     del self.image_reader
64    
65 ksteube 1147 def testImage(self):
66     self.image.translate(0, 0, -1)
67     self.image.setPoint1(GlobalPosition(2, 0, 0))
68     self.image.setPoint2(GlobalPosition(0, 2, 0))
69     self.image.setOpacity(0.6)
70     self.render("TestImage.jpg")
71    
72    
73     ###############################################################################
74    
75    
76     if __name__ == '__main__':
77     suite = unittest.TestSuite()
78     suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestImageOnAMap))
79     unittest.TextTestRunner(verbosity=2).run(suite)
80    

  ViewVC Help
Powered by ViewVC 1.1.26