Changeset 99106 in webkit


Ignore:
Timestamp:
Nov 2, 2011, 3:25:56 PM (14 years ago)
Author:
eric@webkit.org
Message:

BaselineOptimizer tests should use mocks instead of real Executive/FileSystem objects
https://bugs.webkit.org/show_bug.cgi?id=71237

Reviewed by Adam Barth.

Calling the static version of factory.get() with proper mocking
requires passsing an explict filesystem, executive, etc.
So instead, we use a PortFactory instance and pass it a Host pointer.
I had to add a MockHost since we'd not needed a non-host tool before now.

  • Scripts/webkitpy/common/checkout/baselineoptimizer.py:
  • Scripts/webkitpy/common/checkout/baselineoptimizer_unittest.py:
  • Scripts/webkitpy/tool/commands/rebaseline.py:
  • Scripts/webkitpy/tool/mocktool.py:
Location:
trunk/Tools
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Tools/ChangeLog

    r99103 r99106  
     12011-10-31  Eric Seidel  <eric@webkit.org>
     2
     3        BaselineOptimizer tests should use mocks instead of real Executive/FileSystem objects
     4        https://bugs.webkit.org/show_bug.cgi?id=71237
     5
     6        Reviewed by Adam Barth.
     7
     8        Calling the static version of factory.get() with proper mocking
     9        requires passsing an explict filesystem, executive, etc.
     10        So instead, we use a PortFactory instance and pass it a Host pointer.
     11        I had to add a MockHost since we'd not needed a non-host tool before now.
     12
     13        * Scripts/webkitpy/common/checkout/baselineoptimizer.py:
     14        * Scripts/webkitpy/common/checkout/baselineoptimizer_unittest.py:
     15        * Scripts/webkitpy/tool/commands/rebaseline.py:
     16        * Scripts/webkitpy/tool/mocktool.py:
     17
    1182011-11-02  Anders Carlsson  <andersca@apple.com>
    219
  • trunk/Tools/Scripts/webkitpy/common/checkout/baselineoptimizer.py

    r98877 r99106  
    2727# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2828
    29 from webkitpy.layout_tests.port import factory as port_factory
    30 
    3129
    3230# Yes, it's a hypergraph.
    3331# FIXME: Should this function live with the ports somewhere?
    34 def _baseline_search_hypergraph(fs):
     32# Perhaps this should move onto PortFactory?
     33def _baseline_search_hypergraph(host):
    3534    hypergraph = {}
    3635
     
    4342    fallback_path = ['LayoutTests']
    4443
     44    port_factory = host.port_factory
    4545    for port_name in port_factory.all_port_names():
    46         # FIXME: This should pass User and Executive as well to allow for easy mocking.
    47         # Alternatively, we should get a pre-mocked PortFactory from tool.
    48         port = port_factory.get(port_name, filesystem=fs)
     46        port = port_factory.get(port_name)
    4947        webkit_base = port.webkit_base()
    5048        search_path = port.baseline_search_path()
    5149        if search_path:
    52             hypergraph[port_name] = [fs.relpath(path, webkit_base) for path in search_path] + fallback_path
     50            hypergraph[port_name] = [host.filesystem.relpath(path, webkit_base) for path in search_path] + fallback_path
    5351    return hypergraph
    5452
     
    6664
    6765class BaselineOptimizer(object):
    68     def __init__(self, scm, filesystem):
    69         self._scm = scm
    70         self._filesystem = filesystem
    71         self._hypergraph = _baseline_search_hypergraph(self._filesystem)
     66    def __init__(self, host):
     67        self._host = host
     68        self._filesystem = self._host.filesystem
     69        self._scm = self._host.scm()
     70        self._hypergraph = _baseline_search_hypergraph(host)
    7271        self._directories = reduce(set.union, map(set, self._hypergraph.values()))
    7372
  • trunk/Tools/Scripts/webkitpy/common/checkout/baselineoptimizer_unittest.py

    r96428 r99106  
    3232from webkitpy.common.checkout.baselineoptimizer import BaselineOptimizer
    3333from webkitpy.common.system.filesystem_mock import MockFileSystem
    34 from webkitpy.tool.mocktool import MockSCM
     34from webkitpy.layout_tests.port.factory import PortFactory
     35from webkitpy.tool.mocktool import MockHost
    3536
    3637
    3738class TestBaselineOptimizer(BaselineOptimizer):
    3839    def __init__(self, mock_results_by_directory):
    39         BaselineOptimizer.__init__(self, MockSCM(), MockFileSystem())
     40        host = MockHost()
     41        host.port_factory = PortFactory(host)  # We want a real PortFactory, but it should use mocks.
     42        BaselineOptimizer.__init__(self, host)
    4043        self._mock_results_by_directory = mock_results_by_directory
    4144
     
    5356
    5457    def test_move_baselines(self):
    55         fs = MockFileSystem()
    56         fs.write_binary_file('/mock-checkout/LayoutTests/platform/chromium-win/another/test-expected.txt', 'result A')
    57         fs.write_binary_file('/mock-checkout/LayoutTests/platform/chromium-cg-mac/another/test-expected.txt', 'result A')
    58         fs.write_binary_file('/mock-checkout/LayoutTests/platform/chromium/another/test-expected.txt', 'result B')
    59         baseline_optimizer = BaselineOptimizer(MockSCM(), fs)
     58        host = MockHost()
     59        host.port_factory = PortFactory(host)  # We want a real PortFactory, but it should use mocks.
     60        host.filesystem.write_binary_file('/mock-checkout/LayoutTests/platform/chromium-win/another/test-expected.txt', 'result A')
     61        host.filesystem.write_binary_file('/mock-checkout/LayoutTests/platform/chromium-cg-mac/another/test-expected.txt', 'result A')
     62        host.filesystem.write_binary_file('/mock-checkout/LayoutTests/platform/chromium/another/test-expected.txt', 'result B')
     63        baseline_optimizer = BaselineOptimizer(host)
    6064        baseline_optimizer._move_baselines('another/test-expected.txt', {
    6165            'LayoutTests/platform/chromium-win': 'aaa',
     
    6569            'LayoutTests/platform/chromium': 'aaa',
    6670        })
    67         self.assertEqual(fs.read_binary_file('/mock-checkout/LayoutTests/platform/chromium/another/test-expected.txt'), 'result A')
     71        self.assertEqual(host.filesystem.read_binary_file('/mock-checkout/LayoutTests/platform/chromium/another/test-expected.txt'), 'result A')
    6872
    6973    def test_chromium_linux_redundant_with_win(self):
     
    133137    def test_complex_shadowing(self):
    134138        # This test relies on OS specific functionality, so it doesn't work on Windows.
     139        # FIXME: What functionality does this rely on?  When can we remove this if?
    135140        if sys.platform == 'win32':
    136141            return
  • trunk/Tools/Scripts/webkitpy/tool/commands/rebaseline.py

    r94325 r99106  
    117117
    118118    def execute(self, options, args, tool):
    119         self._baseline_optimizer = BaselineOptimizer(tool.scm(), tool.filesystem)
     119        self._baseline_optimizer = BaselineOptimizer(tool)
    120120        self._port = factory.get("chromium-win-win7")  # FIXME: This should be selectable.
    121121
     
    147147
    148148    def execute(self, options, args, tool):
    149         self._baseline_optimizer = BaselineOptimizer(tool.scm(), tool.filesystem)
     149        self._baseline_optimizer = BaselineOptimizer(tool)
    150150        self._port = factory.get("chromium-win-win7")  # FIXME: This should be selectable.
    151151
  • trunk/Tools/Scripts/webkitpy/tool/mocktool.py

    r98753 r99106  
    840840
    841841
    842 class MockTool(object):
     842class MockHost(object):
    843843    def __init__(self, log_executive=False, executive_throws_when_run=None):
    844844        self.wakeup_event = threading.Event()
     
    869869        return self._checkout
    870870
     871    def port(self):
     872        return self._port
     873
    871874    def chromium_buildbot(self):
    872875        return self._chromium_buildbot
     
    882885        return self._irc
    883886
     887
     888class MockTool(MockHost):
    884889    def path(self):
    885890        return "echo"
    886891
    887     def port(self):
    888         return self._port
    889 
    890892
    891893class MockBrowser(object):
Note: See TracChangeset for help on using the changeset viewer.