當前位置: 首頁>>代碼示例>>Python>>正文


Python XROOTStorage.putDirectory方法代碼示例

本文整理匯總了Python中DIRAC.Resources.Storage.XROOTStorage.XROOTStorage.putDirectory方法的典型用法代碼示例。如果您正苦於以下問題:Python XROOTStorage.putDirectory方法的具體用法?Python XROOTStorage.putDirectory怎麽用?Python XROOTStorage.putDirectory使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在DIRAC.Resources.Storage.XROOTStorage.XROOTStorage的用法示例。


在下文中一共展示了XROOTStorage.putDirectory方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_putDirectory

# 需要導入模塊: from DIRAC.Resources.Storage.XROOTStorage import XROOTStorage [as 別名]
# 或者: from DIRAC.Resources.Storage.XROOTStorage.XROOTStorage import putDirectory [as 別名]
  def test_putDirectory(self):
    ''' tests the output of putDirectory
    '''
    global mocked_xrootclient

    # I again try to have 2 subdirs, and 1 file per subdir and 1 file a the root

    resource = XROOTStorage('storageName', self.parameterDict)

    statusCopyMock = xrootStatusMock()
    statusCopyMock.makeOk()

    mocked_xrootclient.copy.return_value = statusCopyMock, None

    statusMkDirMock = xrootStatusMock()
    statusMkDirMock.makeOk()

    mocked_xrootclient.mkdir.return_value = statusMkDirMock, None

    statusRmMock = xrootStatusMock()
    statusRmMock.makeOk()

    mocked_xrootclient.rm.return_value = statusRmMock, None

    statusStatMock = xrootStatusMock()
    statusStatMock.makeOk()
    statInfoMock = xrootStatInfoMock()
    statInfoMock.makeFile()
    statInfoMock.size = 1

    updateStatMockReferences(statusStatMock, statInfoMock)

    # This test should upload the 3 files
    copymock = mock.Mock()
    copymock.run.return_value = statusCopyMock, None
    mocked_xrootd.client.CopyProcess = mock.Mock(return_value=copymock)
    res = resource.putDirectory({"remoteA": "localA"})
    self.assertEqual(True, res['OK'])
    self.assertEqual({"remoteA": {"Files": 3, "Size": 3}}, res['Value']['Successful'])
    self.assertEqual({}, res['Value']['Failed'])

    # The copy command is just in error
    statusCopyMock.makeError()
    copymock.run.return_value = statusCopyMock, None
    mocked_xrootd.client.CopyProcess = mock.Mock(return_value=copymock)
    with mock.patch('os.path.isdir',
                    new=MagicMock(side_effect=[True,
                                               True,
                                               True,
                                               False,
                                               True,
                                               True,
                                               False,
                                               False])), mock.patch('os.listdir',
                                                                    new=MagicMock(side_effect=[("dir1",
                                                                                                "dir2",
                                                                                                "file1"),
                                                                                  ("file2", ), ("file3", )])):
      res = resource.putDirectory({"remoteA": "localA"})
    self.assertEqual(True, res['OK'])
    self.assertEqual({}, res['Value']['Successful'])
    self.assertEqual({"remoteA": {"Files": 0, "Size": 0}}, res['Value']['Failed'])

    # The copy command is fatal
    statusCopyMock.makeFatal()
    copymock.run.return_value = statusCopyMock, None
    mocked_xrootd.client.CopyProcess = mock.Mock(return_value=copymock)
    with mock.patch('os.path.isdir',
                    new=MagicMock(side_effect=[True,
                                               True,
                                               True,
                                               False,
                                               True,
                                               True,
                                               False,
                                               False])), mock.patch('os.listdir',
                                                                    new=MagicMock(side_effect=[("dir1",
                                                                                                "dir2",
                                                                                                "file1"),
                                                                                  ("file2", ), ("file3", )])):
      res = resource.putDirectory({"remoteA": "localA"})
    self.assertEqual(True, res['OK'])
    self.assertEqual({}, res['Value']['Successful'])
    self.assertEqual({"remoteA": {"Files": 0, "Size": 0}}, res['Value']['Failed'])
開發者ID:DIRACGrid,項目名稱:DIRAC,代碼行數:86,代碼來源:Test_XROOTStorage.py


注:本文中的DIRAC.Resources.Storage.XROOTStorage.XROOTStorage.putDirectory方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。