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


Python patch.dict方法代碼示例

本文整理匯總了Python中unittest.mock.patch.dict方法的典型用法代碼示例。如果您正苦於以下問題:Python patch.dict方法的具體用法?Python patch.dict怎麽用?Python patch.dict使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在unittest.mock.patch的用法示例。


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

示例1: test_succeeds_if_source_is_master

# 需要導入模塊: from unittest.mock import patch [as 別名]
# 或者: from unittest.mock.patch import dict [as 別名]
def test_succeeds_if_source_is_master(self, mocks_factory):
        mocklab, api, job = mocks_factory(
            extra_mocklab_opts=dict(merge_request_options={
                'source_branch': 'master',
                'target_branch': 'production',
            }),
        )
        api.add_transition(
            GET(
                '/projects/1234/repository/branches/{source}'.format(
                    source=mocklab.merge_request_info['source_branch'],
                ),
            ),
            Ok({'commit': {'id': mocklab.rewritten_sha}}),
            from_state='initial', to_state='pushed',
        )
        job.execute()

        assert api.state == 'merged'
        assert api.notes == [] 
開發者ID:smarkets,項目名稱:marge-bot,代碼行數:22,代碼來源:test_single_job.py

示例2: test_handles_races_for_merging

# 需要導入模塊: from unittest.mock import patch [as 別名]
# 或者: from unittest.mock.patch import dict [as 別名]
def test_handles_races_for_merging(self, mocks):
        mocklab, api, job = mocks
        rewritten_sha = mocklab.rewritten_sha
        api.add_transition(
            PUT(
                '/projects/1234/merge_requests/{iid}/merge'.format(iid=mocklab.merge_request_info['iid']),
                dict(sha=rewritten_sha, should_remove_source_branch=True, merge_when_pipeline_succeeds=True),
            ),
            Error(marge.gitlab.NotFound(404, {'message': '404 Branch Not Found'})),
            from_state='passed', to_state='someone_else_merged',
        )
        api.add_merge_request(
            dict(mocklab.merge_request_info, state='merged'),
            from_state='someone_else_merged',
        )
        job.execute()
        assert api.state == 'someone_else_merged'
        assert api.notes == [] 
開發者ID:smarkets,項目名稱:marge-bot,代碼行數:20,代碼來源:test_single_job.py

示例3: test_calculates_merge_when_pipeline_succeeds_correctly

# 需要導入模塊: from unittest.mock import patch [as 別名]
# 或者: from unittest.mock.patch import dict [as 別名]
def test_calculates_merge_when_pipeline_succeeds_correctly(
        self, mocks, only_allow_merge_if_pipeline_succeeds
    ):
        mocklab, api, job = mocks
        rewritten_sha = mocklab.rewritten_sha
        project_info = dict(TEST_PROJECT_INFO)
        project_info["only_allow_merge_if_pipeline_succeeds"] = only_allow_merge_if_pipeline_succeeds
        api.add_project(project_info)
        api.add_transition(
            PUT(
                '/projects/{pid}/merge_requests/{iid}/merge'.format(
                    iid=mocklab.merge_request_info['iid'],
                    pid=project_info["id"]
                ),
                dict(
                    sha=rewritten_sha,
                    should_remove_source_branch=True,
                    merge_when_pipeline_succeeds=only_allow_merge_if_pipeline_succeeds
                ),
            ),
            Ok(True),
            to_state='merged',
        )
        job.execute()
        assert api.state == 'merged' 
開發者ID:smarkets,項目名稱:marge-bot,代碼行數:27,代碼來源:test_single_job.py

示例4: test_handles_request_becoming_wip_after_push

# 需要導入模塊: from unittest.mock import patch [as 別名]
# 或者: from unittest.mock.patch import dict [as 別名]
def test_handles_request_becoming_wip_after_push(self, mocks):
        mocklab, api, job = mocks
        rewritten_sha = mocklab.rewritten_sha
        api.add_transition(
            PUT(
                '/projects/1234/merge_requests/{iid}/merge'.format(iid=mocklab.merge_request_info['iid']),
                dict(sha=rewritten_sha, should_remove_source_branch=True, merge_when_pipeline_succeeds=True),
            ),
            Error(marge.gitlab.MethodNotAllowed(405, {'message': '405 Method Not Allowed'})),
            from_state='passed', to_state='now_is_wip',
        )
        api.add_merge_request(
            dict(mocklab.merge_request_info, work_in_progress=True),
            from_state='now_is_wip',
        )
        message = 'The request was marked as WIP as I was processing it (maybe a WIP commit?)'
        with mocklab.expected_failure(message):
            job.execute()
        assert api.state == 'now_is_wip'
        assert api.notes == ["I couldn't merge this branch: %s" % message] 
