Changeset 69905 in webkit


Ignore:
Timestamp:
Oct 15, 2010 6:31:15 PM (14 years ago)
Author:
dpranke@chromium.org
Message:

2010-10-15 Dirk Pranke <dpranke@chromium.org>

Reviewed by Eric Siedel.

mocktool.MockOptions is inheriting from Mock, which has the side
effect of defaulting any attribute to another MockObject. So,
MockOptions().foo would always evaluate to true. This was
covering over bugs in the unit tests, and is probably the wrong
default behavior for anything attempting to mock out the options
argument returned from optparse.parse_args().

This patch changes the default behavior. The new MockOptions()
class takes an optional list of keyword parameters to set; this
patch doesn't use that feature but the fix for bug 47510 will.

Also, this patch just fills in the default values necessary to
get all of the tests to pass; I didn't stare at each test by
hand to determine the "right" values. We can either fix that in
subsequent patches or let me know if we want to do that now (and
give me some guidance on what those values might want to be).

https://bugs.webkit.org/show_bug.cgi?id=47709

  • Scripts/webkitpy/tool/commands/commandtest.py:
  • Scripts/webkitpy/tool/commands/download_unittest.py:
  • Scripts/webkitpy/tool/commands/upload_unittest.py:
  • Scripts/webkitpy/tool/mocktool.py:
  • Scripts/webkitpy/tool/steps/steps_unittest.py:
  • Scripts/webkitpy/tool/steps/updatechangelogswithreview_unittest.py:
