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


Python mock.Mock类代码示例

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


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

示例1: get_manager_with_tests

 def get_manager_with_tests(test_names):
     port = Mock()  # FIXME: Use a tighter mock.
     port.TEST_PATH_SEPARATOR = '/'
     manager = Manager(port, options=MockOptions(http=True), printer=Mock())
     manager._test_files = set(test_names)
     manager._test_files_list = test_names
     return manager
开发者ID:,项目名称:,代码行数:7,代码来源:

示例2: assert_queue_outputs

    def assert_queue_outputs(self, queue, args=None, work_item=None, expected_stdout=None, expected_stderr=None, expected_exceptions=None, options=None, tool=None):
        if not tool:
            tool = MockTool()
            # This is a hack to make it easy for callers to not have to setup a custom MockFileSystem just to test the commit-queue
            # the cq tries to read the layout test results, and will hit a KeyError in MockFileSystem if we don't do this.
            tool.filesystem.write_text_file('/mock/results.html', "")
        if not expected_stdout:
            expected_stdout = {}
        if not expected_stderr:
            expected_stderr = {}
        if not args:
            args = []
        if not options:
            options = Mock()
            options.port = None
        if not work_item:
            work_item = self.mock_work_item
        tool.user.prompt = lambda message: "yes"

        queue.execute(options, args, tool, engine=MockQueueEngine)

        self.assert_outputs(queue.queue_log_path, "queue_log_path", [], expected_stdout, expected_stderr, expected_exceptions)
        self.assert_outputs(queue.work_item_log_path, "work_item_log_path", [work_item], expected_stdout, expected_stderr, expected_exceptions)
        self.assert_outputs(queue.begin_work_queue, "begin_work_queue", [], expected_stdout, expected_stderr, expected_exceptions)
        self.assert_outputs(queue.should_continue_work_queue, "should_continue_work_queue", [], expected_stdout, expected_stderr, expected_exceptions)
        self.assert_outputs(queue.next_work_item, "next_work_item", [], expected_stdout, expected_stderr, expected_exceptions)
        self.assert_outputs(queue.should_proceed_with_work_item, "should_proceed_with_work_item", [work_item], expected_stdout, expected_stderr, expected_exceptions)
        self.assert_outputs(queue.process_work_item, "process_work_item", [work_item], expected_stdout, expected_stderr, expected_exceptions)
        self.assert_outputs(queue.handle_unexpected_error, "handle_unexpected_error", [work_item, "Mock error message"], expected_stdout, expected_stderr, expected_exceptions)
        # Should we have a different function for testing StepSequenceErrorHandlers?
        if isinstance(queue, StepSequenceErrorHandler):
            self.assert_outputs(queue.handle_script_error, "handle_script_error", [tool, {"patch": self.mock_work_item}, ScriptError(message="ScriptError error message", script_args="MockErrorCommand")], expected_stdout, expected_stderr, expected_exceptions)
开发者ID:0x4d52,项目名称:JavaScriptCore-X,代码行数:32,代码来源:queuestest.py

示例3: test_shard_tests

    def test_shard_tests(self):
        # Test that _shard_tests in test_runner.TestRunner really
        # put the http tests first in the queue.
        port = Mock()
        port._filesystem = filesystem_mock.MockFileSystem()
        runner = TestRunnerWrapper(port=port, options=Mock(),
            printer=Mock())

        test_list = [
          "LayoutTests/websocket/tests/unicode.htm",
          "LayoutTests/animations/keyframes.html",
          "LayoutTests/http/tests/security/view-source-no-refresh.html",
          "LayoutTests/websocket/tests/websocket-protocol-ignored.html",
          "LayoutTests/fast/css/display-none-inline-style-change-crash.html",
          "LayoutTests/http/tests/xmlhttprequest/supported-xml-content-types.html",
          "LayoutTests/dom/html/level2/html/HTMLAnchorElement03.html",
          "LayoutTests/ietestcenter/Javascript/11.1.5_4-4-c-1.html",
          "LayoutTests/dom/html/level2/html/HTMLAnchorElement06.html",
        ]

        expected_tests_to_http_lock = set([
          'LayoutTests/websocket/tests/unicode.htm',
          'LayoutTests/http/tests/security/view-source-no-refresh.html',
          'LayoutTests/websocket/tests/websocket-protocol-ignored.html',
          'LayoutTests/http/tests/xmlhttprequest/supported-xml-content-types.html',
        ])

        # FIXME: Ideally the HTTP tests don't have to all be in one shard.
        single_thread_results = runner._shard_tests(test_list, False)
        multi_thread_results = runner._shard_tests(test_list, True)

        self.assertEqual("tests_to_http_lock", single_thread_results[0][0])
        self.assertEqual(expected_tests_to_http_lock, set(single_thread_results[0][1]))
        self.assertEqual("tests_to_http_lock", multi_thread_results[0][0])
        self.assertEqual(expected_tests_to_http_lock, set(multi_thread_results[0][1]))
