本文整理汇总了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)]
#.........这里部分代码省略.........