Changeset 51436 in webkit


Ignore:
Timestamp:
Nov 27, 2009 12:02:05 AM (14 years ago)
Author:
abarth@webkit.org
Message:

2009-11-27 Adam Barth <abarth@webkit.org>

Reviewed by Eric Seidel.

[bzt] Unit test upload commands
https://bugs.webkit.org/show_bug.cgi?id=31903

Adds unit tests for all but two of the upload commands. The two
remaining ones are more difficult. I'll return to them later. The
goal of these tests is just to run the commands. We can test more
detailed behavior later.

  • Scripts/modules/commands/commandtest.py:
  • Scripts/modules/commands/upload.py:
  • Scripts/modules/commands/upload_unittest.py:
  • Scripts/modules/mock.py: Added.
  • Scripts/modules/mock_bugzillatool.py:
Location:
trunk/WebKitTools
Files:
1 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebKitTools/ChangeLog

    r51435 r51436  
     12009-11-27  Adam Barth  <abarth@webkit.org>
     2
     3        Reviewed by Eric Seidel.
     4
     5        [bzt] Unit test upload commands
     6        https://bugs.webkit.org/show_bug.cgi?id=31903
     7
     8        Adds unit tests for all but two of the upload commands.  The two
     9        remaining ones are more difficult.  I'll return to them later.  The
     10        goal of these tests is just to run the commands.  We can test more
     11        detailed behavior later.
     12
     13        * Scripts/modules/commands/commandtest.py:
     14        * Scripts/modules/commands/upload.py:
     15        * Scripts/modules/commands/upload_unittest.py:
     16        * Scripts/modules/mock.py: Added.
     17        * Scripts/modules/mock_bugzillatool.py:
     18
    1192009-11-26  Adam Barth  <abarth@webkit.org>
    220
  • trunk/WebKitTools/Scripts/modules/commands/commandtest.py

    r51405 r51436  
    2929import unittest
    3030
     31from modules.mock import Mock
    3132from modules.mock_bugzillatool import MockBugzillaTool
    3233from modules.outputcapture import OutputCapture
    3334
    3435class CommandsTest(unittest.TestCase):
    35     def assert_execute_outputs(self, command, command_args, expected_stdout, expected_stderr=""):
     36    def assert_execute_outputs(self, command, args, expected_stdout="", expected_stderr="", options=Mock(), tool=MockBugzillaTool()):
    3637        capture = OutputCapture()
    3738        capture.capture_output()
    38         command.execute(None, command_args, MockBugzillaTool())
     39        command.execute(options, args, tool)
    3940        (stdout_string, stderr_string) = capture.restore_output()
    4041        self.assertEqual(stdout_string, expected_stdout)
  • trunk/WebKitTools/Scripts/modules/commands/upload.py

    r51404 r51436  
    5555from modules.workqueue import WorkQueue, WorkQueueDelegate
    5656
     57# FIXME: Requires unit test.  Blocking issue: commit_message_for_this_commit.
    5758class CommitMessageForCurrentDiff(Command):
    5859    name = "commit-message"
     
    181182
    182183
     184# FIXME: Requires unit test.  Blocking issue: too complex for now.
    183185class CreateBug(Command):
    184186    name = "create-bug"
  • trunk/WebKitTools/Scripts/modules/commands/upload_unittest.py

    r51405 r51436  
    3434class UploadCommandsTest(CommandsTest):
    3535    def test_mark_fixed(self):
    36         self.assert_execute_outputs(MarkFixed(), [43, "Test comment"], "", "")
     36        self.assert_execute_outputs(MarkFixed(), [43, "Test comment"])
     37
     38    def test_obsolete_attachments(self):
     39        self.assert_execute_outputs(ObsoleteAttachments(), [42])
     40
     41    def test_post_diff(self):
     42        self.assert_execute_outputs(PostDiff(), [42])
  • trunk/WebKitTools/Scripts/modules/mock_bugzillatool.py

    r51405 r51436  
    2727# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2828
     29from modules.scm import CommitMessage
     30
    2931class MockBugzilla():
    30     patch1 = { "id": 197, "bug_id": 42, "url": "http://example.com/197" }
    31     patch2 = { "id": 128, "bug_id": 42, "url": "http://example.com/128" }
     32    patch1 = { "id": 197, "bug_id": 42, "url": "http://example.com/197", "is_obsolete": False }
     33    patch2 = { "id": 128, "bug_id": 42, "url": "http://example.com/128", "is_obsolete": False }
    3234
    3335    def fetch_bug_ids_from_commit_queue(self):
     
    4244        return None
    4345
     46    def fetch_attachments_from_bug(self, bug_id):
     47        if bug_id == 42:
     48            return [self.patch1, self.patch2]
     49        return None
     50
     51    def fetch_patches_from_bug(self, bug_id):
     52        if bug_id == 42:
     53            return [self.patch1, self.patch2]
     54        return None
     55
    4456    def close_bug_as_fixed(self, bug_id, comment_text=None):
     57        pass
     58
     59    def obsolete_attachment(self, attachment_id, comment_text=None):
     60        pass
     61
     62    def add_patch_to_bug(self, bug_id, patch_file_object, description, comment_text=None, mark_for_review=False, mark_for_commit_queue=False):
    4563        pass
    4664
     
    5775
    5876
     77class MockSCM():
     78    def create_patch(self):
     79        return "Patch1"
     80
     81    def commit_ids_from_commitish_arguments(self, args):
     82        return ["Commitish1", "Commitish2"]
     83
     84    def commit_message_for_local_commit(self, commit_id):
     85        if commit_id == "Commitish1":
     86            return CommitMessage("CommitMessage1\nhttps://bugs.example.org/show_bug.cgi?id=42\n")
     87        if commit_id == "Commitish2":
     88            return CommitMessage("CommitMessage2\nhttps://bugs.example.org/show_bug.cgi?id=75\n")
     89        raise Exception("Bogus commit_id in commit_message_for_local_commit.")
     90
     91    def create_patch_from_local_commit(self, commit_id):
     92        if commit_id == "Commitish1":
     93            return "Patch1"
     94        if commit_id == "Commitish2":
     95            return "Patch2"
     96        raise Exception("Bogus commit_id in commit_message_for_local_commit.")
     97
     98
    5999class MockBugzillaTool():
    60100    bugs = MockBugzilla()
    61101    buildbot = MockBuildBot()
     102
     103    _scm = MockSCM()
     104    def scm(self):
     105        return self._scm
Note: See TracChangeset for help on using the changeset viewer.