开发者ID:dankurka,项目名称:webkit_titanium,代码行数:35,代码来源:test_runner_unittest.py

示例4: __init__

 def __init__(self):
     Mock.__init__(self)
     # FIXME: We should probably use real checkout-root detection logic here.
     # os.getcwd() can't work here because other parts of the code assume that "checkout_root"
     # will actually be the root.  Since getcwd() is wrong, use a globally fake root for now.
     self.checkout_root = self.fake_checkout_root
     self.added_paths = set()
开发者ID:mcgrawp,项目名称:webkit-webcl,代码行数:7,代码来源:mocktool.py

示例5: _test_ews

 def _test_ews(self, ews):
     ews.bind_to_tool(MockTool())
     ews.host = MockHost()
     options = Mock()
     options.port = None
     options.run_tests = ews.run_tests
     self.assert_queue_outputs(ews, expected_logs=self._default_expected_logs(ews), options=options)
开发者ID:eocanha,项目名称:webkit,代码行数:7,代码来源:earlywarningsystem_unittest.py

示例6: test_modified_changelogs

 def test_modified_changelogs(self):
     scm = Mock()
     scm.checkout_root = "/foo/bar"
     scm.changed_files = lambda git_commit: ["file1", "ChangeLog", "relative/path/ChangeLog"]
     checkout = Checkout(scm)
     expected_changlogs = ["/foo/bar/ChangeLog", "/foo/bar/relative/path/ChangeLog"]
     self.assertEqual(checkout.modified_changelogs(git_commit=None), expected_changlogs)
开发者ID:KDE,项目名称:android-qtwebkit,代码行数:7,代码来源:checkout_unittest.py

示例7: assert_queue_outputs

    def assert_queue_outputs(self, queue, args=None, work_item=None, expected_stdout=None, expected_stderr=None, expected_exceptions=None, options=None, tool=None):
        if not tool:
            tool = MockTool()
        if not expected_stdout:
            expected_stdout = {}
        if not expected_stderr:
            expected_stderr = {}
        if not args:
            args = []
        if not options:
            options = Mock()
            options.port = None
        if not work_item:
            work_item = self.mock_work_item
        tool.user.prompt = lambda message: "yes"

        queue.execute(options, args, tool, engine=MockQueueEngine)

        self.assert_outputs(queue.queue_log_path, "queue_log_path", [], expected_stdout, expected_stderr, expected_exceptions)
        self.assert_outputs(queue.work_item_log_path, "work_item_log_path", [work_item], expected_stdout, expected_stderr, expected_exceptions)
        self.assert_outputs(queue.begin_work_queue, "begin_work_queue", [], expected_stdout, expected_stderr, expected_exceptions)
        self.assert_outputs(queue.should_continue_work_queue, "should_continue_work_queue", [], expected_stdout, expected_stderr, expected_exceptions)
        self.assert_outputs(queue.next_work_item, "next_work_item", [], expected_stdout, expected_stderr, expected_exceptions)
        self.assert_outputs(queue.should_proceed_with_work_item, "should_proceed_with_work_item", [work_item], expected_stdout, expected_stderr, expected_exceptions)
        self.assert_outputs(queue.process_work_item, "process_work_item", [work_item], expected_stdout, expected_stderr, expected_exceptions)
        self.assert_outputs(queue.handle_unexpected_error, "handle_unexpected_error", [work_item, "Mock error message"], expected_stdout, expected_stderr, expected_exceptions)
        # Should we have a different function for testing StepSequenceErrorHandlers?
        if isinstance(queue, StepSequenceErrorHandler):
            self.assert_outputs(queue.handle_script_error, "handle_script_error", [tool, {"patch": self.mock_work_item}, ScriptError(message="ScriptError error message", script_args="MockErrorCommand")], expected_stdout, expected_stderr, expected_exceptions)
开发者ID:Andersbakken,项目名称:check-coding-style,代码行数:29,代码来源:queuestest.py

示例8: test_commit_message_for_current_diff

 def test_commit_message_for_current_diff(self):
     tool = MockTool()
     mock_commit_message_for_this_commit = Mock()
     mock_commit_message_for_this_commit.message = lambda: "Mock message"
     tool._checkout.commit_message_for_this_commit = lambda: mock_commit_message_for_this_commit
     expected_stdout = "Mock message\n"
     self.assert_execute_outputs(CommitMessageForCurrentDiff(), [], expected_stdout=expected_stdout, tool=tool)
开发者ID:UIKit0,项目名称:WebkitAIR,代码行数:7,代码来源:upload_unittest.py

示例9: test_interrupt_if_at_failure_limits

    def test_interrupt_if_at_failure_limits(self):
        port = Mock()  # FIXME: This should be a tighter mock.
        port.TEST_PATH_SEPARATOR = '/'
        port._filesystem = MockFileSystem()
        manager = Manager(port=port, options=MockOptions(), printer=Mock())

        manager._options = MockOptions(exit_after_n_failures=None, exit_after_n_crashes_or_timeouts=None)
        result_summary = ResultSummary(expectations=Mock(), test_files=[])
        result_summary.unexpected_failures = 100
        result_summary.unexpected_crashes = 50
        result_summary.unexpected_timeouts = 50
        # No exception when the exit_after* options are None.
        manager._interrupt_if_at_failure_limits(result_summary)

        # No exception when we haven't hit the limit yet.
        manager._options.exit_after_n_failures = 101
        manager._options.exit_after_n_crashes_or_timeouts = 101
        manager._interrupt_if_at_failure_limits(result_summary)

        # Interrupt if we've exceeded either limit:
        manager._options.exit_after_n_crashes_or_timeouts = 10
        self.assertRaises(TestRunInterruptedException, manager._interrupt_if_at_failure_limits, result_summary)

        manager._options.exit_after_n_crashes_or_timeouts = None
        manager._options.exit_after_n_failures = 10
        exception = self.assertRaises(TestRunInterruptedException, manager._interrupt_if_at_failure_limits, result_summary)
开发者ID:,项目名称:,代码行数:26,代码来源:

示例10: test_mark_bug_fixed

 def test_mark_bug_fixed(self):
     tool = MockTool()
     tool._scm.last_svn_commit_log = lambda: "r9876 |"
     options = Mock()
     options.bug_id = 42
     options.comment = "MOCK comment"
     expected_stderr = "Bug: <http://example.com/42> Bug with two r+'d and cq+'d patches, one of which has an invalid commit-queue setter.\nRevision: 9876\nMOCK: user.open_url: http://example.com/42\nAdding comment to Bug 42.\nMOCK bug comment: bug_id=42, cc=None\n--- Begin comment ---\nMOCK comment\n\nCommitted r9876: <http://trac.webkit.org/changeset/9876>\n--- End comment ---\n\n"
     self.assert_execute_outputs(MarkBugFixed(), [], expected_stderr=expected_stderr, tool=tool, options=options)
开发者ID:,项目名称:,代码行数:8,代码来源:

示例11: test_filename_for_upload

 def test_filename_for_upload(self):
     bugzilla = Bugzilla()
     mock_file = Mock()
     mock_file.name = "foo"
     self.assertEqual(bugzilla._filename_for_upload(mock_file, 1234), 'foo')
     mock_timestamp = lambda: "now"
     filename = bugzilla._filename_for_upload(StringIO.StringIO(), 1234, extension="patch", timestamp=mock_timestamp)
     self.assertEqual(filename, "bug-1234-now.patch")
