/[escript]/trunk/finley/test/python/run_generators.py
ViewVC logotype

Diff of /trunk/finley/test/python/run_generators.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 709 by gross, Wed Apr 26 06:35:36 2006 UTC revision 1044 by gross, Mon Mar 19 07:29:31 2007 UTC
# Line 15  import sys Line 15  import sys
15  import os  import os
16  import unittest  import unittest
17  from esys.escript import *  from esys.escript import *
18  from esys.finley import Interval,Rectangle,Brick,JoinFaces  from esys.finley import Interval,Rectangle,Brick,JoinFaces, ReadGmsh, ReadMesh
19    
20  FINLEY_TEST_DATA_PATH=os.environ['FINLEY_TEST_DATA']+"/data_meshes/"  try:
21  FINLEY_WORKDIR_PATH=os.environ['FINLEY_WORKDIR']+"/"       FINLEY_TEST_DATA=os.environ['FINLEY_TEST_DATA']
22    except KeyError:
23         FINLEY_TEST_DATA='.'
24    
25    try:
26         FINLEY_WORKDIR=os.environ['FINLEY_WORKDIR']
27    except KeyError:
28         FINLEY_WORKDIR='.'
29    
30    FINLEY_TEST_MESH_PATH=FINLEY_TEST_DATA+"/data_meshes/"
31    if os.name == "nt":
32       FINLEY_TEST_MESH_PATH = FINLEY_TEST_MESH_PATH+"win32/"
33    FINLEY_WORKDIR_PATH=FINLEY_WORKDIR+"/"
34    
35  TEST_FILE_EXT=".test"  TEST_FILE_EXT=".test"
36  class Test_Generators(unittest.TestCase):  class Test_Generators(unittest.TestCase):
# Line 26  class Test_Generators(unittest.TestCase) Line 38  class Test_Generators(unittest.TestCase)
38     def checker(self,dom,reference):     def checker(self,dom,reference):
39        dom_file=FINLEY_WORKDIR_PATH+TEST_FILE_EXT        dom_file=FINLEY_WORKDIR_PATH+TEST_FILE_EXT
40        dom.write(dom_file)        dom.write(dom_file)
41    # Uncomment this section to dump the files for regression testing
42    #      if True:
43    #         dom.write(FINLEY_TEST_MESH_PATH+reference)
44        dom_string=open(dom_file).read().splitlines()        dom_string=open(dom_file).read().splitlines()
45        ref_string=open(FINLEY_TEST_DATA_PATH+reference).read().splitlines()        ref_string=open(FINLEY_TEST_MESH_PATH+reference).read().splitlines()
46        self.failUnlessEqual(len(dom_string),len(ref_string),"number of lines in mesh files does not match reference")        self.failUnlessEqual(len(dom_string),len(ref_string),"number of lines in mesh files does not match reference")
47        for l in range(1,len(ref_string)):        for l in range(1,len(ref_string)):
48           self.failUnlessEqual(dom_string[l].strip(),ref_string[l].strip(),"line %d (%s) in mesh files does not match reference (%s)"%(l,ref_string[l].strip(),dom_string[l].strip()))           self.failUnlessEqual(dom_string[l].strip(),ref_string[l].strip(),"line %d (%s) in mesh files does not match reference (%s)"%(l,ref_string[l].strip(),dom_string[l].strip()))
# Line 156  class Test_Generators(unittest.TestCase) Line 171  class Test_Generators(unittest.TestCase)
171        my_dom=JoinFaces([ms1,ms2])        my_dom=JoinFaces([ms1,ms2])
172        self.checker(my_dom,file)        self.checker(my_dom,file)
173    
174    class Test_GMSHReader(unittest.TestCase):
175       def compare(self, test_file, reference_file):
176          dom_string=open(test_file).read().splitlines()
177          ref_string=open(reference_file).read().splitlines()
178          self.failUnlessEqual(len(dom_string),len(ref_string),"number of lines in mesh files does not match reference")
179          for l in range(1,len(ref_string)):
180             self.failUnlessEqual(dom_string[l].strip(),ref_string[l].strip(),"line %d (%s) in mesh files does not match reference (%s)"%(l,ref_string[l].strip(),dom_string[l].strip()))
181    
182       def test_Tri3(self):
183           file="tri3_gmsh.msh"
184           ref ="tri3.fly"
185           test = FINLEY_WORKDIR+os.sep+"tri3_test.fly"
186           dom = ReadGmsh(FINLEY_TEST_MESH_PATH+os.sep+file,2)
187           dom.write(test)
188           self.compare(test, FINLEY_TEST_MESH_PATH+os.sep+ref)
189    
190       def test_Tri6(self):
191           file="tri6_gmsh.msh"
192           ref="tri6.fly"
193           test = FINLEY_WORKDIR+os.sep+"tri8_test.fly"
194           dom = ReadGmsh(FINLEY_TEST_MESH_PATH+os.sep+file,2)
195           dom.write(test)
196           self.compare(test, FINLEY_TEST_MESH_PATH+os.sep+ref)
197    
198       def test_Tet4(self):
199           file="tet4_gmsh.msh"
200           ref="tet4.fly"
201           test = FINLEY_WORKDIR+os.sep+"tet4_test.fly"
202           dom = ReadGmsh(FINLEY_TEST_MESH_PATH+os.sep+file,3)
203           dom.write(test)
204           self.compare(test, FINLEY_TEST_MESH_PATH+os.sep+ref)
205    
206       def test_Tet(self):
207           file="tet10_gmsh.msh"
208           ref="tet10.fly"
209           test = FINLEY_WORKDIR+os.sep+"tet10_test.fly"
210           dom = ReadGmsh(FINLEY_TEST_MESH_PATH+os.sep+file,3)
211           dom.write(test)
212           self.compare(test, FINLEY_TEST_MESH_PATH+os.sep+ref)
213    
214    class Test_Reader(unittest.TestCase):
215       def test_ReadWriteTagNames(self):
216           file="hex_2D_order2.msh"
217           test = FINLEY_WORKDIR+os.sep+"test.fly"
218           dom = ReadMesh(FINLEY_TEST_MESH_PATH+os.sep+file,3)
219           insertTagNames(dom,A=1,B=2)
220           dom.write(test)
221           dom2 = ReadMesh(test,3)
222           t=getTagNames(dom)
223           self.failUnless(len(t)==2)
224           self.failUnless("A" in t)
225           self.failUnless("B" in t)
226           self.failUnless(dom2.getTag("A") == 1)
227           self.failUnless(dom2.getTag("B") == 2)
228           self.failUnless(dom2.isValidTagName("A"))
229           self.failUnless(dom2.isValidTagName("B"))
230          
231    
232  if __name__ == '__main__':  if __name__ == '__main__':
233     suite = unittest.TestSuite()     suite = unittest.TestSuite()
234     suite.addTest(unittest.makeSuite(Test_Generators))     suite.addTest(unittest.makeSuite(Test_Generators))
235       suite.addTest(unittest.makeSuite(Test_GMSHReader))
236       suite.addTest(unittest.makeSuite(Test_Reader))
237     s=unittest.TextTestRunner(verbosity=2).run(suite)     s=unittest.TextTestRunner(verbosity=2).run(suite)
238     if s.wasSuccessful():     if s.wasSuccessful():
239       sys.exit(0)       sys.exit(0)

Legend:
Removed from v.709  
changed lines
  Added in v.1044

  ViewVC Help
Powered by ViewVC 1.1.26