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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1388 - (show annotations)
Fri Jan 11 07:45:58 2008 UTC (11 years, 10 months ago) by trankine
File MIME type: text/x-python
File size: 5090 byte(s)
And get the *(&(*&(* name right
1 from esys.pyvisi import DataCollector
2 from esys.pyvisi.constant import *
3 import unittest, os, sys
4
5 try:
6 PYVISI_WORKDIR=os.environ['PYVISI_WORKDIR']
7 except KeyError:
8 PYVISI_WORKDIR='.'
9 try:
10 PYVISI_TEST_DATA_ROOT=os.environ['PYVISI_TEST_DATA_ROOT']
11 except KeyError:
12 PYVISI_TEST_DATA_ROOT='.'
13
14 PYVISI_TEST_MESHES_PATH = os.path.join(PYVISI_TEST_DATA_ROOT, "data_meshes")
15 FILE_2D = "interior_2D.xml"
16 FILE_3D = "interior_3D.xml"
17
18 SCALAR_FIELD_POINT_DATA = "temperature"
19 VECTOR_FIELD_POINT_DATA = "velocity"
20 TENSOR_FIELD_POINT_DATA = "stress"
21
22 SCALAR_FIELD_CELL_DATA = "temperature_cell"
23 VECTOR_FIELD_CELL_DATA = "velocity_cell"
24 TENSOR_FIELD_CELL_DATA = "stress_cell"
25
26 class TestSourceXml:
27 def setFileName(self, file):
28 self.data_collector.setFileName(file_name = \
29 os.path.join(PYVISI_TEST_MESHES_PATH, file))
30
31 def setActiveScalar(self, s):
32 self.data_collector.setActiveScalar(scalar = s)
33
34 def setActiveVector(self, v):
35 self.data_collector.setActiveVector(vector = v)
36
37 def setActiveTensor(self, t):
38 self.data_collector.setActiveTensor(tensor = t)
39
40 def checkScalarFieldPointData(self, f):
41 self.failUnlessEqual(self.data_collector._getDataCollectorOutput().GetPointData().GetScalars().GetName(), f)
42
43 def checkVectorFieldPointData(self, f):
44 self.failUnlessEqual(self.data_collector._getDataCollectorOutput().GetPointData().GetVectors().GetName(), f)
45
46 def checkTensorFieldPointData(self, f):
47 self.failUnlessEqual(self.data_collector._getDataCollectorOutput().GetPointData().GetTensors().GetName(), f)
48
49 def checkScalarFieldCellData(self, f):
50 self.failUnlessEqual(self.data_collector._getDataCollectorOutput().GetCellData().GetScalars().GetName(), f)
51
52 def checkVectorFieldCellData(self, f):
53 self.failUnlessEqual(self.data_collector._getDataCollectorOutput().GetCellData().GetVectors().GetName(), f)
54
55 def checkTensorFieldCellData(self, f):
56 self.failUnlessEqual(self.data_collector._getDataCollectorOutput().GetCellData().GetTensors().GetName(), f)
57
58
59 class TestSourceXml2DPointData(unittest.TestCase, TestSourceXml):
60 def setUp(self):
61 self.data_collector = DataCollector(source = Source.XML)
62 self.setFileName(FILE_2D)
63
64 def tearDown(self):
65 del self.data_collector
66
67 def testSetActiveScalar(self):
68 self.setActiveScalar(SCALAR_FIELD_POINT_DATA)
69 self.checkScalarFieldPointData(SCALAR_FIELD_POINT_DATA)
70
71 def testSetActiveVector(self):
72 self.setActiveVector(VECTOR_FIELD_POINT_DATA)
73 self.checkVectorFieldPointData(VECTOR_FIELD_POINT_DATA)
74
75 def testSetActiveTensor(self):
76 self.setActiveTensor(TENSOR_FIELD_POINT_DATA)
77 self.checkTensorFieldPointData(TENSOR_FIELD_POINT_DATA)
78
79 class TestSourceXml2DCellData(unittest.TestCase, TestSourceXml):
80 def setUp(self):
81 self.data_collector = DataCollector(source = Source.XML)
82 self.setFileName(FILE_2D)
83
84 def tearDown(self):
85 del self.data_collector
86
87 def testSetActiveScalar(self):
88 self.setActiveScalar(SCALAR_FIELD_CELL_DATA)
89 self.checkScalarFieldCellData(SCALAR_FIELD_CELL_DATA)
90
91 def testSetActiveVector(self):
92 self.setActiveVector(VECTOR_FIELD_CELL_DATA)
93 self.checkVectorFieldCellData(VECTOR_FIELD_CELL_DATA)
94
95 def testSetActiveTensor(self):
96 self.setActiveTensor(TENSOR_FIELD_CELL_DATA)
97 self.checkTensorFieldCellData(TENSOR_FIELD_CELL_DATA)
98
99 class TestSourceXml3DPointData(unittest.TestCase, TestSourceXml):
100 def setUp(self):
101 self.data_collector = DataCollector(source = Source.XML)
102 self.setFileName(FILE_3D)
103
104 def tearDown(self):
105 del self.data_collector
106
107 def testSetActiveScalar(self):
108 self.setActiveScalar(SCALAR_FIELD_POINT_DATA)
109 self.checkScalarFieldPointData(SCALAR_FIELD_POINT_DATA)
110
111 def testSetActiveVector(self):
112 self.setActiveVector(VECTOR_FIELD_POINT_DATA)
113 self.checkVectorFieldPointData(VECTOR_FIELD_POINT_DATA)
114
115 def testSetActiveTensor(self):
116 self.setActiveTensor(TENSOR_FIELD_POINT_DATA)
117 self.checkTensorFieldPointData(TENSOR_FIELD_POINT_DATA)
118
119 class TestSourceXml3DCellData(unittest.TestCase, TestSourceXml):
120 def setUp(self):
121 self.data_collector = DataCollector(source = Source.XML)
122 self.setFileName(FILE_3D)
123
124 def tearDown(self):
125 del self.data_collector
126
127 def testSetActiveScalar(self):
128 self.setActiveScalar(SCALAR_FIELD_CELL_DATA)
129 self.checkScalarFieldCellData(SCALAR_FIELD_CELL_DATA)
130
131 def testSetActiveVector(self):
132 self.setActiveVector(VECTOR_FIELD_CELL_DATA)
133 self.checkVectorFieldCellData(VECTOR_FIELD_CELL_DATA)
134
135 def testSetActiveTensor(self):
136 self.setActiveTensor(TENSOR_FIELD_CELL_DATA)
137 self.checkTensorFieldCellData(TENSOR_FIELD_CELL_DATA)
138
139
140 ###############################################################################
141
142
143 if __name__ == '__main__':
144 suite = unittest.TestSuite()
145 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestSourceXml2DPointData))
146 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestSourceXml2DCellData))
147 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestSourceXml3DPointData))
148 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestSourceXml3DCellData))
149 s=unittest.TextTestRunner(verbosity=2).run(suite)
150 if not s.wasSuccessful(): sys.exit(1)
151

  ViewVC Help
Powered by ViewVC 1.1.26