开发者ID:0x4d52,项目名称:JavaScriptCore-X,代码行数:8,代码来源:bugzilla_unittest.py

示例12: test_apply_patch

 def test_apply_patch(self):
     checkout = self._make_checkout()
     checkout._executive = MockExecutive(should_log=True)
     checkout._scm.script_path = lambda script: script
     mock_patch = Mock()
     mock_patch.contents = lambda: "foo"
     mock_patch.reviewer = lambda: None
     expected_stderr = "MOCK run_command: ['svn-apply', '--force'], cwd=/mock-checkout\n"
     OutputCapture().assert_outputs(self, checkout.apply_patch, [mock_patch], expected_stderr=expected_stderr)
开发者ID:sohocoke,项目名称:webkit,代码行数:9,代码来源:checkout_unittest.py

示例13: test_patches_to_commit_queue

    def test_patches_to_commit_queue(self):
        expected_stdout = "http://example.com/10003&action=edit\n"
        expected_logs = "10000 already has cq=+\n10001 already has cq=+\n10004 committer = \"Eric Seidel\" <[email protected]>\n"
        options = Mock()
        options.bugs = False
        self.assert_execute_outputs(PatchesToCommitQueue(), None, expected_stdout, expected_logs=expected_logs, options=options)

        expected_stdout = "http://example.com/50003\n"
        options.bugs = True
        self.assert_execute_outputs(PatchesToCommitQueue(), None, expected_stdout, expected_logs=expected_logs, options=options)
开发者ID:,项目名称:,代码行数:10,代码来源:

示例14: test_latest_entry_for_changelog_at_revision

 def test_latest_entry_for_changelog_at_revision(self):
     scm = Mock()
     def mock_contents_at_revision(changelog_path, revision):
         self.assertEqual(changelog_path, "foo")
         self.assertEqual(revision, "bar")
         return _changelog1
     scm.contents_at_revision = mock_contents_at_revision
     checkout = Checkout(scm)
     entry = checkout._latest_entry_for_changelog_at_revision("foo", "bar")
     self.assertEqual(entry.contents(), _changelog1entry1)
开发者ID:mikezit,项目名称:Webkit_Code,代码行数:10,代码来源:api_unittest.py

示例15: _test_json_generation

    def _test_json_generation(self, passed_tests_list, failed_tests_list):
        tests_set = set(passed_tests_list) | set(failed_tests_list)

        DISABLED_tests = set([t for t in tests_set if t.startswith("DISABLED_")])
        FLAKY_tests = set([t for t in tests_set if t.startswith("FLAKY_")])
        FAILS_tests = set([t for t in tests_set if t.startswith("FAILS_")])
        PASS_tests = tests_set - (DISABLED_tests | FLAKY_tests | FAILS_tests)

        failed_tests = set(failed_tests_list) - DISABLED_tests
        failed_count_map = dict([(t, 1) for t in failed_tests])

        test_timings = {}
        i = 0
        for test in tests_set:
            test_timings[test] = float(self._num_runs * 100 + i)
            i += 1

        test_results_map = dict()
        for test in tests_set:
            test_results_map[test] = json_results_generator.TestResult(
                test, failed=(test in failed_tests), elapsed_time=test_timings[test]
            )

        host = MockHost()
        port = Mock()
        port._filesystem = host.filesystem
        generator = json_results_generator.JSONResultsGeneratorBase(
            port,
            self.builder_name,
            self.build_name,
            self.build_number,
            "",
            None,  # don't fetch past json results archive
            test_results_map,
        )

        failed_count_map = dict([(t, 1) for t in failed_tests])

        # Test incremental json results
        incremental_json = generator.get_json()
        self._verify_json_results(
            tests_set,
            test_timings,
            failed_count_map,
            len(PASS_tests),
            len(DISABLED_tests),
            len(FLAKY_tests),
            len(DISABLED_tests | failed_tests),
            incremental_json,
            1,
        )

        # We don't verify the results here, but at least we make sure the code runs without errors.
        generator.generate_json_output()
        generator.generate_times_ms_file()
开发者ID:sukwon0709,项目名称:Artemis,代码行数:55,代码来源:json_results_generator_unittest.py


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