bool SALOME_Fake_NamingService::Change_Directory(const char* Path)
{
+ _current_dir = Path;
return true;
}
+std::vector<std::string> SALOME_Fake_NamingService::SplitDir(const std::string& fullPath)
+{
+ constexpr char SEP = '/';
+ std::vector<std::string> 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<std::string> SALOME_Fake_NamingService::list_subdirs()
{
return std::vector<std::string>();
std::vector<std::string> SALOME_Fake_NamingService::list_directory()
{
- return std::vector<std::string>();
+ std::vector<std::string> ret;
+ std::vector<std::string> splitCWD(SplitDir(_current_dir));
+ auto len = _current_dir.length();
+ for(auto it : _map)
+ {
+ std::vector<std::string> splitIt(SplitDir(it.first));
+ if(splitIt.size()<=splitCWD.size())
+ continue;
+ std::vector<std::string> partSplitIt(splitIt.cbegin(),splitIt.cbegin()+splitCWD.size());
+ if(partSplitIt!=splitCWD)
+ continue;
+ ret.push_back(splitIt.at(splitCWD.size()));
+ }
+ return ret;
}
std::vector<std::string> SALOME_Fake_NamingService::list_directory_recurs()
class SalomeSDSTest(unittest.TestCase):
- def tessList1(self):
+ def testList1(self):
a=SalomeSDSClt.CreateRdExtGlobalVar([],"a","Scope0")
self.assertEqual(a.local_copy(),[])
a.append(5)
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})
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")
#
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")
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")
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")
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"
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"
dsm.removeDataScope(scopeName)
pass
- def tessTransaction7(self):
+ def testTransaction7(self):
"""Like testTransaction5 but after a recovery."""
scopeName="Scope1"
varName="a"
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
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
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.
"""