]> SALOME platform Git repositories - modules/kernel.git/commitdiff
Salome HOME
Put test in salome test mechanism.
authorAnthony Geay <anthony.geay@edf.fr>
Wed, 22 Jul 2015 08:52:29 +0000 (10:52 +0200)
committerAnthony Geay <anthony.geay@edf.fr>
Wed, 22 Jul 2015 08:52:29 +0000 (10:52 +0200)
CTestTestfileInstall.cmake.in
src/SALOMESDS/CMakeLists.txt
src/SALOMESDS/CTestTestfileInstall.cmake [new file with mode: 0644]
src/SALOMESDS/TestSalomeSDS.py [new file with mode: 0644]
src/SALOMESDS/TestSalomeSDS2.py [deleted file]
src/SALOMESDS/TestSalomeSDS3.py [deleted file]
src/SALOMESDS/TestSalomeSDSHelper0.py [new file with mode: 0644]

index b739c2e22bbb7f4a9f43e50b285c01c6ebc0369a..05f1720ca10c9b1917a35f927cc735b155f361ad 100644 (file)
@@ -36,6 +36,7 @@ SUBDIRS( Launcher
          KernelHelpers
          SALOMEDS
          SALOMEDSImpl
+        SALOMESDS
          Utils
          UnitTests
          connect
index 259f95a91a6780bebc15f0e5a989e92f33052623..79ca214dc22f9757becd244ef8800cf1ca108827 100644 (file)
@@ -56,7 +56,9 @@ ADD_EXECUTABLE(SALOME_DataScopeServer SALOME_DataScopeServer.cxx)
 TARGET_LINK_LIBRARIES(SALOME_DataScopeServer SalomeSDS)
 INSTALL(TARGETS SALOME_DataScopeServer DESTINATION ${SALOME_INSTALL_BINS})
 INSTALL(FILES SalomeSDSClt.py DESTINATION ${SALOME_INSTALL_BINS})
-INSTALL(FILES TestSalomeSDS3.py DESTINATION ${SALOME_INSTALL_BINS})
-
 FILE(GLOB COMMON_HEADERS_HXX "${CMAKE_CURRENT_SOURCE_DIR}/*.hxx")
 INSTALL(FILES ${COMMON_HEADERS_HXX} DESTINATION ${SALOME_INSTALL_HEADERS})
+# tests part
+SET(LOCAL_TEST_DIR ${KERNEL_TEST_DIR}/SALOMESDS)
+INSTALL(FILES TestSalomeSDS.py TestSalomeSDSHelper0.py DESTINATION ${LOCAL_TEST_DIR})
+INSTALL(FILES CTestTestfileInstall.cmake DESTINATION ${LOCAL_TEST_DIR} RENAME CTestTestfile.cmake)
diff --git a/src/SALOMESDS/CTestTestfileInstall.cmake b/src/SALOMESDS/CTestTestfileInstall.cmake
new file mode 100644 (file)
index 0000000..bb88946
--- /dev/null
@@ -0,0 +1,23 @@
+# Copyright (C) 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, 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
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+#
+# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+#
+
+IF(NOT WIN32)
+  ADD_TEST(TestSalomeSDS python ${SALOME_TEST_DRIVER} ${TIMEOUT} TestSalomeSDS.py)
+  SET_TESTS_PROPERTIES(TestSalomeSDS PROPERTIES LABELS "${COMPONENT_NAME}" ENVIRONMENT "PYTHONPATH=${KERNEL_TEST_LIB}:$ENV{PYTHONPATH}")
+ENDIF(NOT WIN32)
diff --git a/src/SALOMESDS/TestSalomeSDS.py b/src/SALOMESDS/TestSalomeSDS.py
new file mode 100644 (file)
index 0000000..8bae455
--- /dev/null
@@ -0,0 +1,139 @@
+# -*- coding: utf-8 -*-
+# Copyright (C) 2007-2015  CEA/DEN, EDF R&D, OPEN CASCADE
+#
+# 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, 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
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+#
+# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+#
+# Author : Anthony Geay
+
+import SalomeSDSClt
+import SALOME
+import salome
+import unittest
+import cPickle
+import gc
+import time
+import multiprocessing as mp
+
+def obj2Str(obj):
+  return cPickle.dumps(obj,cPickle.HIGHEST_PROTOCOL)
+def str2Obj(strr):
+  return cPickle.loads(strr)
+def generateKey(varName,scopeName):
+  dsm=salome.naming_service.Resolve("/DataServerManager")
+  dss,isCreated=dsm.giveADataScopeTransactionCalled(scopeName)
+  assert(not isCreated)
+  t=dss.addKeyValueInVarHard(varName,obj2Str("ef"),obj2Str([11,14,100]))
+  time.sleep(3)
+  dss.atomicApply([t])
+def work(t):
+  i,varName,scopeName=t
+  if i==0:
+    generateKey(varName,scopeName)
+    return 0
+  else:
+    import TestSalomeSDSHelper0
+    import os,subprocess
+    fname=os.path.splitext(TestSalomeSDSHelper0.__file__)[0]+".py"
+    proc=subprocess.Popen(["python",fname],stdout=subprocess.PIPE,stderr=subprocess.PIPE)
+    out,err=proc.communicate()
+    if proc.returncode!=0:
+      print out
+      print err
+    return proc.returncode
+
+class SalomeSDSTest(unittest.TestCase):
+  
+  def testList1(self):
+    a=SalomeSDSClt.CreateRdExtGlobalVar([],"a","Scope0")
+    self.assertEqual(a.local_copy(),[])
+    a.append(5)
+    self.assertEqual(a.local_copy(),[5])
+    self.assertRaises(SALOME.SALOME_Exception,a.__delitem__,0)
+    a.append(["rt"])
+    self.assertEqual(a.local_copy(),[5,["rt"]])
+    a[1].append(8)
+    self.assertEqual(a.local_copy(),[5,["rt",8]])
+    a.extend(a)
+    self.assertEqual(a.local_copy(),[5,["rt",8],5,["rt",8]])
+    a.extend(a[3:])
+    self.assertEqual(a.local_copy(),[5,["rt",8],5,["rt",8],["rt",8]])
+    a[4].append(7)
+    self.assertEqual(a.local_copy(),[5,["rt",8],5,["rt",8],["rt",8,7]])
+    a.ptr().getMyDataScopeServer().deleteVar("a")
+    pass
+  
+  def testDict1(self):
+    a=SalomeSDSClt.CreateRdExtGlobalVar({},"a","Scope0")
+    a["ab"]=4
+    self.assertEqual(a.local_copy(),{"ab":4})
+    a["cd"]=[5]
+    self.assertEqual(a.local_copy(),{"ab":4,"cd":[5]})
+    a["cd"].append(77)
+    self.assertEqual(a.local_copy(),{"ab":4,"cd":[5,77]})
+    a.__setitem__("ef",["a","bb"])
+    self.assertEqual(a.local_copy(),{"ab":4,"cd":[5,77],"ef":["a","bb"]})
+    self.assertRaises(SALOME.SALOME_Exception,a.__setitem__,"ef",["a","bb"])
+    self.assertRaises(SALOME.SALOME_Exception,a.__setitem__,"ef",["a","bb","ccc"])
+    a["ef"].append("ccc")
+    self.assertEqual(a.local_copy(),{"ab":4,"cd":[5,77],"ef":["a","bb","ccc"]})
+    a["gh"]=a
+    self.assertEqual(a.local_copy(),{"ab":4,"cd":[5,77],"ef":["a","bb","ccc"],"gh":{"ab":4,"cd":[5,77],"ef":["a","bb","ccc"]}})
+    a["gh"]["cd"].append(99) ; a["cd"].append(88)
+    self.assertEqual(a.local_copy(),{"ab":4,"cd":[5,77,88],"ef":["a","bb","ccc"],"gh":{"ab":4,"cd":[5,77,99],"ef":["a","bb","ccc"]}})
+    a.ptr().getMyDataScopeServer().deleteVar("a")
+    pass
+
+  def testReadOnly1(self):
+    a=SalomeSDSClt.CreateRdOnlyGlobalVar({"ab":4,"cd":[5,77]},"a","Scope0")
+    self.assertEqual(a.local_copy(),{"ab":4,"cd":[5,77]})
+    self.assertRaises(Exception,a.__getitem__,"ab")
+    a.ptr().getMyDataScopeServer().deleteVar("a")
+
+  def testTransaction1(self):
+    scopeName="Scope1"
+    varName="a"
+    dsm=salome.naming_service.Resolve("/DataServerManager")
+    dsm.cleanScopesInNS()
+    if scopeName in dsm.listScopes():
+      dsm.removeDataScope(scopeName)
+    dss,isCreated=dsm.giveADataScopeTransactionCalled(scopeName)
+    self.assertTrue(isCreated)
+    #
+    t0=dss.createRdExtVarTransac(varName,obj2Str({"ab":[4,5,6]}))
+    dss.atomicApply([t0])
+    #
+    t1=dss.addKeyValueInVarHard(varName,obj2Str("cd"),obj2Str([7,8,9,10]))
+    dss.atomicApply([t1])
+    #
+    self.assertEqual(str2Obj(dss.fetchSerializedContent(varName)),{'ab':[4,5,6],'cd':[7,8,9,10]})
+    wk=dss.waitForKeyInVar(varName,obj2Str("cd"))
+    self.assertEqual(str2Obj(wk.waitFor()),[7,8,9,10])
+    #
+    nbProc=8
+    pool=mp.Pool(processes=nbProc)
+    asyncResult=pool.map_async(work,[(i,varName,scopeName) for i in xrange(nbProc)])
+    self.assertEqual(asyncResult.get(),nbProc*[0]) # <- the big test is here !
+    dsm.removeDataScope(scopeName)
+
+  def setUp(self):
+    salome.salome_init()
+    pass
+  
+  pass
+
+unittest.main()
+
diff --git a/src/SALOMESDS/TestSalomeSDS2.py b/src/SALOMESDS/TestSalomeSDS2.py
deleted file mode 100644 (file)
index 21fe167..0000000
+++ /dev/null
@@ -1,139 +0,0 @@
-# -*- coding: utf-8 -*-
-# Copyright (C) 2007-2015  CEA/DEN, EDF R&D, OPEN CASCADE
-#
-# 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, 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
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
-#
-# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
-#
-# Author : Anthony Geay
-
-import SalomeSDSClt
-import SALOME
-import salome
-import unittest
-import cPickle
-import gc
-import time
-import multiprocessing as mp
-
-def obj2Str(obj):
-  return cPickle.dumps(obj,cPickle.HIGHEST_PROTOCOL)
-def str2Obj(strr):
-  return cPickle.loads(strr)
-def generateKey(varName,scopeName):
-  dsm=salome.naming_service.Resolve("/DataServerManager")
-  dss,isCreated=dsm.giveADataScopeTransactionCalled(scopeName)
-  assert(not isCreated)
-  t=dss.addKeyValueInVarHard(varName,obj2Str("ef"),obj2Str([11,14,100]))
-  time.sleep(3)
-  dss.atomicApply([t])
-def work(t):
-  i,varName,scopeName=t
-  if i==0:
-    generateKey(varName,scopeName)
-    return 0
-  else:
-    import TestSalomeSDS3
-    import os,subprocess
-    fname=os.path.splitext(TestSalomeSDS3.__file__)[0]+".py"
-    proc=subprocess.Popen(["python",fname],stdout=subprocess.PIPE,stderr=subprocess.PIPE)
-    out,err=proc.communicate()
-    if proc.returncode!=0:
-      print out
-      print err
-    return proc.returncode
-
-class SalomeSDS2Test(unittest.TestCase):
-  
-  def testList1(self):
-    a=SalomeSDSClt.CreateRdExtGlobalVar([],"a","Scope0")
-    self.assertEqual(a.local_copy(),[])
-    a.append(5)
-    self.assertEqual(a.local_copy(),[5])
-    self.assertRaises(SALOME.SALOME_Exception,a.__delitem__,0)
-    a.append(["rt"])
-    self.assertEqual(a.local_copy(),[5,["rt"]])
-    a[1].append(8)
-    self.assertEqual(a.local_copy(),[5,["rt",8]])
-    a.extend(a)
-    self.assertEqual(a.local_copy(),[5,["rt",8],5,["rt",8]])
-    a.extend(a[3:])
-    self.assertEqual(a.local_copy(),[5,["rt",8],5,["rt",8],["rt",8]])
-    a[4].append(7)
-    self.assertEqual(a.local_copy(),[5,["rt",8],5,["rt",8],["rt",8,7]])
-    a.ptr().getMyDataScopeServer().deleteVar("a")
-    pass
-  
-  def testDict1(self):
-    a=SalomeSDSClt.CreateRdExtGlobalVar({},"a","Scope0")
-    a["ab"]=4
-    self.assertEqual(a.local_copy(),{"ab":4})
-    a["cd"]=[5]
-    self.assertEqual(a.local_copy(),{"ab":4,"cd":[5]})
-    a["cd"].append(77)
-    self.assertEqual(a.local_copy(),{"ab":4,"cd":[5,77]})
-    a.__setitem__("ef",["a","bb"])
-    self.assertEqual(a.local_copy(),{"ab":4,"cd":[5,77],"ef":["a","bb"]})
-    self.assertRaises(SALOME.SALOME_Exception,a.__setitem__,"ef",["a","bb"])
-    self.assertRaises(SALOME.SALOME_Exception,a.__setitem__,"ef",["a","bb","ccc"])
-    a["ef"].append("ccc")
-    self.assertEqual(a.local_copy(),{"ab":4,"cd":[5,77],"ef":["a","bb","ccc"]})
-    a["gh"]=a
-    self.assertEqual(a.local_copy(),{"ab":4,"cd":[5,77],"ef":["a","bb","ccc"],"gh":{"ab":4,"cd":[5,77],"ef":["a","bb","ccc"]}})
-    a["gh"]["cd"].append(99) ; a["cd"].append(88)
-    self.assertEqual(a.local_copy(),{"ab":4,"cd":[5,77,88],"ef":["a","bb","ccc"],"gh":{"ab":4,"cd":[5,77,99],"ef":["a","bb","ccc"]}})
-    a.ptr().getMyDataScopeServer().deleteVar("a")
-    pass
-
-  def testReadOnly1(self):
-    a=SalomeSDSClt.CreateRdOnlyGlobalVar({"ab":4,"cd":[5,77]},"a","Scope0")
-    self.assertEqual(a.local_copy(),{"ab":4,"cd":[5,77]})
-    self.assertRaises(Exception,a.__getitem__,"ab")
-    a.ptr().getMyDataScopeServer().deleteVar("a")
-
-  def testTransaction1(self):
-    scopeName="Scope1"
-    varName="a"
-    dsm=salome.naming_service.Resolve("/DataServerManager")
-    dsm.cleanScopesInNS()
-    if scopeName in dsm.listScopes():
-      dsm.removeDataScope(scopeName)
-    dss,isCreated=dsm.giveADataScopeTransactionCalled(scopeName)
-    assert(isCreated)
-    #
-    t0=dss.createRdExtVarTransac(varName,obj2Str({"ab":[4,5,6]}))
-    dss.atomicApply([t0])
-    #
-    t1=dss.addKeyValueInVarHard(varName,obj2Str("cd"),obj2Str([7,8,9,10]))
-    dss.atomicApply([t1])
-    #
-    assert(str2Obj(dss.fetchSerializedContent(varName))=={'ab':[4,5,6],'cd':[7,8,9,10]})
-    wk=dss.waitForKeyInVar(varName,obj2Str("cd"))
-    assert(str2Obj(wk.waitFor())==[7,8,9,10])
-    #
-    nbProc=8
-    pool=mp.Pool(processes=nbProc)
-    asyncResult=pool.map_async(work,[(i,varName,scopeName) for i in xrange(nbProc)])
-    assert(asyncResult.get()==nbProc*[0])
-    dsm.removeDataScope(scopeName)
-
-  def setUp(self):
-    salome.salome_init()
-    pass
-  
-  pass
-
-unittest.main()
-
diff --git a/src/SALOMESDS/TestSalomeSDS3.py b/src/SALOMESDS/TestSalomeSDS3.py
deleted file mode 100644 (file)
index fc3fd0f..0000000
+++ /dev/null
@@ -1,25 +0,0 @@
-import SALOME
-import cPickle
-import salome
-import sys
-
-salome.salome_init()
-
-scopeName="Scope1"
-varName="a"
-
-def obj2Str(obj):
-    return cPickle.dumps(obj,cPickle.HIGHEST_PROTOCOL)
-
-def str2Obj(strr):
-    return cPickle.loads(strr)
-
-def waitKey():
-    dsm=salome.naming_service.Resolve("/DataServerManager")
-    dss,isCreated=dsm.giveADataScopeTransactionCalled(scopeName)
-    assert(not isCreated)
-    wk=dss.waitForKeyInVar(varName,obj2Str("ef"))
-    return str2Obj(wk.waitFor())==[11,14,100]
-
-if __name__=="__main__":
-    sys.exit(not int(waitKey()))
diff --git a/src/SALOMESDS/TestSalomeSDSHelper0.py b/src/SALOMESDS/TestSalomeSDSHelper0.py
new file mode 100644 (file)
index 0000000..fc3fd0f
--- /dev/null
@@ -0,0 +1,25 @@
+import SALOME
+import cPickle
+import salome
+import sys
+
+salome.salome_init()
+
+scopeName="Scope1"
+varName="a"
+
+def obj2Str(obj):
+    return cPickle.dumps(obj,cPickle.HIGHEST_PROTOCOL)
+
+def str2Obj(strr):
+    return cPickle.loads(strr)
+
+def waitKey():
+    dsm=salome.naming_service.Resolve("/DataServerManager")
+    dss,isCreated=dsm.giveADataScopeTransactionCalled(scopeName)
+    assert(not isCreated)
+    wk=dss.waitForKeyInVar(varName,obj2Str("ef"))
+    return str2Obj(wk.waitFor())==[11,14,100]
+
+if __name__=="__main__":
+    sys.exit(not int(waitKey()))