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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1158 - (show annotations)
Tue May 22 04:24:01 2007 UTC (13 years, 11 months ago) by jongui
File MIME type: text/x-python
File size: 2321 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 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_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 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 TestImageWithLazyEvaluation:
30 def render(self, file):
31 self.scene.render(image_name = \
32 os.path.join(PYVISI_TEST_IMAGE_IMAGES_PATH, file))
33
34 self.failUnless(os.stat(os.path.join(PYVISI_TEST_IMAGE_IMAGES_PATH, \
35 file))[ST_SIZE] > MIN_IMAGE_SIZE)
36
37 class TestImage(unittest.TestCase, TestImageWithLazyEvaluation):
38 def tearDown(self):
39 del self.scene
40
41 def testImage(self):
42 s = Scene(renderer = JPG_RENDERER, num_viewport = 1, x_size = X_SIZE,
43 y_size = Y_SIZE)
44 self.scene = s
45
46 dc1 = DataCollector(source = Source.XML)
47
48 # Create a map instance for the first viewport.
49 m1 = Map(scene = s, data_collector = dc1,
50 viewport = Viewport.SOUTH_WEST, lut = Lut.COLOR, outline = True)
51
52 # Create one image reader instance (used in place of data collector).
53 ir = ImageReader(ImageFormat.JPG)
54
55
56 # Create one image instance.
57 i = Image(scene = s, image_reader = ir)
58 i.setOpacity(opacity = 0.9)
59 i.translate(0,0,-1.)
60 i.setPoint1(GlobalPosition(2,0,0))
61 i.setPoint2(GlobalPosition(0,2,0))
62
63 ir.setImageName(image_name = os.path.join(PYVISI_TEST_MESHES_PATH, \
64 IMAGE))
65 dc1.setFileName(file_name = os.path.join(PYVISI_TEST_MESHES_PATH, \
66 FILE_3D))
67
68 self.render("TestImageWithLazyEvaluation.jpg")
69
70
71 ###############################################################################
72
73
74 if __name__ == '__main__':
75 suite = unittest.TestSuite()
76 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestImage))
77 unittest.TextTestRunner(verbosity=2).run(suite)
78

  ViewVC Help
Powered by ViewVC 1.1.26