当前位置: 首页>>代码示例>>Python>>正文


Python XROOTStorage.getDirectory方法代码示例

本文整理汇总了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),
#.........这里部分代码省略.........
开发者ID:DIRACGrid,项目名称:DIRAC,代码行数:103,代码来源:Test_XROOTStorage.py


注:本文中的DIRAC.Resources.Storage.XROOTStorage.XROOTStorage.getDirectory方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。