From: Paul RASCLE Date: Thu, 18 Jan 2018 14:14:44 +0000 (+0100) Subject: debug TestSalomeSDS: replacement for python2 builtin cmp was not OK. X-Git-Tag: V9_0_0~2 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=4b17c7f13cac993b19965a07433c77a2d0d9bd86;p=modules%2Fkernel.git debug TestSalomeSDS: replacement for python2 builtin cmp was not OK. --- diff --git a/src/SALOMESDS/SALOMESDS_DataScopeServer.cxx b/src/SALOMESDS/SALOMESDS_DataScopeServer.cxx index 8d2ffe575..d1044d761 100644 --- a/src/SALOMESDS/SALOMESDS_DataScopeServer.cxx +++ b/src/SALOMESDS/SALOMESDS_DataScopeServer.cxx @@ -683,16 +683,25 @@ void DataScopeServerTransaction::pingKey(PyObject *keyObj) { std::size_t ii(0); // this part does nothing except to be sure that in notify key all will be OK. + PyObject *args(PyTuple_New(1)); + PyTuple_SetItem(args,0,keyObj); Py_XINCREF(keyObj); for(std::list< KeyWaiter *>::iterator it=_waiting_keys.begin();it!=_waiting_keys.end();it++,ii++) { PyObject *waitKey((*it)->getKeyPyObj()); - PyObject *res(PyObject_CallMethodObjArgs(keyObj, PyUnicode_DecodeASCII("__ne__", 6, NULL), waitKey)); + PyObject *meth(PyObject_GetAttrString(keyObj,"__eq__")); + if(!meth) + { + std::ostringstream oss; oss << "DataScopeServerTransaction::pingKey : for object id #" << ii << " no __eq__ in pyobj !"; + throw Exception(oss.str()); + } + PyObject *res(PyObject_CallObject(meth,args)); + Py_XDECREF(meth); if(res==NULL) { std::ostringstream oss; oss << "DataScopeServerTransaction::pingKey : for object id #" << ii << " error during cmp(k,wk[i]) !"; throw Exception(oss.str()); } - PyLong_AsLong(res); // res is bool, but it s ok since __int__ is called + PyBool_Check(res); if(PyErr_Occurred()) { std::ostringstream oss; oss << "DataScopeServerTransaction::pingKey : for object id #" << ii << " error during interpretation of cmp(k,wk[i]) !"; @@ -700,11 +709,14 @@ void DataScopeServerTransaction::pingKey(PyObject *keyObj) } Py_XDECREF(res); } + Py_XDECREF(args); } void DataScopeServerTransaction::notifyKey(const std::string& varName, PyObject *keyObj, PyObject *valueObj) { std::size_t ii(0); + PyObject *args(PyTuple_New(1)); + PyTuple_SetItem(args,0,keyObj); Py_XINCREF(keyObj); std::list< KeyWaiter *> newList,listOfEltToWakeUp; for(std::list< KeyWaiter *>::iterator it=_waiting_keys.begin();it!=_waiting_keys.end();it++,ii++) { @@ -714,24 +726,31 @@ void DataScopeServerTransaction::notifyKey(const std::string& varName, PyObject continue; } PyObject *waitKey((*it)->getKeyPyObj()); - PyObject *res(PyObject_CallMethodObjArgs(keyObj, PyUnicode_DecodeASCII("__ne__", 6, NULL), waitKey)); - if(res==NULL) - { - std::ostringstream oss; oss << "DataScopeServerTransaction::notifyKey : MAIN INTERNAL ERROR ! for object id #" << ii << " error during cmp(k,wk[i]) !"; - throw Exception(oss.str()); - } - long resCpp(PyLong_AsLong(res)); // res is bool, but it s ok since __int__ is called + PyObject *meth(PyObject_GetAttrString(keyObj,"__eq__")); + if(!meth) + { + std::ostringstream oss; oss << "DataScopeServerTransaction::pingKey : for object id #" << ii << " no __eq__ in pyobj !"; + throw Exception(oss.str()); + } + PyObject *res(PyObject_CallObject(meth,args)); + Py_XDECREF(meth); + if(!PyBool_Check(res)) + { + std::ostringstream oss; oss << "DataScopeServerTransaction::pingKey : for object id #" << ii << " no __eq__ in pyobj !"; + throw Exception(oss.str()); + } if(PyErr_Occurred()) { std::ostringstream oss; oss << "DataScopeServerTransaction::notifyKey : MAIN INTERNAL ERROR ! for object id #" << ii << " error during interpretation of cmp(k,wk[i]) !"; throw Exception(oss.str()); } - Py_XDECREF(res); - if(resCpp==0) + if(res==Py_True) listOfEltToWakeUp.push_back(*it); else newList.push_back(*it); + Py_XDECREF(res); } + Py_XDECREF(args); for(std::list< KeyWaiter *>::iterator it=listOfEltToWakeUp.begin();it!=listOfEltToWakeUp.end();it++) (*it)->valueJustCome(valueObj); for(std::list< KeyWaiter *>::iterator it=listOfEltToWakeUp.begin();it!=listOfEltToWakeUp.end();it++) diff --git a/src/SALOMESDS/TestSalomeSDS.py b/src/SALOMESDS/TestSalomeSDS.py index 67bc42b2b..3caceef90 100644 --- a/src/SALOMESDS/TestSalomeSDS.py +++ b/src/SALOMESDS/TestSalomeSDS.py @@ -54,8 +54,10 @@ def work(t): proc = subprocess.Popen(["python3", fname], stdout=subprocess.PIPE, stderr=subprocess.PIPE) out,err=proc.communicate() if proc.returncode!=0: + print("-------------- work -----------") print(out) print(err) + print("~~~~~~~~~~~~~~ work ~~~~~~~~~~~") return proc.returncode def func_test7(scopeName,l,l2,cv): @@ -160,6 +162,7 @@ class SalomeSDSTest(unittest.TestCase): nbProc=8 pool=mp.Pool(processes=nbProc) asyncResult=pool.map_async(work,[(i,varName,scopeName) for i in range(nbProc)]) + print("asyncResult=", asyncResult) self.assertEqual(asyncResult.get(),nbProc*[0]) # <- the big test is here ! dsm.removeDataScope(scopeName) @@ -265,7 +268,7 @@ class SalomeSDSTest(unittest.TestCase): wk.waitFor() self.assertEqual(str2Obj(dss.waitForMonoThrRev(wk)),[7,8,9,10]) keys=[str2Obj(elt) for elt in dss.getAllKeysOfVarWithTypeDict(varName)] - self.assertEqual(keys,['ab','cd']) + self.assertEqual(set(keys),set(['ab','cd'])) def testTransaction6(self): """ Test to test RdWr global vars with transaction"""