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


Python MagicMock.exists方法代码示例

本文整理汇总了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) )
开发者ID:akiyamiyamoto,项目名称:ilddirac,代码行数:33,代码来源:Test_JobInfo.py

示例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'
开发者ID:anukat2015,项目名称:pybossa,代码行数:11,代码来源:test_dashboard_active_anon_week.py

示例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'
开发者ID:codeaudit,项目名称:pybossa,代码行数:11,代码来源:test_dashboard_task_task_run.py

示例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'
开发者ID:fiorda,项目名称:pybossa,代码行数:11,代码来源:test_leaderboard_jobs.py

示例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')
开发者ID:linkdd,项目名称:link.riak,代码行数:21,代码来源:driver.py

示例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)
开发者ID:ntrrgc,项目名称:blockwart,代码行数:12,代码来源:directories_tests.py

示例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)
开发者ID:mfriedenhagen,项目名称:bundlewrap,代码行数:12,代码来源:symlinks_tests.py

示例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)
开发者ID:mfriedenhagen,项目名称:bundlewrap,代码行数:13,代码来源:files_tests.py

示例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'
开发者ID:fiorda,项目名称:pybossa,代码行数:16,代码来源:test_leaderboard_jobs.py

示例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
开发者ID:Sendhub,项目名称:drow,代码行数:16,代码来源:mockriak.py

示例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()
开发者ID:linkdd,项目名称:link.riak,代码行数:17,代码来源:driver.py

示例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()
开发者ID:linkdd,项目名称:link.riak,代码行数:18,代码来源:driver.py

示例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')
开发者ID:linkdd,项目名称:link.riak,代码行数:19,代码来源:driver.py

示例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')
开发者ID:linkdd,项目名称:link.riak,代码行数:26,代码来源:driver.py


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