本文整理汇总了Python中mock.MagicMock.exists方法的典型用法代码示例。如果您正苦于以下问题:Python MagicMock.exists方法的具体用法?Python MagicMock.exists怎么用?Python MagicMock.exists使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mock.MagicMock
的用法示例。
在下文中一共展示了MagicMock.exists方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_checkFileExistance
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import exists [as 别名]
def test_checkFileExistance( self ):
"""ILCTransformation.Utilities.JobInfo.checkFileExistance......................................."""
fcMock = Mock( name="fcMock", spec=DIRAC.Resources.Catalog.FileCatalogClient.FileCatalogClient )
## input and output files
repStatus = { "Successful": { "inputFile": True, "outputFile1": False, "outputFile2": True } }
self.jbi.inputFile = "inputFile"
self.jbi.outputFiles = ["outputFile1", "outputFile2", "unknownFile"]
fcMock.exists = Mock( return_value = S_OK( repStatus ) )
self.jbi.checkFileExistance( fcMock )
self.assertTrue( self.jbi.inputFileExists )
self.assertEqual( self.jbi.outputFileStatus, ["Missing", "Exists", "Unknown"] )
## just output files
self.setUp()
repStatus = { "Successful": { "inputFile": True, "outputFile1": False, "outputFile2": True } }
self.jbi.inputFile = ""
self.jbi.outputFiles = ["outputFile1", "outputFile2", "unknownFile"]
fcMock.exists.return_value = S_OK( repStatus )
self.jbi.checkFileExistance( fcMock )
self.assertEqual( self.jbi.outputFileStatus, ["Missing", "Exists", "Unknown"] )
## fcClient Error
self.setUp()
repStatus = { "Successful": { "inputFile": True, "outputFile1": False, "outputFile2": True } }
self.jbi.inputFile = ""
self.jbi.outputFiles = ["outputFile1", "outputFile2", "unknownFile"]
fcMock.exists.return_value = S_ERROR( "No FC" )
with self.assertRaises( RuntimeError ) as cme:
self.jbi.checkFileExistance( fcMock )
self.assertIn( "Failed to check existance: No FC", str(cme.exception) )
示例2: test_materialized_view_created
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import exists [as 别名]
def test_materialized_view_created(self, db_mock):
"""Test JOB dashboard materialized view is created."""
result = MagicMock()
result.exists = False
results = [result]
db_mock.slave_session.execute.return_value = results
res = active_anon_week()
assert db_mock.session.commit.called
assert res == 'Materialized view created'
示例3: test_materialized_view_refreshed
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import exists [as 别名]
def test_materialized_view_refreshed(self, db_mock):
"""Test JOB dashboard materialized view is refreshed."""
result = MagicMock()
result.exists = True
results = [result]
db_mock.slave_session.execute.return_value = results
res = new_task_runs_week()
assert db_mock.session.execute.called
assert res == 'Materialized view refreshed'
示例4: test_materialized_view_refreshed_concurrently
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import exists [as 别名]
def test_materialized_view_refreshed_concurrently(self, db_mock):
"""Test JOB leaderboard materialized view is refreshed."""
result = MagicMock()
result.exists = True
results = [result]
db_mock.slave_session.execute.return_value = results
res = leaderboard()
assert db_mock.session.execute.called
assert res == 'Materialized view refreshed concurrently'
示例5: test_exists
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import exists [as 别名]
def test_exists(self):
obj = MagicMock()
bucket = MagicMock()
bucket.get.return_value = obj
self.conn.bucket.return_value = bucket
self._instanciate()
self.drv.connect()
obj.exists = True
result = self.drv._exists(self.drv.conn, 'key')
self.assertTrue(result)
bucket.get.assert_called_with('key')
obj.exists = False
result = self.drv._exists(self.drv.conn, 'key')
self.assertFalse(result)
bucket.get.assert_called_with('key')
示例6: test_type
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import exists [as 别名]
def test_type(self, fix_type, fix_owner, fix_mode):
f = directories.Directory(MagicMock(), "/", {})
pinfo = MagicMock()
pinfo.exists = False
status = ItemStatus(correct=False, info={
'path_info': pinfo,
'needs_fixing': ['type', 'mode', 'owner'],
})
f.fix(status)
fix_type.assert_called_once_with(status)
示例7: test_type
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import exists [as 别名]
def test_type(self, fix_type, fix_owner):
f = symlinks.Symlink(MagicMock(), "/foo", {'target': "/bar"})
pinfo = MagicMock()
pinfo.exists = False
status = ItemStatus(correct=False, info={
'path_info': pinfo,
'needs_fixing': ['type', 'owner'],
})
f.fix(status)
fix_type.assert_called_once_with(status)
示例8: test_type
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import exists [as 别名]
def test_type(self, fix_type, fix_owner, fix_mode, fix_content):
f = files.File(MagicMock(), "/foo", {})
pinfo = MagicMock()
pinfo.exists = False
status = ItemStatus(correct=False, info={
'path_info': pinfo,
'needs_fixing': ['type', 'content', 'mode', 'owner'],
})
f.fix(status)
fix_type.assert_called_once_with(status)
fix_content.assert_called_once_with(status)
示例9: test_materialized_view_refreshed
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import exists [as 别名]
def test_materialized_view_refreshed(self, db_mock, exists_mock):
"""Test JOB leaderboard materialized view is refreshed."""
result = MagicMock()
result.exists = True
results = [result]
exists_mock.return_value = True
db_mock.slave_session.execute.side_effect = results
db_mock.session.execute.side_effect = [ProgrammingError('foo',
'bar',
'bar'),
True]
res = leaderboard()
assert db_mock.session.execute.called
assert res == 'Materialized view refreshed'
示例10: create_mock_riak_object
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import exists [as 别名]
def create_mock_riak_object(key=None, update_time=None):
riak_object = MagicMock()
riak_object.key = key
riak_object.exists = True
riak_object.data = None
riak_object.encoded_data = None
riak_object.content_type = 'application/json'
if not update_time:
update_time = time()
riak_object.last_modified = update_time
riak_object.siblings = []
riak_object.store.return_value = riak_object
return riak_object
示例11: test_remove
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import exists [as 别名]
def test_remove(self):
obj = MagicMock()
obj.exists = True
bucket = MagicMock()
bucket.get.return_value = obj
self.conn.bucket.return_value = bucket
self._instanciate()
self.drv.connect()
self.drv._remove(self.drv.conn, 'key')
bucket.get.assert_called_with('key')
obj.delete.assert_called_with()
示例12: test_remove_fail
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import exists [as 别名]
def test_remove_fail(self):
obj = MagicMock()
obj.exists = False
bucket = MagicMock()
bucket.get.return_value = obj
self.conn.bucket.return_value = bucket
self._instanciate()
self.drv.connect()
with self.assertRaises(KeyError):
self.drv._remove(self.drv.conn, 'key')
bucket.get.assert_called_with('key')
obj.delete.assert_not_called()
示例13: test_get
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import exists [as 别名]
def test_get(self):
obj = MagicMock()
obj.__class__ = RiakObject
obj.exists = True
obj.data = 'expected'
bucket = MagicMock()
bucket.get.return_value = obj
self.conn.bucket.return_value = bucket
self._instanciate()
self.drv.connect()
result = self.drv._get(self.drv.conn, 'key')
self.assertEqual(result, 'expected')
bucket.get.assert_called_with('key')
示例14: test_get_fail
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import exists [as 别名]
def test_get_fail(self):
obj = MagicMock()
obj.__class__ = RiakObject
obj.exists = False
bucket = MagicMock()
bucket.get.return_value = obj
self.conn.bucket.return_value = bucket
self._instanciate()
self.drv.connect()
with self.assertRaises(KeyError):
self.drv._get(self.drv.conn, 'key')
bucket.get.assert_called_with('key')
obj = MagicMock()
bucket.get.return_value = obj
with self.assertRaises(KeyError):
self.drv._get(self.drv.conn, 'key')
bucket.get.assert_called_with('key')