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


Python XROOTStorage.XROOTStorage類代碼示例

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


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

示例1: test_isDirectory

  def test_isDirectory(self):
    """ Check if a path is a directory"""
    global mocked_xrootclient

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

    statusMock = xrootStatusMock()
    statusMock.makeOk()

    statInfoMock = xrootStatInfoMock()
    statInfoMock.makeDir()

    updateStatMockReferences(statusMock, statInfoMock)

    # This test should be successful and True
    res = resource.isDirectory("A")
    self.assertEqual(True, res['OK'])
    self.assertEqual({}, res['Value']['Failed'])
    self.assertEqual({"A": True}, res['Value']['Successful'])

    statInfoMock.makeFile()

    # This test should be successful and False
    res = resource.isDirectory("A")
    self.assertEqual(True, res['OK'])
    self.assertEqual({}, res['Value']['Failed'])
    self.assertEqual({"A": False}, res['Value']['Successful'])
開發者ID:DIRACGrid,項目名稱:DIRAC,代碼行數:27,代碼來源:Test_XROOTStorage.py

示例2: test_getFileMetadata

  def test_getFileMetadata(self):
    "Try to get the metadata of a File"

    global mocked_xrootclient

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

    statusMock = xrootStatusMock()
    statusMock.makeOk()

    statInfoMock = xrootStatInfoMock()
    statInfoMock.makeFile()
    statInfoMock.size = 10

    updateStatMockReferences(statusMock, statInfoMock)

    # This test should be successful and True
    res = resource.getFileMetadata("A")
    self.assertEqual(True, res['OK'])
    self.assertEqual({}, res['Value']['Failed'])

    metaDict = res['Value']['Successful']["A"]
    self.assertEqual(metaDict["Size"], 10)

    # We try on a directory now, it should fail
    statInfoMock.makeDir()

    # This test should be successful and True
    res = resource.getFileMetadata("A")
    self.assertEqual(True, res['OK'])
    self.assertEqual({}, res['Value']['Successful'])
    self.assertEqual("A", res['Value']['Failed'].keys()[0])
開發者ID:DIRACGrid,項目名稱:DIRAC,代碼行數:32,代碼來源:Test_XROOTStorage.py

示例3: test_getDirectorySize

  def test_getDirectorySize(self):
    ''' tests the output of getDirectorySize
    '''

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

    statusMock = xrootStatusMock()
    statusMock.makeOk()

    statInfoMock = xrootStatInfoMock()
    statInfoMock.makeDir()

    updateStatMockReferences(statusMock, statInfoMock)

    statDir1 = xrootStatInfoMock()
    statDir1.makeDir()
    statDir1.size = 1
    dir1 = xrootListEntryMock("dir1", "host", statDir1)

    statFile1 = xrootStatInfoMock()
    statFile1.makeFile()
    statFile1.size = 4
    file1 = xrootListEntryMock("file1", "host", statFile1)

    directoryListMock = xrootDirectoryListMock("parent", [dir1, file1])

    mocked_xrootclient.dirlist.return_value = (statusMock, directoryListMock)

    # We have 1 file (size4) and 1 subdir in the directory
    res = resource.getDirectorySize('A')
    self.assertEqual(True, res['OK'])
    self.assertEqual(1, res['Value']['Successful']["A"]["Files"])
    self.assertEqual(1, res['Value']['Successful']["A"]["SubDirs"])
    self.assertEqual(4, res['Value']['Successful']["A"]["Size"])
    self.assertEqual({}, res['Value']['Failed'])
開發者ID:DIRACGrid,項目名稱:DIRAC,代碼行數:35,代碼來源:Test_XROOTStorage.py

示例4: test_getCurrentURL

  def test_getCurrentURL(self):
    """ Test the current URL of a file"""

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

    res = resource.getCurrentURL("filename")
    self.assertEqual(True, res['OK'])
    self.assertEqual("protocol://host//path/filename", res['Value'])
開發者ID:DIRACGrid,項目名稱:DIRAC,代碼行數:8,代碼來源:Test_XROOTStorage.py

