- Revision
- 99106
- Author
- [email protected]
- Date
- 2011-11-02 15:25:56 -0700 (Wed, 02 Nov 2011)
Log 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:
Modified Paths
Diff
Modified: trunk/Tools/ChangeLog (99105 => 99106)
--- trunk/Tools/ChangeLog 2011-11-02 22:25:38 UTC (rev 99105)
+++ trunk/Tools/ChangeLog 2011-11-02 22:25:56 UTC (rev 99106)
@@ -1,3 +1,20 @@
+2011-10-31 Eric Seidel <[email protected]>
+
+ 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:
+
2011-11-02 Anders Carlsson <[email protected]>
Update for the WebKit2 API fixage.
Modified: trunk/Tools/Scripts/webkitpy/common/checkout/baselineoptimizer.py (99105 => 99106)
--- trunk/Tools/Scripts/webkitpy/common/checkout/baselineoptimizer.py 2011-11-02 22:25:38 UTC (rev 99105)
+++ trunk/Tools/Scripts/webkitpy/common/checkout/baselineoptimizer.py 2011-11-02 22:25:56 UTC (rev 99106)
@@ -26,12 +26,11 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-from webkitpy.layout_tests.port import factory as port_factory
-
# Yes, it's a hypergraph.
# FIXME: Should this function live with the ports somewhere?
-def _baseline_search_hypergraph(fs):
+# Perhaps this should move onto PortFactory?
+def _baseline_search_hypergraph(host):
hypergraph = {}
# These edges in the hypergraph aren't visible on build.webkit.org,
@@ -42,14 +41,13 @@
# FIXME: Should we get this constant from somewhere?
fallback_path = ['LayoutTests']
+ port_factory = host.port_factory
for port_name in port_factory.all_port_names():
- # FIXME: This should pass User and Executive as well to allow for easy mocking.
- # Alternatively, we should get a pre-mocked PortFactory from tool.
- port = port_factory.get(port_name, filesystem=fs)
+ port = port_factory.get(port_name)
webkit_base = port.webkit_base()
search_path = port.baseline_search_path()
if search_path:
- hypergraph[port_name] = [fs.relpath(path, webkit_base) for path in search_path] + fallback_path
+ hypergraph[port_name] = [host.filesystem.relpath(path, webkit_base) for path in search_path] + fallback_path
return hypergraph
@@ -65,10 +63,11 @@
class BaselineOptimizer(object):
- def __init__(self, scm, filesystem):
- self._scm = scm
- self._filesystem = filesystem
- self._hypergraph = _baseline_search_hypergraph(self._filesystem)
+ def __init__(self, host):
+ self._host = host
+ self._filesystem = self._host.filesystem
+ self._scm = self._host.scm()
+ self._hypergraph = _baseline_search_hypergraph(host)
self._directories = reduce(set.union, map(set, self._hypergraph.values()))
def _read_results_by_directory(self, baseline_name):
Modified: trunk/Tools/Scripts/webkitpy/common/checkout/baselineoptimizer_unittest.py (99105 => 99106)
--- trunk/Tools/Scripts/webkitpy/common/checkout/baselineoptimizer_unittest.py 2011-11-02 22:25:38 UTC (rev 99105)
+++ trunk/Tools/Scripts/webkitpy/common/checkout/baselineoptimizer_unittest.py 2011-11-02 22:25:56 UTC (rev 99106)
@@ -31,12 +31,15 @@
from webkitpy.common.checkout.baselineoptimizer import BaselineOptimizer
from webkitpy.common.system.filesystem_mock import MockFileSystem
-from webkitpy.tool.mocktool import MockSCM
+from webkitpy.layout_tests.port.factory import PortFactory
+from webkitpy.tool.mocktool import MockHost
class TestBaselineOptimizer(BaselineOptimizer):
def __init__(self, mock_results_by_directory):
- BaselineOptimizer.__init__(self, MockSCM(), MockFileSystem())
+ host = MockHost()
+ host.port_factory = PortFactory(host) # We want a real PortFactory, but it should use mocks.
+ BaselineOptimizer.__init__(self, host)
self._mock_results_by_directory = mock_results_by_directory
# We override this method for testing so we don't have to construct an
@@ -52,11 +55,12 @@
self.assertEqual(new_results_by_directory, expected_new_results_by_directory)
def test_move_baselines(self):
- fs = MockFileSystem()
- fs.write_binary_file('/mock-checkout/LayoutTests/platform/chromium-win/another/test-expected.txt', 'result A')
- fs.write_binary_file('/mock-checkout/LayoutTests/platform/chromium-cg-mac/another/test-expected.txt', 'result A')
- fs.write_binary_file('/mock-checkout/LayoutTests/platform/chromium/another/test-expected.txt', 'result B')
- baseline_optimizer = BaselineOptimizer(MockSCM(), fs)
+ host = MockHost()
+ host.port_factory = PortFactory(host) # We want a real PortFactory, but it should use mocks.
+ host.filesystem.write_binary_file('/mock-checkout/LayoutTests/platform/chromium-win/another/test-expected.txt', 'result A')
+ host.filesystem.write_binary_file('/mock-checkout/LayoutTests/platform/chromium-cg-mac/another/test-expected.txt', 'result A')
+ host.filesystem.write_binary_file('/mock-checkout/LayoutTests/platform/chromium/another/test-expected.txt', 'result B')
+ baseline_optimizer = BaselineOptimizer(host)
baseline_optimizer._move_baselines('another/test-expected.txt', {
'LayoutTests/platform/chromium-win': 'aaa',
'LayoutTests/platform/chromium-cg-mac': 'aaa',
@@ -64,7 +68,7 @@
}, {
'LayoutTests/platform/chromium': 'aaa',
})
- self.assertEqual(fs.read_binary_file('/mock-checkout/LayoutTests/platform/chromium/another/test-expected.txt'), 'result A')
+ self.assertEqual(host.filesystem.read_binary_file('/mock-checkout/LayoutTests/platform/chromium/another/test-expected.txt'), 'result A')
def test_chromium_linux_redundant_with_win(self):
self._assertOptimization({
@@ -132,6 +136,7 @@
def test_complex_shadowing(self):
# This test relies on OS specific functionality, so it doesn't work on Windows.
+ # FIXME: What functionality does this rely on? When can we remove this if?
if sys.platform == 'win32':
return
self._assertOptimization({
Modified: trunk/Tools/Scripts/webkitpy/tool/commands/rebaseline.py (99105 => 99106)
--- trunk/Tools/Scripts/webkitpy/tool/commands/rebaseline.py 2011-11-02 22:25:38 UTC (rev 99105)
+++ trunk/Tools/Scripts/webkitpy/tool/commands/rebaseline.py 2011-11-02 22:25:56 UTC (rev 99106)
@@ -116,7 +116,7 @@
return self._tool.filesystem.relpath(file_name, self._port.layout_tests_dir())
def execute(self, options, args, tool):
- self._baseline_optimizer = BaselineOptimizer(tool.scm(), tool.filesystem)
+ self._baseline_optimizer = BaselineOptimizer(tool)
self._port = factory.get("chromium-win-win7") # FIXME: This should be selectable.
for test_name in map(self._to_test_name, test_files.find(self._port, args)):
@@ -146,7 +146,7 @@
return self._tool.filesystem.relpath(file_name, self._port.layout_tests_dir())
def execute(self, options, args, tool):
- self._baseline_optimizer = BaselineOptimizer(tool.scm(), tool.filesystem)
+ self._baseline_optimizer = BaselineOptimizer(tool)
self._port = factory.get("chromium-win-win7") # FIXME: This should be selectable.
for test_name in map(self._to_test_name, test_files.find(self._port, args)):
Modified: trunk/Tools/Scripts/webkitpy/tool/mocktool.py (99105 => 99106)
--- trunk/Tools/Scripts/webkitpy/tool/mocktool.py 2011-11-02 22:25:38 UTC (rev 99105)
+++ trunk/Tools/Scripts/webkitpy/tool/mocktool.py 2011-11-02 22:25:56 UTC (rev 99106)
@@ -839,7 +839,7 @@
return "MOCK Web result, convert 404 to None=%s" % convert_404_to_None
-class MockTool(object):
+class MockHost(object):
def __init__(self, log_executive=False, executive_throws_when_run=None):
self.wakeup_event = threading.Event()
self.bugs = MockBugzilla()
@@ -868,6 +868,9 @@
def checkout(self):
return self._checkout
+ def port(self):
+ return self._port
+
def chromium_buildbot(self):
return self._chromium_buildbot
@@ -881,13 +884,12 @@
def irc(self):
return self._irc
+
+class MockTool(MockHost):
def path(self):
return "echo"
- def port(self):
- return self._port
-
class MockBrowser(object):
params = {}