2009-11-27 Adam Barth <abarth@webkit.org>
authorabarth@webkit.org <abarth@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 27 Nov 2009 17:37:46 +0000 (17:37 +0000)
committerabarth@webkit.org <abarth@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 27 Nov 2009 17:37:46 +0000 (17:37 +0000)
        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:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@51442 268f45cc-cd09-0410-ab3c-d52691b4dbfc

WebKitTools/ChangeLog
WebKitTools/Scripts/modules/commands/download.py
WebKitTools/Scripts/modules/commands/download_unittest.py [new file with mode: 0644]
WebKitTools/Scripts/modules/mock_bugzillatool.py
WebKitTools/Scripts/run-webkit-unittests

index 1338d79831e9df5eb129b6a85128735c3e42b00a..ce5e4022182e3956b0258c8813f2e49e48bccc5a 100644 (file)
@@ -1,3 +1,20 @@
+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.
index 98a8ebbaa821a6db74b1b258f6a46543160f5ee6..365b4079a2b4a399d8b302650cc2709ad1a4cfd7 100644 (file)
@@ -79,6 +79,7 @@ class Build(Command):
         sequence.run_and_handle_errors()
 
 
+# FIXME: Requires unit test. Blocking issue: WebKitApplyingScripts
 class ApplyAttachment(Command):
     name = "apply-attachment"
     show_in_main_help = True
@@ -94,6 +95,7 @@ class ApplyAttachment(Command):
         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
@@ -229,7 +231,7 @@ class AbstractPatchProcessingCommand(Command):
         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):
@@ -350,6 +352,7 @@ class LandPatches(AbstractPatchLandingCommand):
         return all_patches
 
 
+# FIXME: Requires unit test.
 class Rollout(Command):
     name = "rollout"
     show_in_main_help = True
diff --git a/WebKitTools/Scripts/modules/commands/download_unittest.py b/WebKitTools/Scripts/modules/commands/download_unittest.py
new file mode 100644 (file)
index 0000000..d0fff6e
--- /dev/null
@@ -0,0 +1,65 @@
+# 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())
index 8015f1021ca4656c3451a18e5d99d2984be8cdf1..9ebb2874d66bdfc2e1ea611685133de09bedae09 100644 (file)
 # (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]
@@ -53,17 +68,15 @@ class MockBugzilla():
             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",
@@ -74,7 +87,11 @@ class MockBuildBot():
         }]
 
 
-class MockSCM():
+class MockSCM(Mock):
+    def __init__(self):
+        Mock.__init__(self)
+        self.checkout_root = os.getcwd()
+
     def create_patch(self):
         return "Patch1"
 
@@ -95,11 +112,18 @@ class MockSCM():
             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
index f447dfa98fa69c20c913f12fcc1d8e005ca7cfd9..42bfe650f820e2d94bee4a9852addbbba5933e7f 100755 (executable)
@@ -32,6 +32,7 @@ import unittest
 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 *