Salome HOME
Some useful tools for MEDCouplingMappedExtrudedMesh users that needs to store it...
[tools/medcoupling.git] / src / MEDCoupling_Swig / MEDCouplingBasicsTest4.py
index a4106d88b8ba1576b59b267da8fa77e9a4cfed3e..26f456cbf231bffe85ae1c7cc3bc02de14313b2c 100644 (file)
@@ -1,5 +1,5 @@
 #  -*- coding: utf-8 -*-
-# Copyright (C) 2007-2015  CEA/DEN, EDF R&D
+# Copyright (C) 2007-2016  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
@@ -24,6 +24,29 @@ from math import pi,e,sqrt,cos,sin
 from datetime import datetime
 from MEDCouplingDataForTest import MEDCouplingDataForTest
 import rlcompleter,readline # this line has to be here, to ensure a usability of MEDCoupling/MEDLoader. B4 removing it please notify to anthony.geay@cea.fr
+from sys import platform
+
+def checkFreeMemory(size):
+    """
+    Get node total memory and memory usage
+    """
+    ret = True
+    dic = {}
+    if platform not in ["win32"]:
+        with open('/proc/meminfo', 'r') as mem:
+            tmp = 0
+            for i in mem:
+                sline = i.split()
+                if str(sline[0]) == 'MemTotal:':
+                    dic['total'] = int(sline[1])
+                elif str(sline[0]) in ('MemFree:', 'Buffers:', 'Cached:'):
+                    tmp += int(sline[1])
+            dic['free'] = tmp
+            dic['used'] = int(dic['total']) - int(dic['free'])
+            ret = dic['free'] > size
+    #TODO: extend this method for Windows OS            
+    return ret
+
 
 class MEDCouplingBasicsTest4(unittest.TestCase):
     def testSwigDADOp4(self):
@@ -2873,7 +2896,8 @@ class MEDCouplingBasicsTest4(unittest.TestCase):
         self.assertTrue(a.isEqual(DataArrayInt([0,2,4])))
         self.assertTrue(b.isEqual(DataArrayInt([0,1,2,7,8,15,16,17])))
         pass
-    
+
+    @unittest.skipUnless(checkFreeMemory((223456789*16)/(1024)), "Not enough memory")
     def testSwig2BigMem(self):
         if MEDCouplingSizeOfVoidStar()==64:
             d=DataArrayAsciiChar(223456789,16)