本文整理匯總了Python中DIRAC.Resources.Storage.XROOTStorage.XROOTStorage.removeDirectory方法的典型用法代碼示例。如果您正苦於以下問題:Python XROOTStorage.removeDirectory方法的具體用法?Python XROOTStorage.removeDirectory怎麽用?Python XROOTStorage.removeDirectory使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類DIRAC.Resources.Storage.XROOTStorage.XROOTStorage
的用法示例。
在下文中一共展示了XROOTStorage.removeDirectory方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_removeDirectory
# 需要導入模塊: from DIRAC.Resources.Storage.XROOTStorage import XROOTStorage [as 別名]
# 或者: from DIRAC.Resources.Storage.XROOTStorage.XROOTStorage import removeDirectory [as 別名]
def test_removeDirectory(self):
''' tests the output of removeDirectory
'''
global mocked_xrootclient
resource = XROOTStorage('storageName', self.parameterDict)
statusStatDirMock = xrootStatusMock()
statusStatDirMock.makeOk()
statInfoMock = xrootStatInfoMock()
statInfoMock.makeDir()
updateStatMockReferences(statusStatDirMock, statInfoMock)
statDir1 = xrootStatInfoMock()
statDir1.makeDir()
statDir1.size = 1
dir1 = xrootListEntryMock("dir1", "host", statDir1)
statDir2 = xrootStatInfoMock()
statDir2.makeDir()
statDir2.size = 2
dir2 = xrootListEntryMock("dir2", "host", statDir2)
statFile1 = xrootStatInfoMock()
statFile1.makeFile()
statFile1.size = 4
file1 = xrootListEntryMock("file1", "host", statFile1)
statFile2 = xrootStatInfoMock()
statFile2.makeFile()
statFile2.size = 8
file2 = xrootListEntryMock("file2", "host", statFile2)
statFile3 = xrootStatInfoMock()
statFile3.makeFile()
statFile3.size = 16
file3 = xrootListEntryMock("file3", "host", statFile3)
directoryListMock1 = xrootDirectoryListMock("parent", [dir1, dir2, file1])
directoryListMock2 = xrootDirectoryListMock("dir1", [file2])
directoryListMock3 = xrootDirectoryListMock("dir2", [file3])
statusMock = xrootStatusMock()
statusMock.makeOk()
mocked_xrootclient.rm.return_value = (statusMock, None)
mocked_xrootclient.rmdir.return_value = (statusMock, None)
# This test should remove file1 only
setMockDirectory(directoryListMock1)
res = resource.removeDirectory("A", recursive=False)
self.assertEqual(True, res['OK'])
self.assertEqual({"A": {"FilesRemoved": 1, "SizeRemoved": 4}}, res['Value']['Successful'])
self.assertEqual({}, res['Value']['Failed'])
mocked_xrootclient.dirlist.side_effect = [
(statusStatDirMock,
directoryListMock1),
(statusStatDirMock,
directoryListMock2),
(statusStatDirMock,
directoryListMock3)]
mocked_xrootclient.stat.side_effect = None
mockDirA = xrootStatInfoMock()
mockDirA.makeDir()
mockDirA.size = 3
tmp_collect_sideeffs = [(statusStatDirMock, mockDirA)]
for entry in directoryListMock1:
tmp_tuple = (statusStatDirMock, entry.statinfo)
tmp_collect_sideeffs.append(tmp_tuple)
for entry in directoryListMock2:
tmp_tuple = (statusStatDirMock, entry.statinfo)
tmp_collect_sideeffs.append(tmp_tuple)
for entry in directoryListMock3:
tmp_tuple = (statusStatDirMock, entry.statinfo)
tmp_collect_sideeffs.append(tmp_tuple)
mocked_xrootclient.stat.side_effect = tmp_collect_sideeffs
# This test should remove the 3 files
res = resource.removeDirectory("A", recursive=True)
self.assertEqual(True, res['OK'])
self.assertEqual({"A": {"FilesRemoved": 3, "SizeRemoved": 28}}, res['Value']['Successful'])
self.assertEqual({}, res['Value']['Failed'])
# The rmdir command fails
statusMock.makeError()
mocked_xrootclient.dirlist.side_effect = None
mocked_xrootclient.dirlist.return_value = statusMock, directoryListMock1
res = resource.removeDirectory("A", recursive=False)
self.assertEqual(True, res['OK'])
self.assertEqual({}, res['Value']['Successful'])
self.assertEqual({"A": {"FilesRemoved": 0, "SizeRemoved": 0}}, res['Value']['Failed'])
# The rmdir command is fatal
statusMock.makeFatal()
mocked_xrootclient.dirlist.side_effect = [(statusStatDirMock, directoryListMock1)]
#.........這裏部分代碼省略.........