⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 120370 in webkit


Ignore:
Timestamp:
Jun 14, 2012, 4:18:09 PM (14 years ago)
Author:
dpranke@chromium.org
Message:

webkitpy: remove DummyOptions and clean up the code in Port.get_option() and Port.set_option_default()
https://bugs.webkit.org/show_bug.cgi?id=89135

Reviewed by Ryosuke Niwa.

This patch is just some minor cleanup and simplification. There
should be no functional changes here.

  • Scripts/webkitpy/layout_tests/port/base.py:

(Port.init):
(Port.get_option):
(Port.set_option_default):

  • Scripts/webkitpy/layout_tests/port/chromium_win_unittest.py:

(ChromiumWinTest.test_setup_environ_for_server_register_cygwin):

  • Scripts/webkitpy/style/checkers/test_expectations.py:

(TestExpectationsChecker._determine_port_from_expectations_path):

  • Scripts/webkitpy/tool/mocktool.py:

(MockOptions.ensure_value):

Location:
trunk/Tools
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Tools/ChangeLog

    r120360 r120370  
     12012-06-14  Dirk Pranke  <dpranke@chromium.org>
     2
     3        webkitpy: remove DummyOptions and clean up the code in Port.get_option() and Port.set_option_default()
     4        https://bugs.webkit.org/show_bug.cgi?id=89135
     5
     6        Reviewed by Ryosuke Niwa.
     7
     8        This patch is just some minor cleanup and simplification. There
     9        should be no functional changes here.
     10
     11        * Scripts/webkitpy/layout_tests/port/base.py:
     12        (Port.__init__):
     13        (Port.get_option):
     14        (Port.set_option_default):
     15        * Scripts/webkitpy/layout_tests/port/chromium_win_unittest.py:
     16        (ChromiumWinTest.test_setup_environ_for_server_register_cygwin):
     17        * Scripts/webkitpy/style/checkers/test_expectations.py:
     18        (TestExpectationsChecker._determine_port_from_expectations_path):
     19        * Scripts/webkitpy/tool/mocktool.py:
     20        (MockOptions.ensure_value):
     21
    1222012-06-14  Ian Vollick  <vollick@chromium.org>
    223
  • trunk/Tools/Scripts/webkitpy/layout_tests/port/base.py

    r120349 r120370  
    3535import errno
    3636import os
     37import optparse
    3738import re
    3839
     
    6263
    6364
    64 class DummyOptions(object):
    65     """Fake implementation of optparse.Values. Cloned from webkitpy.tool.mocktool.MockOptions."""
    66 
    67     def __init__(self, *args, **kwargs):
    68         # The caller can set option values using keyword arguments. We don't
    69         # set any values by default because we don't know how this
    70         # object will be used. Generally speaking unit tests should
    71         # subclass this or provider wrapper functions that set a common
    72         # set of options.
    73         for key, value in kwargs.items():
    74             self.__dict__[key] = value
    75 
    76 
    7765# FIXME: This class should merge with WebKitPort now that Chromium behaves mostly like other webkit ports.
    7866class Port(object):
     
    112100        # well-formed options object that had all of the necessary
    113101        # options defined on it.
    114         self._options = options or DummyOptions()
     102        self._options = options or optparse.Values()
    115103
    116104        self.host = host
     
    679667
    680668    def get_option(self, name, default_value=None):
    681         # FIXME: Eventually we should not have to do a test for
    682         # hasattr(), and we should be able to just do
    683         # self.options.value. See additional FIXME in the constructor.
    684         if hasattr(self._options, name):
    685             return getattr(self._options, name)
    686         return default_value
     669        return getattr(self._options, name, default_value)
    687670
    688671    def set_option_default(self, name, default_value):
    689         # FIXME: Callers could also use optparse_parser.Values.ensure_value,
    690         # since this should always be a optparse_parser.Values object.
    691         if not hasattr(self._options, name) or getattr(self._options, name) is None:
    692             return setattr(self._options, name, default_value)
     672        return self._options.ensure_value(name, default_value)
    693673
    694674    def path_from_webkit_base(self, *comps):
  • trunk/Tools/Scripts/webkitpy/layout_tests/port/chromium_win_unittest.py

    r119649 r120370  
    3939
    4040class ChromiumWinTest(port_testcase.PortTestCase):
    41     class RegisterCygwinOption(object):
    42         def __init__(self):
    43             self.register_cygwin = True
    44             self.results_directory = '/'
    45 
    4641    port_name = 'chromium-win'
    4742    port_maker = chromium_win.ChromiumWinPort
     
    6863
    6964    def test_setup_environ_for_server_register_cygwin(self):
    70         port = self.make_port(options=ChromiumWinTest.RegisterCygwinOption())
     65        port = self.make_port(options=MockOptions(register_cygwin=True, results_directory='/'))
    7166        port._executive = MockExecutive(should_log=True)
    7267        expected_stderr = "MOCK run_command: ['/mock-checkout/Source/WebKit/chromium/third_party/cygwin/setup_mount.bat'], cwd=None\n"
  • trunk/Tools/Scripts/webkitpy/style/checkers/test_expectations.py

    r120238 r120370  
    3030
    3131import logging
     32import optparse
    3233import os
    3334import re
     
    3738from webkitpy.common.host import Host
    3839from webkitpy.layout_tests.models.test_expectations import TestExpectationParser
    39 from webkitpy.layout_tests.port.base import DummyOptions
    4040
    4141
     
    5050    def _determine_port_from_expectations_path(self, host, expectations_path):
    5151        # Pass a configuration to avoid calling default_configuration() when initializing the port (takes 0.5 seconds on a Mac Pro!).
    52         options = DummyOptions(configuration='Release')
     52        options = optparse.Values({'configuration': 'Release'})
    5353        for port_name in host.port_factory.all_port_names():
    5454            port = host.port_factory.get(port_name, options=options)
  • trunk/Tools/Scripts/webkitpy/tool/mocktool.py

    r113802 r120370  
    3737
    3838
    39 # FIXME: This should be moved somewhere in common and renamed
    40 # something without Mock in the name.
     39# FIXME: We should just replace this with optparse.Values(default=kwargs)
    4140class MockOptions(object):
    4241    """Mock implementation of optparse.Values."""
     
    5352        self.__dict__.update(**kwargs)
    5453        return self
     54
     55    def ensure_value(self, key, value):
     56        if getattr(self, key, None) == None:
     57            self.__dict__[key] = value
     58        return self.__dict__[key]
    5559
    5660
Note: See TracChangeset for help on using the changeset viewer.