• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python patch.stopall函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中mock.patch.stopall函数的典型用法代码示例。如果您正苦于以下问题:Python stopall函数的具体用法?Python stopall怎么用?Python stopall使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了stopall函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: mock_request

 def mock_request(self, username, task):
     """
     Patch get_object_or_404 to return given task.
     Yield Mock request as context variable.
     """
     patch("scores.views.get_object_or_404", Mock(side_effect=lambda *a, **k: task)).start()
     yield Mock(user=self.users[username], method="GET", is_ajax=lambda: True, GET={"task_id": 1})
     patch.stopall()
开发者ID:btbroot,项目名称:exmo2010,代码行数:8,代码来源:tests.py


示例2: teardown_scenario

def teardown_scenario(scenario):
    """
    Empty the temporary directory and restore the working directory.
    """
    # remove the scenario variables
    del world.scenario

    # Remove the fixtures directory
    shutil.rmtree(world.fixtures_dir)

    # Restore the current working directory
    os.chdir(world.old_cwd)

    # Uninstall all mocks
    patch.stopall()
开发者ID:bharatmooc,项目名称:js-test-tool,代码行数:15,代码来源:terrain.py


示例3: _patched

        def _patched(*args, **kwargs):
            try:
                for patch in patches:
                    mock = patch.start()
                    if isinstance(mock.kwargs_field, str):
                        kwargs[mock.kwargs_field] = mock

                # Merge additional fields into kwargs with kwargs taking precedence
                kwargs = dict(additional_fields.items() + kwargs.items())

                retval = func(*args, **kwargs)
            finally:
                Patch.stopall()

            return retval
开发者ID:Angakkuit,项目名称:asiaq-aws,代码行数:15,代码来源:patcher.py


示例4: test__method

    def test__method(self):
        """ Test Api._method rest submission """
        ret = {'test': 'val'}
        ret_val = RequestRet(content=json_dumps(ret).encode('utf-8'),
                             status_code=200)
        post = patch('requests.post', return_value=ret_val).start()
        delete = patch('requests.delete', return_value=ret_val).start()
        get = patch('requests.get', return_value=ret_val).start()

        # pylint:disable=protected-access
        _auth = Mock()

        # call get
        ret = rest.Api._method(self._url)
        get.assert_called_with(self._url, auth=None)
        self.assertEquals(ret, ret)
        ret = rest.Api._method(self._url, method='GET', auth=_auth)
        get.assert_called_with(self._url, auth=_auth)
        self.assertEquals(ret, ret)

        # call delete
        ret = rest.Api._method(self._url, method='DELETE')
        delete.assert_called_with(self._url, auth=None)
        self.assertEquals(ret, ret)

        # call post
        ret = rest.Api._method(self._url, method='POST', data={})
        post.assert_called_with(
            self._url, data='{}'.encode('utf-8'),
            headers={'content-type': 'application/json'},
            auth=None)
        self.assertEquals(ret, ret)

        # call multipart
        _files = {'entry': '{}'}
        ret = rest.Api._method(self._url, method='MULTIPART', data=_files)
        post.assert_called_with(self._url, files=_files, auth=None)
        self.assertEquals(ret, ret)
        patch.stopall()
开发者ID:adjih,项目名称:cli-tools,代码行数:39,代码来源:rest_test.py


示例5: tearDown

 def tearDown(self):
     super(FakeFSTest, self).tearDown()
     patch.stopall()
开发者ID:mathcamp,项目名称:devbox,代码行数:3,代码来源:__init__.py


示例6: tearDown

 def tearDown(self):
     cache.clear()
     patch.stopall()
开发者ID:globocom,项目名称:iaas-usage,代码行数:3,代码来源:tests.py


示例7: tearDown

 def tearDown(self):
     super(TestBasicAuthPolicy, self).tearDown()
     patch.stopall()
开发者ID:philwhln,项目名称:pypicloud,代码行数:3,代码来源:test_auth.py


示例8: tearDown

 def tearDown(self):
     super(TestGoogleCloudStorage, self).tearDown()
     patch.stopall()
开发者ID:mathcamp,项目名称:pypicloud,代码行数:3,代码来源:test_storage.py


示例9: tearDown

 def tearDown(self):
     super(TestAuth, self).tearDown()
     patch.stopall()
开发者ID:stevearc,项目名称:pyramid_duh,代码行数:3,代码来源:test_auth.py


示例10: teardown_module

def teardown_module(module):
    """Stop patches and enable logging output"""
    patch.stopall()
    logging.disable(logging.NOTSET)
开发者ID:openpermissions,项目名称:koi,代码行数:4,代码来源:test_base.py


示例11: teardown

    def teardown(self):
        super(BaseDealerTest, self).teardown()
        patch.stopall()

        # Reset dealer instance.
        self.dealer = None
开发者ID:nivbend,项目名称:bdd_bot,代码行数:6,代码来源:test_dealer.py


示例12: tearDown

 def tearDown(self):
     try:
         os.remove(TEST_RC_FILE)
     except OSError:
         pass
     patch.stopall()
开发者ID:adjih,项目名称:cli-tools,代码行数:6,代码来源:auth_test.py