開發者ID:smarkets,項目名稱:marge-bot,代碼行數:22,代碼來源:test_single_job.py

示例5: test_guesses_git_hook_error_on_merge_refusal

# 需要導入模塊: from unittest.mock import patch [as 別名]
# 或者: from unittest.mock.patch import dict [as 別名]
def test_guesses_git_hook_error_on_merge_refusal(self, mocks):
        mocklab, api, job = mocks
        rewritten_sha = mocklab.rewritten_sha
        api.add_transition(
            PUT(
                '/projects/1234/merge_requests/{iid}/merge'.format(iid=mocklab.merge_request_info['iid']),
                dict(sha=rewritten_sha, should_remove_source_branch=True, merge_when_pipeline_succeeds=True),
            ),
            Error(marge.gitlab.MethodNotAllowed(405, {'message': '405 Method Not Allowed'})),
            from_state='passed', to_state='rejected_by_git_hook',
        )
        api.add_merge_request(
            dict(mocklab.merge_request_info, state='reopened'),
            from_state='rejected_by_git_hook',
        )
        message = (
            'GitLab refused to merge this branch. I suspect that a Push Rule or a git-hook '
            'is rejecting my commits; maybe my email needs to be white-listed?'
        )
        with mocklab.expected_failure(message):
            job.execute()
        assert api.state == 'rejected_by_git_hook'
        assert api.notes == ["I couldn't merge this branch: %s" % message] 
開發者ID:smarkets,項目名稱:marge-bot,代碼行數:25,代碼來源:test_single_job.py

示例6: test_discovers_if_someone_closed_the_merge_request

# 需要導入模塊: from unittest.mock import patch [as 別名]
# 或者: from unittest.mock.patch import dict [as 別名]
def test_discovers_if_someone_closed_the_merge_request(self, mocks):
        mocklab, api, job = mocks
        rewritten_sha = mocklab.rewritten_sha
        api.add_transition(
            PUT(
                '/projects/1234/merge_requests/{iid}/merge'.format(iid=mocklab.merge_request_info['iid']),
                dict(sha=rewritten_sha, should_remove_source_branch=True, merge_when_pipeline_succeeds=True),
            ),
            Error(marge.gitlab.MethodNotAllowed(405, {'message': '405 Method Not Allowed'})),
            from_state='passed', to_state='oops_someone_closed_it',
        )
        api.add_merge_request(
            dict(mocklab.merge_request_info, state='closed'),
            from_state='oops_someone_closed_it',
        )
        message = 'Someone closed the merge request while I was attempting to merge it.'
        with mocklab.expected_failure(message):
            job.execute()
        assert api.state == 'oops_someone_closed_it'
        assert api.notes == ["I couldn't merge this branch: %s" % message] 
開發者ID:smarkets,項目名稱:marge-bot,代碼行數:22,代碼來源:test_single_job.py

示例7: test_tells_explicitly_that_gitlab_refused_to_merge

# 需要導入模塊: from unittest.mock import patch [as 別名]
# 或者: from unittest.mock.patch import dict [as 別名]
def test_tells_explicitly_that_gitlab_refused_to_merge(self, mocks):
        mocklab, api, job = mocks
        rewritten_sha = mocklab.rewritten_sha
        api.add_transition(
            PUT(
                '/projects/1234/merge_requests/{iid}/merge'.format(iid=mocklab.merge_request_info['iid']),
                dict(sha=rewritten_sha, should_remove_source_branch=True, merge_when_pipeline_succeeds=True),
            ),
            Error(marge.gitlab.MethodNotAllowed(405, {'message': '405 Method Not Allowed'})),
            from_state='passed', to_state='rejected_for_mysterious_reasons',
        )
        message = "Gitlab refused to merge this request and I don't know why!"
        with mocklab.expected_failure(message):
            job.execute()
        assert api.state == 'rejected_for_mysterious_reasons'
        assert api.notes == ["I couldn't merge this branch: %s" % message] 
開發者ID:smarkets,項目名稱:marge-bot,代碼行數:18,代碼來源:test_single_job.py

示例8: test_wont_merge_branches_with_autosquash_if_rewriting

# 需要導入模塊: from unittest.mock import patch [as 別名]
# 或者: from unittest.mock.patch import dict [as 別名]
def test_wont_merge_branches_with_autosquash_if_rewriting(self, mocks):
        mocklab, api, job = mocks

        autosquash_merge_request = dict(mocklab.merge_request_info, squash=True)
        api.add_merge_request(autosquash_merge_request, from_state='initial')

        admin_user = dict(mocklab.user_info, is_admin=True)
        api.add_user(admin_user, is_current=True)

        if job.opts.requests_commit_tagging:
            message = "Sorry, merging requests marked as auto-squash would ruin my commit tagging!"
            with mocklab.expected_failure(message):
                job.execute()
            assert api.state == 'initial'
        else:
            job.execute()
            assert api.state == 'merged' 
開發者ID:smarkets,項目名稱:marge-bot,代碼行數:19,代碼來源:test_single_job.py

示例9: test_adaptive_length

# 需要導入模塊: from unittest.mock import patch [as 別名]
# 或者: from unittest.mock.patch import dict [as 別名]
def test_adaptive_length(self):
        with patch.dict('os.environ', {'COLUMNS': '80'}):
            out = StringIO()
            bar_width = 20
            prog_bar = mmcv.ProgressBar(10, bar_width=bar_width, file=out)
            time.sleep(1)
            reset_string_io(out)
            prog_bar.update()
            assert len(out.getvalue()) == 66

            os.environ['COLUMNS'] = '30'
            reset_string_io(out)
            prog_bar.update()
            assert len(out.getvalue()) == 48

            os.environ['COLUMNS'] = '60'
            reset_string_io(out)
            prog_bar.update()
            assert len(out.getvalue()) == 60 
開發者ID:open-mmlab,項目名稱:mmcv,代碼行數:21,代碼來源:test_progressbar.py

示例10: test__get_version_info_loggers_enabled

# 需要導入模塊: from unittest.mock import patch [as 別名]
# 或者: from unittest.mock.patch import dict [as 別名]
def test__get_version_info_loggers_enabled(self):
        mock_loggers = {
            'versionfinder': Mock(),
            'pip': Mock(),
            'git': Mock()
        }

        def se_getLogger(lname):
            return mock_loggers[lname]

        with patch('awslimitchecker.version.logging.getLogger') as mock_logger:
            mock_logger.side_effect = se_getLogger
            with patch.dict(
                'awslimitchecker.version.os.environ',
                {'VERSIONCHECK_DEBUG': 'true'}, clear=True
            ):
                with patch('awslimitchecker.version.find_version'):
                    version._get_version_info()
        assert mock_logger.mock_calls == []
        assert mock_loggers['versionfinder'].mock_calls == []
        assert mock_loggers['pip'].mock_calls == []
        assert mock_loggers['git'].mock_calls == [] 
開發者ID:jantman,項目名稱:awslimitchecker,代碼行數:24,代碼來源:test_version.py

示例11: test_no_service_key_warn

# 需要導入模塊: from unittest.mock import patch [as 別名]
# 或者: from unittest.mock.patch import dict [as 別名]
def test_no_service_key_warn(self):
        self.cls._service_key_crit = 'cKey'
        self.cls._account_alias = 'myAcct'
        with patch('%s._event_dict' % pb, autospec=True) as m_ed:
            m_ed.return_value = {'event': 'dict', 'details': {}}
            with patch('%s._send_event' % pb, autospec=True) as m_send:
                self.cls.on_success(duration=12.3)
        assert m_ed.mock_calls == [call(self.cls)]
        assert m_send.mock_calls == [
            call(self.cls, 'cKey', {
                'event': 'dict',
                'details': {
                    'duration_seconds': 12.3
                },
                'event_type': 'resolve',
                'description': 'awslimitchecker in myAcct rname found '
                               'no problems; run completed in '
                               '12.30 seconds'
            })
        ] 
開發者ID:jantman,項目名稱:awslimitchecker,代碼行數:22,代碼來源:test_pagerdutyv1.py

示例12: test__ma_field_to_fr_field_converts_metadata_param_to_description_if_present

# 需要導入模塊: from unittest.mock import patch [as 別名]
# 或者: from unittest.mock.patch import dict [as 別名]
def test__ma_field_to_fr_field_converts_metadata_param_to_description_if_present():
    @dataclass
    class FakeFieldWithDescription(ma.Field):
        metadata: dict

    expected_description = "test"

    fr_field_dict = utils._ma_field_to_fr_field(
        FakeFieldWithDescription(metadata={"description": expected_description})
    )
    assert fr_field_dict["description"] == expected_description

    @dataclass
    class FakeFieldNoMetaData(ma.Field):
        pass

    fr_field_dict = utils._ma_field_to_fr_field(FakeFieldNoMetaData())
    assert "description" not in fr_field_dict

    @dataclass
    class FakeFieldNoDescription(ma.Field):
        metadata: dict

    fr_field_dict = utils._ma_field_to_fr_field(FakeFieldNoDescription(metadata={}))
    assert "description" not in fr_field_dict 
開發者ID:apryor6,項目名稱:flask_accepts,代碼行數:27,代碼來源:utils_test.py

示例13: test_map_type_calls_type_map_dict_function_for_schema_instance

# 需要導入模塊: from unittest.mock import patch [as 別名]
# 或者: from unittest.mock.patch import dict [as 別名]
def test_map_type_calls_type_map_dict_function_for_schema_instance():
    class MarshmallowSchema(Schema):
        test_field: ma.Float

    expected_ma_field = MarshmallowSchema()
    expected_model_name, expected_operation, expected_namespace = _get_type_mapper_default_params()

    schema_type_mapper_mock = Mock()
    type_map_mock = dict(utils.type_map)
    type_map_mock[Schema] = schema_type_mapper_mock

    type_map_patch = patch.object(utils, "type_map", new=type_map_mock)

    with type_map_patch:
        utils.map_type(expected_ma_field, expected_namespace, expected_model_name, expected_operation)
        schema_type_mapper_mock.assert_called_with(
            expected_ma_field, expected_namespace, expected_model_name, expected_operation
        ) 
開發者ID:apryor6,項目名稱:flask_accepts,代碼行數:20,代碼來源:utils_test.py

示例14: test_map_type_calls_type_map_dict_function_for_schema_class

# 需要導入模塊: from unittest.mock import patch [as 別名]
# 或者: from unittest.mock.patch import dict [as 別名]
def test_map_type_calls_type_map_dict_function_for_schema_class():
    class InheritedMeta(SchemaMeta):
        pass

    class MarshmallowSchema(Schema, metaclass=InheritedMeta):
        test_field: ma.Float

    expected_ma_field = MarshmallowSchema
    expected_model_name, expected_operation, expected_namespace = _get_type_mapper_default_params()

    schema_type_mapper_mock = Mock()
    type_map_mock = dict(utils.type_map)
    type_map_mock[Schema] = schema_type_mapper_mock

    type_map_patch = patch.object(utils, "type_map", new=type_map_mock)

    with type_map_patch:
        utils.map_type(expected_ma_field, expected_namespace, expected_model_name, expected_operation)
        schema_type_mapper_mock.assert_called_with(
            expected_ma_field, expected_namespace, expected_model_name, expected_operation
        ) 
開發者ID:apryor6,項目名稱:flask_accepts,代碼行數:23,代碼來源:utils_test.py

示例15: test_ignore_core

# 需要導入模塊: from unittest.mock import patch [as 別名]
# 或者: from unittest.mock.patch import dict [as 別名]
def test_ignore_core():
    bot = MagicMock()
    event = MagicMock()
    _hook = MagicMock()

    _hook.plugin.title = "core.optout"
    _hook.function_name = "optout"

    event.chan = "#test"
    conn = event.conn

    conn.name = "test"

    opt = optout.OptOut("#test", "*", False)

    with patch.dict(optout.optout_cache, clear=True, test=[opt]):
        res = optout.optout_sieve(bot, event, _hook)
        assert res is event 
開發者ID:TotallyNotRobots,項目名稱:CloudBot,代碼行數:20,代碼來源:test_optout.py


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