示例5: test_listDirectory

  def test_listDirectory( self ):
    """ Try to list the directory"""
    global mocked_xrootclient

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

    statusMock = xrootStatusMock()
    statusMock.makeOk()

    statInfoMock = xrootStatInfoMock()
    statInfoMock.makeDir()

    updateStatMockReferences( statusMock, 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 )

    directoryListMock = xrootDirectoryListMock( "parent", [dir1, dir2, file1] )

    parentdir = xrootStatInfoMock()
    parentdir.makeDir()

    setMockDirectory(directoryListMock)

    # We created a Directory which contains 2 subdir and 1 file

    res = resource.listDirectory( "A" )
    self.assertEqual( True, res['OK'] )
    self.assertEqual( {}, res['Value']['Failed'] )
    SubDirs = res['Value']['Successful']["A"]["SubDirs"]
    SubFiles = res['Value']['Successful']["A"]["Files"]
    self.assertEqual( 2 , len( SubDirs ) )
    self.assertEqual( 1 , len( SubFiles ) )
    self.assertEqual( SubFiles["root://host/A/file1"]["Size"], 4 )

    #Cleanup old side effect
    mocked_xrootclient.stat.side_effect = None

    # Let's try on a File. It should fail
    statInfoMock.makeFile()
    updateStatMockReferences( infoval = statInfoMock )

    res = resource.listDirectory( "A" )
    self.assertEqual( True, res['OK'] )
    self.assertEqual( {}, res['Value']['Successful'] )
    self.assertEqual( "A" , res['Value']['Failed'].keys()[0] )
開發者ID:ahaupt,項目名稱:DIRAC,代碼行數:58,代碼來源:Test_XROOTStorage.py

示例6: test_getFile

  def test_getFile( self ):
    """ Test the output of getFile"""
    global mocked_xrootclient
    global mocked_xrootd

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

    statusMock = xrootStatusMock()
    statusMock.makeOk()

    mocked_xrootclient.copy.return_value = statusMock, None

    statusStatMock = xrootStatusMock()
    statusStatMock.makeOk()

    statInfoMock = xrootStatInfoMock()
    statInfoMock.makeFile()
    statInfoMock.size = -1

    updateStatMockReferences(statusStatMock, statInfoMock)

    # This test should be completely okay
    copymock = mock.Mock()
    copymock.run.return_value = (statusMock, None)
    mocked_xrootd.client.CopyProcess = mock.Mock(return_value = copymock)
    res = resource.getFile( "a", "/tmp" )
    self.assertEqual( True, res['OK'] )
    self.assertEqual( {"a" :-1}, res['Value']['Successful'] )
    self.assertEqual( {}, res['Value']['Failed'] )


    # Here the sizes should not match
    statInfoMock.size = 1000
    updateStatMockReferences(infoval = statInfoMock)
    res = resource.getFile( "a", "/tmp" )
    self.assertEqual( True, res['OK'] )
    self.assertEqual( {}, res['Value']['Successful'] )
    self.assertEqual( "a", res['Value']['Failed'].keys()[0] )
    statInfoMock.size = -1


    # Here we should not be able to get the file from storage
    statusMock.makeError()
    updateStatMockReferences(statusMock)
    res = resource.getFile( "a", "/tmp" )
    self.assertEqual( True, res['OK'] )
    self.assertEqual( {}, res['Value']['Successful'] )
    self.assertEqual( "a", res['Value']['Failed'].keys()[0] )

    # Fatal error in getting the file from storage
    updateStatMockReferences(statusMock)
    statusMock.makeFatal()
    res = resource.getFile( "a", "/tmp" )
    self.assertEqual( True, res['OK'] )
    self.assertEqual( {}, res['Value']['Successful'] )
    self.assertEqual( "a", res['Value']['Failed'].keys()[0] )
開發者ID:DIRACGrid-test,項目名稱:DIRAC,代碼行數:56,代碼來源:Test_XROOTStorage.py

示例7: test_getParameters

  def test_getParameters(self):
    ''' tests the output of getParameters method
    '''

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

    res = resource.getParameters()
    self.assertEqual('storageName', res['StorageName'])
    self.assertEqual('protocol', res['Protocol'])
    self.assertEqual('/path', res['Path'])
    self.assertEqual('host', res['Host'])
    self.assertEqual(0, res['Port'])
    self.assertEqual('spaceToken', res['SpaceToken'])
    self.assertEqual(0, res['WSUrl'])
開發者ID:DIRACGrid,項目名稱:DIRAC,代碼行數:14,代碼來源:Test_XROOTStorage.py

示例8: test_createDirectory

  def test_createDirectory(self):
    """ Test the create directory  method"""

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

    res = resource.createDirectory({})
    self.assertEqual(True, res['OK'])
    self.assertEqual({}, res['Value']['Successful'])
    self.assertEqual({}, res['Value']['Failed'])

    res = resource.createDirectory({"A": 0})
    self.assertEqual(True, res['OK'])
    self.assertEqual({"A": True}, res['Value']['Successful'])
    self.assertEqual({}, res['Value']['Failed'])

    res = resource.createDirectory("A")
    self.assertEqual(True, res['OK'])
    self.assertEqual({"A": True}, res['Value']['Successful'])
    self.assertEqual({}, res['Value']['Failed'])
開發者ID:DIRACGrid,項目名稱:DIRAC,代碼行數:19,代碼來源:Test_XROOTStorage.py


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