From 885f89bc3dd828a0a4452be1f6e6a02e444d63d3 Mon Sep 17 00:00:00 2001 From: Anthony Geay Date: Wed, 18 Aug 2021 16:38:10 +0200 Subject: [PATCH] WIP --- .../SALOME_Fake_NamingService.cxx | 38 ++++++++++++++++++- .../SALOME_Fake_NamingService.hxx | 3 ++ src/SALOMESDS/TestSalomeSDS.py | 26 ++++++------- src/SALOMESDS/TestSalomeSDSHelper0.py | 5 --- 4 files changed, 53 insertions(+), 19 deletions(-) diff --git a/src/NamingService/SALOME_Fake_NamingService.cxx b/src/NamingService/SALOME_Fake_NamingService.cxx index e9e19f30d..ce5360833 100644 --- a/src/NamingService/SALOME_Fake_NamingService.cxx +++ b/src/NamingService/SALOME_Fake_NamingService.cxx @@ -72,9 +72,32 @@ void SALOME_Fake_NamingService::Destroy_FullDirectory(const char* Path) bool SALOME_Fake_NamingService::Change_Directory(const char* Path) { + _current_dir = Path; return true; } +std::vector SALOME_Fake_NamingService::SplitDir(const std::string& fullPath) +{ + constexpr char SEP = '/'; + std::vector ret; + if(fullPath.empty()) + THROW_SALOME_EXCEPTION("Empty input string"); + if(fullPath.at(0) != SEP) + THROW_SALOME_EXCEPTION("input string is expected to start with " << SEP); + auto len = fullPath.length(); + if( len == 1 ) + THROW_SALOME_EXCEPTION("input string is expected to be different from " << SEP); + std::size_t pos = 1; + while(pos < len) + { + std::size_t endPos = fullPath.find_first_of(SEP,pos); + std::string elt(fullPath.substr(pos,endPos==std::string::npos?std::string::npos:endPos-pos)); + ret.push_back(elt); + pos = endPos==std::string::npos?std::string::npos:endPos+1; + } + return ret; +} + std::vector SALOME_Fake_NamingService::list_subdirs() { return std::vector(); @@ -82,7 +105,20 @@ std::vector SALOME_Fake_NamingService::list_subdirs() std::vector SALOME_Fake_NamingService::list_directory() { - return std::vector(); + std::vector ret; + std::vector splitCWD(SplitDir(_current_dir)); + auto len = _current_dir.length(); + for(auto it : _map) + { + std::vector splitIt(SplitDir(it.first)); + if(splitIt.size()<=splitCWD.size()) + continue; + std::vector partSplitIt(splitIt.cbegin(),splitIt.cbegin()+splitCWD.size()); + if(partSplitIt!=splitCWD) + continue; + ret.push_back(splitIt.at(splitCWD.size())); + } + return ret; } std::vector SALOME_Fake_NamingService::list_directory_recurs() diff --git a/src/NamingService/SALOME_Fake_NamingService.hxx b/src/NamingService/SALOME_Fake_NamingService.hxx index 295433cfa..a4a10f96b 100644 --- a/src/NamingService/SALOME_Fake_NamingService.hxx +++ b/src/NamingService/SALOME_Fake_NamingService.hxx @@ -56,9 +56,12 @@ private: static std::string ReprOfContainersIORS(); static std::vector< std::pair< std::string, Engines::Container_var> > ListOfContainersInNS_NoThreadSafe(); static void FlushLogContainersFile_NoThreadSafe(); + static std::vector SplitDir(const std::string& fullPath); private: static std::mutex _mutex; static std::map _map; static bool _log_container_file_thread_launched; static std::string _log_container_file_name; +private: + mutable std::string _current_dir; }; diff --git a/src/SALOMESDS/TestSalomeSDS.py b/src/SALOMESDS/TestSalomeSDS.py index d61a9e1ed..9a37b1284 100644 --- a/src/SALOMESDS/TestSalomeSDS.py +++ b/src/SALOMESDS/TestSalomeSDS.py @@ -95,7 +95,7 @@ def func_test7(scopeName,cv,cv2,cv3,sharedNum): class SalomeSDSTest(unittest.TestCase): - def tessList1(self): + def testList1(self): a=SalomeSDSClt.CreateRdExtGlobalVar([],"a","Scope0") self.assertEqual(a.local_copy(),[]) a.append(5) @@ -114,7 +114,7 @@ class SalomeSDSTest(unittest.TestCase): a.ptr().getMyDataScopeServer().deleteVar("a") pass - def tessDict1(self): + def testDict1(self): a=SalomeSDSClt.CreateRdExtGlobalVar({},"a","Scope0") a["ab"]=4 self.assertEqual(a.local_copy(),{"ab":4}) @@ -135,7 +135,7 @@ class SalomeSDSTest(unittest.TestCase): a.ptr().getMyDataScopeServer().deleteVar("a") pass - def tessReadOnly1(self): + 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") @@ -166,13 +166,13 @@ class SalomeSDSTest(unittest.TestCase): # nbProc=8 pool=mp.Pool(processes=nbProc) - from NamingService import NamingService + from NamingService import NamingService asyncResult=pool.map_async(work,[(NamingService.IOROfNS(),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) - def tessTransaction2(self): + def testTransaction2(self): scopeName="Scope1" varName="a" dsm=salome.naming_service.Resolve("/DataServerManager") @@ -196,7 +196,7 @@ class SalomeSDSTest(unittest.TestCase): wk.waitFor() self.assertEqual(str2Obj(dss.waitForMonoThrRev(wk)),[7,8,9,10]) - def tessTransaction3(self): + def testTransaction3(self): scopeName="Scope1" varName="a" dsm=salome.naming_service.Resolve("/DataServerManager") @@ -218,7 +218,7 @@ class SalomeSDSTest(unittest.TestCase): dss.atomicApply([t2]) self.assertEqual(str2Obj(dss.fetchSerializedContent(varName)),{'cd':[7,8,9,10]}) - def tessTransaction4(self): + def testTransaction4(self): scopeName="Scope1" varName="a" dsm=salome.naming_service.Resolve("/DataServerManager") @@ -242,7 +242,7 @@ class SalomeSDSTest(unittest.TestCase): dss.atomicApply([t2]) self.assertEqual(str2Obj(dss.fetchSerializedContent(varName)),{'ab':[4,5,6]}) - def tessTransaction5(self): + def testTransaction5(self): """ Like testTransaction2 but without transactions. """ scopeName="Scope1" varName="a" @@ -276,7 +276,7 @@ class SalomeSDSTest(unittest.TestCase): keys=[str2Obj(elt) for elt in dss.getAllKeysOfVarWithTypeDict(varName)] self.assertEqual(set(keys),set(['ab','cd'])) - def tessTransaction6(self): + def testTransaction6(self): """ Test to test RdWr global vars with transaction""" scopeName="Scope1" varName="a" @@ -325,7 +325,7 @@ class SalomeSDSTest(unittest.TestCase): dsm.removeDataScope(scopeName) pass - def tessTransaction7(self): + def testTransaction7(self): """Like testTransaction5 but after a recovery.""" scopeName="Scope1" varName="a" @@ -349,7 +349,7 @@ class SalomeSDSTest(unittest.TestCase): self.assertEqual(str2Obj(dss.fetchSerializedContent(varName)),{'ab':[4,5,6],'cd':[7,8,9,10]}) pass - def tessTransaction8(self): + def testTransaction8(self): """ EDF 16833 and EDF17719 """ funcContent="""def comptchev(a,b): return "d" not in a @@ -386,7 +386,7 @@ class SalomeSDSTest(unittest.TestCase): self.assertEqual(str2Obj(dss.fetchSerializedContent(varName)),value3) pass - def tessTransaction9(self): + def testTransaction9(self): """ EDF 16833 and EDF17719 : use case 2. Trying to createRdExt during add key session""" funcContent="""def comptchev(a,b): return a==b @@ -416,7 +416,7 @@ class SalomeSDSTest(unittest.TestCase): pass - def tessLockToDump(self): + def testLockToDump(self): """ Test to check that holdRequests method. This method wait for clean server status and hold it until activeRequests is called. Warning this method expects a not overloaded machine to be run because test is based on ellapse time. """ diff --git a/src/SALOMESDS/TestSalomeSDSHelper0.py b/src/SALOMESDS/TestSalomeSDSHelper0.py index d77678b91..7f44e3cd9 100644 --- a/src/SALOMESDS/TestSalomeSDSHelper0.py +++ b/src/SALOMESDS/TestSalomeSDSHelper0.py @@ -39,9 +39,6 @@ def waitKey(IORNS): ns = orb.string_to_object(IORNS) import SALOME dsm = orb.string_to_object(ns.Resolve("/DataServerManager").decode()) - print(400*"$") - print(dsm) - print(type(dsm)) dss,isCreated=dsm.giveADataScopeTransactionCalled(scopeName) assert(not isCreated) wk=dss.waitForKeyInVar(varName,obj2Str("ef")) @@ -50,6 +47,4 @@ def waitKey(IORNS): if __name__=="__main__": IORNS = sys.argv[-1] - print(50*"#") - print(sys.argv) sys.exit(not waitKey(IORNS)) -- 2.39.2