示例13: tearDown

 def tearDown(self):
   patch.stopall()
   if path.exists(TEST_WORKSPACE):
     shutil.rmtree(TEST_WORKSPACE)
开发者ID:dnalborczyk,项目名称:node,代码行数:4,代码来源:run_perf_test.py


示例14: tearDown

 def tearDown(self):
     unittest.TestCase.tearDown(self)
     patch.stopall()
开发者ID:SpamExperts,项目名称:spoon,代码行数:3,代码来源:test_server.py


示例15: tearDownModule

def tearDownModule():
    patch.stopall()
开发者ID:takesxi-shimada,项目名称:versionah,代码行数:2,代码来源:test_errors.py


示例16: tearDown

 def tearDown(self):
     super(TestS3Storage, self).tearDown()
     patch.stopall()
     self.s3_mock.stop()
开发者ID:philwhln,项目名称:pypicloud,代码行数:4,代码来源:test_storage.py


示例17: kill_patches

 def kill_patches():
     patch.stopall()
     imp.reload(repository_module)
开发者ID:jpalanco,项目名称:alienvault-ossim,代码行数:3,代码来源:alchemy_test_case.py


示例18: tearDownClass

 def tearDownClass(cls):
     patch.stopall()
开发者ID:drtyhbo,项目名称:rockstor-core,代码行数:2,代码来源:test_api.py


示例19: test_solve_captcha

def test_solve_captcha(app):

    m = 'controllers.solve'
    check_request = _patch("%s.check_request" % m)
    decaptcher_response = _patch("%s.decaptcher_response" % m)
    solvers = _patch("%s.solvers" % m)
    check_solver = _patch("%s.check_solver" % m)
    storage = _patch("%s.RedisStorage" % m)()

    solve = MagicMock()
    solvers.get_highest_notblocked.return_value.__getitem__.return_value\
            = solvers.get_by_name.return_value.__getitem__.return_value\
            = solvers.get_next.return_value.__getitem__.return_value\
            = solve

    pict = Upload('captcha.png', 'picture_binary_data')
    some_data = {'pict': pict}

    # моделирование запроса с невалидными POST-данными
    check_request.return_value = "error description"
    decaptcher_response.return_value = "error"
    app.post('/', some_data)
    #
    assert check_request.called
    assert decaptcher_response.called
    assert not solve.called
    reset_mocks(locals())

    # моделирование запроса с валидными POST-данными
    # без явного указания сервиса-расшифровщика
    check_request.return_value = None
    check_solver.side_effect = ["errcode", None]
    solve.side_effect = [SolverError, "captchacode1"]
    decaptcher_response.return_value = "resp1"
    app.post('/', some_data)
    #
    assert solvers.get_highest_notblocked.call_count == 2
    assert not solvers.get_by_name.called
    assert check_solver.call_count == 2
    assert storage.block.call_count == 1
    assert storage.incr_uses.call_count == 2
    assert solve.call_count == 2
    assert storage.incr_fails.call_count == 1
    assert solvers.get_next.call_count == 1
    assert decaptcher_response.called
    reset_mocks(locals())
    check_solver.side_effect = None

    # моделирование запроса с валидными POST-данными
    # с явным указанием сервиса-расшифровщика
    check_request.return_value = None
    decaptcher_response.return_value = "resp2"
    solve.side_effect = ["captchacode2"]
    app.post('/?upstream_service=captchabot', some_data)
    #
    assert solvers.get_by_name.called
    assert not solvers.get_highest_notblocked.called
    assert not check_solver.called
    assert storage.incr_uses.call_count == 1
    assert solve.call_count == 1
    assert not storage.incr_fails.called
    assert not solvers.get_next.called
    assert decaptcher_response.called
    reset_mocks(locals())
    check_solver.side_effect = None

    # моделирование случая, при котором число попыток
    # расшифровать капчу превышает допустимое
    check_request.return_value = None
    check_solver.return_value = None
    solve.side_effect = SolverError
    decaptcher_response.return_value = "resp1"
    app.post('/', some_data)
    #
    assert storage.incr_uses.call_count\
            == storage.incr_fails.call_count\
            == solve.call_count\
            == solvers.get_next.call_count\
            == settings.MAX_ATTEMPTS_TO_SOLVE
    assert decaptcher_response.called
    reset_mocks(locals())

    # проверяем, что параметры "pict_type" и "pict" передаются в расшифровщик
    some_data = {'pict': pict, 'pict_type': 'some_type'}
    check_request.return_value = None
    check_solver.return_value = None
    solve.side_effect = None
    decaptcher_response.return_value = "resp1"
    app.post('/', some_data)
    #
    assert solve.call_args[1]['pict_type'] == some_data['pict_type']
    reset_mocks(locals())

    patch.stopall()
开发者ID:maxpmaxp,项目名称:decaptcher,代码行数:94,代码来源:test_app.py


示例20: tearDown

 def tearDown(self):
     patch.stopall()
     sys.stderr = sys.__stderr__
开发者ID:belonesox,项目名称:subscription-manager,代码行数:3,代码来源:test_migration.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python mock_args_container.MockClass类代码示例发布时间:2022-05-27
下一篇:
Python patch.object函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap