本文整理匯總了Python中DIRAC.Resources.Storage.XROOTStorage.XROOTStorage.getDirectory方法的典型用法代碼示例。如果您正苦於以下問題:Python XROOTStorage.getDirectory方法的具體用法?Python XROOTStorage.getDirectory怎麽用?Python XROOTStorage.getDirectory使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類DIRAC.Resources.Storage.XROOTStorage.XROOTStorage
的用法示例。
在下文中一共展示了XROOTStorage.getDirectory方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_getDirectory
# 需要導入模塊: from DIRAC.Resources.Storage.XROOTStorage import XROOTStorage [as 別名]
# 或者: from DIRAC.Resources.Storage.XROOTStorage.XROOTStorage import getDirectory [as 別名]
def test_getDirectory(self):
''' tests the output of getDirectory
'''
global mocked_xrootclient
resource = XROOTStorage('storageName', self.parameterDict)
statusStatDirMock = xrootStatusMock()
statusStatDirMock.makeOk()
statInfoMockDir = xrootStatInfoMock()
statInfoMockDir.makeDir()
statInfoMockFile = xrootStatInfoMock()
statInfoMockFile.size = -1
statInfoMockFile.makeFile()
# Old comment, still true :(
# This dirty thing forces us to know how many time api.stat is called and in what order...
mocked_xrootclient.stat.side_effect = [
(statusStatDirMock,
statInfoMockDir),
(statusStatDirMock,
statInfoMockFile),
(statusStatDirMock,
statInfoMockDir),
(statusStatDirMock,
statInfoMockFile),
(statusStatDirMock,
statInfoMockDir),
(statusStatDirMock,
statInfoMockFile)]
statDir1 = xrootStatInfoMock()
statDir1.makeDir()
statDir1.size = -1
dir1 = xrootListEntryMock("dir1", "host", statDir1)
statDir2 = xrootStatInfoMock()
statDir2.makeDir()
statDir2.size = -1
dir2 = xrootListEntryMock("dir2", "host", statDir2)
statFile1 = xrootStatInfoMock()
statFile1.makeFile()
statFile1.size = -1
file1 = xrootListEntryMock("file1", "host", statFile1)
statFile2 = xrootStatInfoMock()
statFile2.makeFile()
statFile2.size = -1
file2 = xrootListEntryMock("file2", "host", statFile2)
statFile3 = xrootStatInfoMock()
statFile3.makeFile()
statFile3.size = -1
file3 = xrootListEntryMock("file3", "host", statFile3)
directoryListMock1 = xrootDirectoryListMock("parent", [dir1, dir2, file1])
directoryListMock2 = xrootDirectoryListMock("dir1", [file2])
directoryListMock3 = xrootDirectoryListMock("dir1", [file3])
statusMock = xrootStatusMock()
statusMock.makeOk()
mocked_xrootclient.copy.return_value = statusMock, None
mocked_xrootclient.dirlist.side_effect = [
(statusStatDirMock,
directoryListMock1),
(statusStatDirMock,
directoryListMock2),
(statusStatDirMock,
directoryListMock3)]
# This test should get the 3 files
copymock = mock.Mock()
copymock.run.return_value = (statusMock, None)
mocked_xrootd.client.CopyProcess = mock.Mock(return_value=copymock)
# Mock the os calls that access the filesystem and really create the directories locally.
with mock.patch('os.makedirs',
new=MagicMock(return_value=True)), mock.patch('os.remove', new=MagicMock(return_value=True)):
res = resource.getDirectory("A")
self.assertEqual(True, res['OK'])
self.assertEqual({"A": {"Files": 3, "Size": -3}}, res['Value']['Successful'])
self.assertEqual({}, res['Value']['Failed'])
# The copy command is just in error
statusMock.makeError()
mocked_xrootclient.dirlist.side_effect = [
(statusStatDirMock,
directoryListMock1),
(statusStatDirMock,
directoryListMock2),
(statusStatDirMock,
directoryListMock3)]
mocked_xrootclient.stat.side_effect = [
(statusStatDirMock,
statInfoMockDir),
(statusStatDirMock,
statInfoMockFile),
#.........這裏部分代碼省略.........