本文整理汇总了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'])
示例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])
示例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'])
示例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'])
示例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] )
示例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] )
示例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'])
示例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'])