From: Anthony Geay Date: Thu, 27 Sep 2018 07:35:15 +0000 (+0200) Subject: Context manager for MEDFile*Field1TS X-Git-Tag: V9_2_0a2~13 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=f20f597e26cd59cda5297565226be6a261b2500d;p=tools%2Fmedcoupling.git Context manager for MEDFile*Field1TS --- diff --git a/src/MEDLoader/Swig/MEDLoaderCommon.i b/src/MEDLoader/Swig/MEDLoaderCommon.i index 460be09de..359f8be11 100644 --- a/src/MEDLoader/Swig/MEDLoaderCommon.i +++ b/src/MEDLoader/Swig/MEDLoaderCommon.i @@ -4113,3 +4113,14 @@ namespace MEDCoupling } }; } + +%pythoncode %{ +def enter1TS(self): + self.loadArrays() + pass +def exit1TS(self, exctype, exc, tb): + self.unloadArrays() + pass +MEDFileAnyTypeField1TS.__enter__=enter1TS +MEDFileAnyTypeField1TS.__exit__=exit1TS +%} diff --git a/src/MEDLoader/Swig/MEDLoaderTest3.py b/src/MEDLoader/Swig/MEDLoaderTest3.py index 65295157d..b8a8936a0 100644 --- a/src/MEDLoader/Swig/MEDLoaderTest3.py +++ b/src/MEDLoader/Swig/MEDLoaderTest3.py @@ -6488,6 +6488,35 @@ class MEDLoaderTest3(unittest.TestCase): pass pass + def tessContxtMger1TS(self): + fname="Pyfile119.med" + coo=DataArrayDouble(1000) ; coo.iota() + m=MEDCouplingUMesh.Build0DMeshFromCoords(coo) + m.setName("mesh") + WriteMesh(fname,m,True) + f=MEDCouplingFieldDouble(ON_CELLS) + f.setMesh(m) + f.setName("Field") + arr=DataArrayDouble(m.getNumberOfCells()) + f.setArray(arr) + f.checkConsistencyLight() + for i in range(10): + arr[:]=float(i+1) + f.setTime(float(i),i,0) + WriteFieldUsingAlreadyWrittenMesh(fname,f) + pass + # + mm=MEDFileMesh.New(fname) + fmts=MEDFileFieldMultiTS(fname,False) + refSize=fmts.getHeapMemorySize() + for f1ts in fmts: + with f1ts: + f=f1ts.field(mm) + pass + pass + self.assertIn(fmts.getHeapMemorySize(),range(refSize,refSize+refSize//10)) + pass + pass if __name__ == "__main__":