+2009-11-27 Adam Barth <abarth@webkit.org>
+
+ Reviewed by Eric Seidel.
+
+ [bzt] Unit test download commands
+ https://bugs.webkit.org/show_bug.cgi?id=31923
+
+ Adds download_unittest and fixes a bug found while testing.
+
+ * Scripts/modules/commands/commandtest.py:
+ * Scripts/modules/commands/download.py:
+ Fixed a bug where we'd throw an error because [].append returns
+ None.
+ * Scripts/modules/commands/download_unittest.py: Added.
+ * Scripts/modules/mock_bugzillatool.py:
+ * Scripts/run-webkit-unittests:
+
2009-11-27 Adam Barth <abarth@webkit.org>
Unreviewed "build" fix found while writing unit tests.
sequence.run_and_handle_errors()
+# FIXME: Requires unit test. Blocking issue: WebKitApplyingScripts
class ApplyAttachment(Command):
name = "apply-attachment"
show_in_main_help = True
WebKitApplyingScripts.apply_patches_with_options(tool.scm(), [attachment], options)
+# FIXME: Requires unit test. Blocking issue: WebKitApplyingScripts
class ApplyPatches(Command):
name = "apply-patches"
show_in_main_help = True
bugs_to_patches = {}
for patch in patches:
bug_id = patch["bug_id"]
- bugs_to_patches[bug_id] = bugs_to_patches.get(bug_id, []).append(patch)
+ bugs_to_patches[bug_id] = bugs_to_patches.get(bug_id, []) + [patch]
return bugs_to_patches
def execute(self, options, args, tool):
return all_patches
+# FIXME: Requires unit test.
class Rollout(Command):
name = "rollout"
show_in_main_help = True
--- /dev/null
+# Copyright (C) 2009 Google Inc. All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met:
+#
+# * Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# * Redistributions in binary form must reproduce the above
+# copyright notice, this list of conditions and the following disclaimer
+# in the documentation and/or other materials provided with the
+# distribution.
+# * Neither the name of Google Inc. nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+import unittest
+
+from modules.commands.commandtest import CommandsTest
+from modules.commands.download import *
+from modules.mock import Mock
+
+class DownloadCommandsTest(CommandsTest):
+ def _default_options(self):
+ options = Mock()
+ options.force_clean = False
+ options.clean = True
+ options.check_builders = True
+ options.quiet = False
+ options.non_interactive = False
+ options.update = True
+ options.build = True
+ options.test = True
+ options.close_bug = True
+ return options
+
+ def test_build(self):
+ self.assert_execute_outputs(Build(), [], options=self._default_options())
+
+ def test_land_diff(self):
+ self.assert_execute_outputs(LandDiff(), [42], options=self._default_options())
+
+ def test_check_style(self):
+ self.assert_execute_outputs(CheckStyle(), [197], options=self._default_options())
+
+ def test_build_attachment(self):
+ self.assert_execute_outputs(BuildAttachment(), [197], options=self._default_options())
+
+ def test_land_attachment(self):
+ self.assert_execute_outputs(LandAttachment(), [197], options=self._default_options())
+
+ def test_land_patches(self):
+ self.assert_execute_outputs(LandPatches(), [42], options=self._default_options())
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+import os
+
+from modules.mock import Mock
from modules.scm import CommitMessage
-class MockBugzilla():
- patch1 = { "id": 197, "bug_id": 42, "url": "http://example.com/197", "is_obsolete": False }
- patch2 = { "id": 128, "bug_id": 42, "url": "http://example.com/128", "is_obsolete": False }
+class MockBugzilla(Mock):
+ patch1 = {
+ "id": 197,
+ "bug_id": 42,
+ "url": "http://example.com/197",
+ "is_obsolete": False,
+ "reviewer": "Reviewer1"
+ }
+ patch2 = {
+ "id": 128,
+ "bug_id": 42,
+ "url": "http://example.com/128",
+ "is_obsolete": False,
+ "reviewer": "Reviewer2"
+ }
def fetch_bug_ids_from_commit_queue(self):
return [42, 75]
return [self.patch1, self.patch2]
return None
- def close_bug_as_fixed(self, bug_id, comment_text=None):
- pass
-
- def obsolete_attachment(self, attachment_id, comment_text=None):
- pass
-
- def add_patch_to_bug(self, bug_id, patch_file_object, description, comment_text=None, mark_for_review=False, mark_for_commit_queue=False):
- pass
+ def fetch_attachment(self, attachment_id):
+ if attachment_id == 197:
+ return self.patch1
+ if attachment_id == 128:
+ return self.patch2
+ raise Exception("Bogus attachment_id in fetch_attachment.")
-class MockBuildBot():
+class MockBuildBot(Mock):
def builder_statuses(self):
return [{
"name": "Builder1",
}]
-class MockSCM():
+class MockSCM(Mock):
+ def __init__(self):
+ Mock.__init__(self)
+ self.checkout_root = os.getcwd()
+
def create_patch(self):
return "Patch1"
return "Patch2"
raise Exception("Bogus commit_id in commit_message_for_local_commit.")
+ def modified_changelogs(self):
+ # Ideally we'd return something more interesting here.
+ # The problem is that LandDiff will try to actually read the path from disk!
+ return []
+
class MockBugzillaTool():
- bugs = MockBugzilla()
- buildbot = MockBuildBot()
+ def __init__(self):
+ self.bugs = MockBugzilla()
+ self.buildbot = MockBuildBot()
+ self.steps = Mock()
+ self._scm = MockSCM()
- _scm = MockSCM()
def scm(self):
return self._scm
from modules.bugzilla_unittest import *
from modules.buildbot_unittest import *
from modules.changelogs_unittest import *
+from modules.commands.download_unittest import *
from modules.commands.upload_unittest import *
from modules.commands.queries_unittest import *
from modules.committers_unittest import *