Changeset 99106 in webkit
- Timestamp:
- Nov 2, 2011, 3:25:56 PM (14 years ago)
- Location:
- trunk/Tools
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Tools/ChangeLog
r99103 r99106 1 2011-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 1 18 2011-11-02 Anders Carlsson <andersca@apple.com> 2 19 -
trunk/Tools/Scripts/webkitpy/common/checkout/baselineoptimizer.py
r98877 r99106 27 27 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 28 29 from webkitpy.layout_tests.port import factory as port_factory30 31 29 32 30 # Yes, it's a hypergraph. 33 31 # FIXME: Should this function live with the ports somewhere? 34 def _baseline_search_hypergraph(fs): 32 # Perhaps this should move onto PortFactory? 33 def _baseline_search_hypergraph(host): 35 34 hypergraph = {} 36 35 … … 43 42 fallback_path = ['LayoutTests'] 44 43 44 port_factory = host.port_factory 45 45 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) 49 47 webkit_base = port.webkit_base() 50 48 search_path = port.baseline_search_path() 51 49 if search_path: 52 hypergraph[port_name] = [ fs.relpath(path, webkit_base) for path in search_path] + fallback_path50 hypergraph[port_name] = [host.filesystem.relpath(path, webkit_base) for path in search_path] + fallback_path 53 51 return hypergraph 54 52 … … 66 64 67 65 class 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) 72 71 self._directories = reduce(set.union, map(set, self._hypergraph.values())) 73 72 -
trunk/Tools/Scripts/webkitpy/common/checkout/baselineoptimizer_unittest.py
r96428 r99106 32 32 from webkitpy.common.checkout.baselineoptimizer import BaselineOptimizer 33 33 from webkitpy.common.system.filesystem_mock import MockFileSystem 34 from webkitpy.tool.mocktool import MockSCM 34 from webkitpy.layout_tests.port.factory import PortFactory 35 from webkitpy.tool.mocktool import MockHost 35 36 36 37 37 38 class TestBaselineOptimizer(BaselineOptimizer): 38 39 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) 40 43 self._mock_results_by_directory = mock_results_by_directory 41 44 … … 53 56 54 57 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) 60 64 baseline_optimizer._move_baselines('another/test-expected.txt', { 61 65 'LayoutTests/platform/chromium-win': 'aaa', … … 65 69 'LayoutTests/platform/chromium': 'aaa', 66 70 }) 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') 68 72 69 73 def test_chromium_linux_redundant_with_win(self): … … 133 137 def test_complex_shadowing(self): 134 138 # 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? 135 140 if sys.platform == 'win32': 136 141 return -
trunk/Tools/Scripts/webkitpy/tool/commands/rebaseline.py
r94325 r99106 117 117 118 118 def execute(self, options, args, tool): 119 self._baseline_optimizer = BaselineOptimizer(tool .scm(), tool.filesystem)119 self._baseline_optimizer = BaselineOptimizer(tool) 120 120 self._port = factory.get("chromium-win-win7") # FIXME: This should be selectable. 121 121 … … 147 147 148 148 def execute(self, options, args, tool): 149 self._baseline_optimizer = BaselineOptimizer(tool .scm(), tool.filesystem)149 self._baseline_optimizer = BaselineOptimizer(tool) 150 150 self._port = factory.get("chromium-win-win7") # FIXME: This should be selectable. 151 151 -
trunk/Tools/Scripts/webkitpy/tool/mocktool.py
r98753 r99106 840 840 841 841 842 class Mock Tool(object):842 class MockHost(object): 843 843 def __init__(self, log_executive=False, executive_throws_when_run=None): 844 844 self.wakeup_event = threading.Event() … … 869 869 return self._checkout 870 870 871 def port(self): 872 return self._port 873 871 874 def chromium_buildbot(self): 872 875 return self._chromium_buildbot … … 882 885 return self._irc 883 886 887 888 class MockTool(MockHost): 884 889 def path(self): 885 890 return "echo" 886 891 887 def port(self):888 return self._port889 890 892 891 893 class MockBrowser(object):
Note:
See TracChangeset
for help on using the changeset viewer.