Location:
trunk/WebKitTools
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebKitTools/ChangeLog

    r69894 r69905  
     12010-10-15  Dirk Pranke  <dpranke@chromium.org>
     2
     3        Reviewed by Eric Siedel.
     4
     5        mocktool.MockOptions is inheriting from Mock, which has the side
     6        effect of defaulting any attribute to another MockObject. So,
     7        MockOptions().foo would always evaluate to true. This was
     8        covering over bugs in the unit tests, and is probably the wrong
     9        default behavior for anything attempting to mock out the options
     10        argument returned from optparse.parse_args().
     11
     12        This patch changes the default behavior. The new MockOptions()
     13        class takes an optional list of keyword parameters to set; this
     14        patch doesn't use that feature but the fix for bug 47510 will.
     15
     16        Also, this patch just fills in the default values necessary to
     17        get all of the tests to pass; I didn't stare at each test by
     18        hand to determine the "right" values. We can either fix that in
     19        subsequent patches or let me know if we want to do that now (and
     20        give me some guidance on what those values might want to be).
     21
     22        https://bugs.webkit.org/show_bug.cgi?id=47709
     23
     24        * Scripts/webkitpy/tool/commands/commandtest.py:
     25        * Scripts/webkitpy/tool/commands/download_unittest.py:
     26        * Scripts/webkitpy/tool/commands/upload_unittest.py:
     27        * Scripts/webkitpy/tool/mocktool.py:
     28        * Scripts/webkitpy/tool/steps/steps_unittest.py:
     29        * Scripts/webkitpy/tool/steps/updatechangelogswithreview_unittest.py:
     30
    1312010-10-15  Simon Fraser  <simon.fraser@apple.com>
    232
  • trunk/WebKitTools/Scripts/webkitpy/tool/commands/commandtest.py

    r63020 r69905  
    3434class CommandsTest(unittest.TestCase):
    3535    def assert_execute_outputs(self, command, args, expected_stdout="", expected_stderr="", options=MockOptions(), tool=MockTool()):
     36        options.blocks = True
     37        options.cc = 'MOCK cc'
     38        options.component = 'MOCK component'
     39        options.confirm = True
     40        options.email = 'MOCK email'
     41        options.git_commit = 'MOCK git commit'
     42        options.obsolete_patches = True
     43        options.open_bug = True
     44        options.port = 'MOCK port'
     45        options.quiet = True
     46        options.reviewer = 'MOCK reviewer'
    3647        command.bind_to_tool(tool)
    3748        OutputCapture().assert_outputs(self, command.execute, [options, args, tool], expected_stdout=expected_stdout, expected_stderr=expected_stderr)
  • trunk/WebKitTools/Scripts/webkitpy/tool/commands/download_unittest.py

    r66058 r69905  
    5858    def _default_options(self):
    5959        options = MockOptions()
     60        options.build = True
     61        options.build_style = True
     62        options.check_builders = True
     63        options.check_style = True
     64        options.clean = True
     65        options.close_bug = True
    6066        options.force_clean = False
    61         options.clean = True
    62         options.check_builders = True
     67        options.force_patch = True
     68        options.non_interactive = False
     69        options.parent_command = 'MOCK parent command'
    6370        options.quiet = False
    64         options.non_interactive = False
     71        options.test = True
    6572        options.update = True
    66         options.build = True
    67         options.test = True
    68         options.close_bug = True
    6973        return options
    7074
  • trunk/WebKitTools/Scripts/webkitpy/tool/commands/upload_unittest.py

    r68746 r69905  
    5353    def test_post(self):
    5454        options = MockOptions()
     55        options.cc = None
     56        options.check_style = True
     57        options.comment = None
    5558        options.description = "MOCK description"
    5659        options.request_commit = False
    5760        options.review = True
    58         options.comment = None
    59         options.cc = None
    6061        expected_stderr = """Running check-webkit-style
    6162MOCK: user.open_url: file://...
     
    8283    def test_upload(self):
    8384        options = MockOptions()
     85        options.cc = None
     86        options.check_style = True
     87        options.comment = None
    8488        options.description = "MOCK description"
    8589        options.request_commit = False
    8690        options.review = True
    87         options.comment = None
    88         options.cc = None
    8991        expected_stderr = """Running check-webkit-style
    9092MOCK: user.open_url: file://...
  • trunk/WebKitTools/Scripts/webkitpy/tool/mocktool.py

    r69843 r69905  
    582582
    583583
    584 class MockOptions(Mock):
    585     no_squash = False
    586     squash = False
     584class MockOptions(object):
     585    """Mock implementation of optparse.Values."""
     586
     587    def __init__(self, **kwargs):
     588        # The caller can set option values using keyword arguments. We don't
     589        # set any values by default because we don't know how this
     590        # object will be used. Generally speaking unit tests should
     591        # subclass this or provider wrapper functions that set a common
     592        # set of options.
     593        for key, value in kwargs.items():
     594            self.__dict__[key] = value
    587595
    588596
  • trunk/WebKitTools/Scripts/webkitpy/tool/steps/steps_unittest.py

    r69829 r69905  
    3838
    3939class StepsTest(unittest.TestCase):
     40    def _step_options(self):
     41        options = MockOptions()
     42        options.non_interactive = True
     43        options.port = 'MOCK port'
     44        options.quiet = True
     45        options.test = True
     46        return options
     47
    4048    def _run_step(self, step, tool=None, options=None, state=None):
    4149        if not tool:
    4250            tool = MockTool()
    4351        if not options:
    44             options = MockOptions()
     52            options = self._step_options()
    4553        if not state:
    4654            state = {}
     
    4856
    4957    def test_update_step(self):
    50         options = MockOptions()
     58        tool = MockTool()
     59        options = self._step_options()
    5160        options.update = True
    5261        expected_stderr = "Updating working directory\n"
    53         OutputCapture().assert_outputs(self, self._run_step, [Update, options], expected_stderr=expected_stderr)
     62        OutputCapture().assert_outputs(self, self._run_step, [Update, tool, options], expected_stderr=expected_stderr)
    5463
    5564    def test_prompt_for_bug_or_title_step(self):
     
    6372
    6473    def test_runtests_leopard_commit_queue_hack_command(self):
    65         mock_options = MockOptions()
    66         mock_options.non_interactive = True
     74        mock_options = self._step_options()
     75        step = RunTests(MockTool(log_executive=True), mock_options)
    6776        # FIXME: We shouldn't use a real port-object here, but there is too much to mock at the moment.
    6877        mock_port = WebKitPort()
  • trunk/WebKitTools/Scripts/webkitpy/tool/steps/updatechangelogswithreview_unittest.py

    r63020 r69905  
    4242    def test_empty_state(self):
    4343        capture = OutputCapture()
    44         step = UpdateChangeLogsWithReviewer(MockTool(), MockOptions())
     44        options = MockOptions()
     45        options.reviewer = 'MOCK reviewer'
     46        options.git_commit = 'MOCK git commit'
     47        step = UpdateChangeLogsWithReviewer(MockTool(), options)
    4548        capture.assert_outputs(self, step.run, [{}])
Note: See TracChangeset for help on using the changeset viewer.