X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FMEDLoader%2FSwig%2FSauvLoaderTest.py;h=b60a4fd3d63959d9b065fdb21b6f857eb0535895;hb=b6c89e5886e9b348c00d3d6c23a265f89613cbc7;hp=0da6104cdc1b71ccc92654f375fd5aa196709db4;hpb=cc7bbd19636181c03967b58b6124d20ea313a7eb;p=tools%2Fmedcoupling.git diff --git a/src/MEDLoader/Swig/SauvLoaderTest.py b/src/MEDLoader/Swig/SauvLoaderTest.py index 0da6104cd..b60a4fd3d 100644 --- a/src/MEDLoader/Swig/SauvLoaderTest.py +++ b/src/MEDLoader/Swig/SauvLoaderTest.py @@ -1,10 +1,10 @@ # -*- coding: iso-8859-1 -*- -# Copyright (C) 2007-2013 CEA/DEN, EDF R&D +# Copyright (C) 2007-2015 CEA/DEN, EDF R&D # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public # License as published by the Free Software Foundation; either -# version 2.1 of the License. +# version 2.1 of the License, or (at your option) any later version. # # This library is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -25,20 +25,27 @@ from MEDLoaderDataForTest import MEDLoaderDataForTest class SauvLoaderTest(unittest.TestCase): + def __getResourcesDirectory(self): + med_root_dir=os.getenv("MEDTOOL_ROOT_DIR") + if med_root_dir: + return os.path.join( os.getenv("MEDTOOL_ROOT_DIR"), "share","resources","med") + else: + current_dir = os.path.dirname(os.path.realpath(__file__)) + return os.path.join(current_dir, "..", "..", "..", "resources") + pass + def testSauv2Med(self): # get a file containing all types of readable piles - self.assertTrue( os.getenv("MED_ROOT_DIR") ) - sauvFile = os.path.join( os.getenv("MED_ROOT_DIR"), "share","salome", - "resources","med","allPillesTest.sauv") + sauvFile = os.path.join( self.__getResourcesDirectory(),"allPillesTest.sauv") self.assertTrue( os.access( sauvFile, os.F_OK)) # read SAUV and write MED medFile = "SauvLoaderTest.med" - sr=SauvReader.New(sauvFile); + sr=SauvReader(sauvFile); d2=sr.loadInMEDFileDS(); d2.write(medFile,0); - # check + # check self.assertEqual(1,d2.getNumberOfMeshes()) self.assertEqual(8+97,d2.getNumberOfFields()) mm = d2.getMeshes() @@ -50,9 +57,7 @@ class SauvLoaderTest(unittest.TestCase): def testMed2Sauv(self): # read pointe.med - self.assertTrue( os.getenv("MED_ROOT_DIR") ) - medFile = os.path.join( os.getenv("MED_ROOT_DIR"), "share","salome", - "resources","med","pointe.med") + medFile = os.path.join(self.__getResourcesDirectory(),"pointe.med") self.assertTrue( os.access( medFile, os.F_OK)) pointeMed = MEDFileData.New( medFile ) @@ -95,7 +100,7 @@ class SauvLoaderTest(unittest.TestCase): # write pointeMed to SAUV sauvFile = "SauvLoaderTest.sauv" - sw=SauvWriter.New(); + sw=SauvWriter(); sw.setMEDFileDS(pointeMed); sw.write(sauvFile); @@ -241,9 +246,7 @@ class SauvLoaderTest(unittest.TestCase): @unittest.skipUnless(MEDLoader.HasXDR(),"requires XDR") def testMissingGroups(self): """test for issue 0021749: [CEA 601] Some missing groups in mesh after reading a SAUV file with SauvReader.""" - self.assertTrue( os.getenv("MED_ROOT_DIR") ) - sauvFile = os.path.join( os.getenv("MED_ROOT_DIR"), "share","salome", - "resources","med","BDC-714.sauv") + sauvFile = os.path.join(self.__getResourcesDirectory(),"BDC-714.sauv") self.assertTrue( os.access( sauvFile, os.F_OK)) name_of_group_on_cells='Slice10:ABSORBER' name_of_group_on_cells2='Slice10:00LR' @@ -321,9 +324,71 @@ class SauvLoaderTest(unittest.TestCase): self.assertTrue( f2.isEqual( f, 1e-12, 1e-12 )) del sr os.remove( sauvFile ) + pass + + def testSauvWriterGroupWithOneFamily(self): + """ + This test checks an option for sauv writing. It is requested here to copy a group from a family if a group is lying on a single family. + """ + import re + mfd=MEDLoaderDataForTest.buildAMEDFileDataWithGroupOnOneFamilyForSauv() + sauvFile = "mesh.sauv" + sw=SauvWriter.New() + sw.setMEDFileDS(mfd) + self.assertTrue(not sw.getCpyGrpIfOnASingleFamilyStatus()) + sw.setCpyGrpIfOnASingleFamilyStatus(True) + self.assertTrue(sw.getCpyGrpIfOnASingleFamilyStatus()) + sw.write(sauvFile) + + f = open(sauvFile) + # String pattern for the header of the sub meshes record ("PILE" number, number of named objects, number of objects) + pattern_pile= re.compile(r'\sPILE\sNUMERO\s+(?P[0-9]+)NBRE\sOBJETS\sNOMMES\s+(?P[0-9]+)NBRE\sOBJETS\s+(?P[0-9]+)') + # String pattern for a sub mesh header (cell type, number of components and three numbers) + pattern_header=re.compile(r'\s+(?P[0-9]+)\s+(?P[0-9]+)\s+[0-9]+\s+[0-9]+\s+[0-9]+') + + nbobjects=0 + line = f.readline() + while(line): + match_pile = pattern_pile.match(line) + if match_pile: + number=int(match_pile.group("number")) + if number == 1: + nbnamed=int(match_pile.group("nbnamed")) + nbobjects=int(match_pile.group("nbobjects")) + break + pass + line=f.readline() + pass + # Skipping the objects names + f.readline() + # Skipping the objects ids + f.readline() + # Looking for each sub-mesh header + line = f.readline() + cur_object=0 + while(line and cur_object < nbobjects): + match_header=pattern_header.match(line) + if match_header: + cell_type=int(match_header.group("type")) + nb_subs=int(match_header.group("nbsubs")) + # Looking for a compound object + if cell_type == 0: + # Testing if there is only one component + self.assertTrue(nb_subs > 1) + else: + f.readline() + f.readline() + cur_object = cur_object + 1 + pass + pass + line=f.readline() + pass + f.close() + os.remove(sauvFile) pass + pass unittest.main()