Remove deprecated free functions in port.factory
authoreric@webkit.org <eric@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 3 Nov 2011 20:24:16 +0000 (20:24 +0000)
committereric@webkit.org <eric@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 3 Nov 2011 20:24:16 +0000 (20:24 +0000)
https://bugs.webkit.org/show_bug.cgi?id=71494

Reviewed by Adam Barth.

I removed port.factory.get, get_all, and all_port_names -- long-since deprecated
free functions in factory.py.  To remove these required fixing all callsites
to use MockHost, Host, or PortFactory where appropriate.  After this change
we're only left with a handfull of places where we inappropraitely use a
real Executive, FileSystem or User object during unittesting.

* Scripts/webkitpy/common/checkout/baselineoptimizer_unittest.py:
 - These PortFactory overrides were from an earlier edition of my previous patch
   in the end, I removed MockPortFactory so all tests ended up with this same
   real PortFactory() with a MockHost.  This was simply redundent code.
* Scripts/webkitpy/layout_tests/controllers/manager_unittest.py:
 - Use MockHost to get a mocked-out PortFactory.
* Scripts/webkitpy/layout_tests/controllers/manager_worker_broker.py:
 - This code has no access to a Host object, so we just use a default PortFactory
   for now.  This will still incorrectly create real Executive/FileSystem objects
   durring unittesting, which is wrong. :(
* Scripts/webkitpy/layout_tests/controllers/manager_worker_broker_unittest.py:
 - Use a MockHost to get a mocked PortFactory.
* Scripts/webkitpy/layout_tests/controllers/test_expectations_editor_unittest.py:
 - Use a MockHost to get a mocked PortFactory.
* Scripts/webkitpy/layout_tests/models/test_configuration_unittest.py:
 - ditto.
* Scripts/webkitpy/layout_tests/models/test_expectations_unittest.py:
 - ditto.
* Scripts/webkitpy/layout_tests/port/__init__.py:
 - factory.get no longer exists.  Yay!
* Scripts/webkitpy/layout_tests/port/chromium_gpu_unittest.py:
 - Use a MockHost to get a mocked PortFactory.
   To do this efficiently, I created a helper function
   and combined all these (mostly redundant) tests into one test
   with several calls to the helper function.
* Scripts/webkitpy/layout_tests/port/chromium_unittest.py:
 - Pass MockUser and MockExecutive in these port testing subclasses.
 - I also removed a bunch of unecessary uses of mocktool. namespacing.
* Scripts/webkitpy/layout_tests/port/chromium_win.py:
 - Awesome windows hacks should only happen on win32.  Once we started
   using MockExecutives these 'svn help' commands started printing in
   other tests, which is how I found this bug.
* Scripts/webkitpy/layout_tests/port/dryrun.py:
 - DryRunPort has no Host, so just use a PortFactory() directly.
   This will do the wrong thing if we're unittesting the DryRun port
   but it's no worse than the existing code.
* Scripts/webkitpy/layout_tests/port/factory.py:
 - Remove the free functions.
 - Fix argument overriding to be able to override None.
* Scripts/webkitpy/layout_tests/port/factory_unittest.py:
 - Use a mocked-out PortFactory during testing.
* Scripts/webkitpy/layout_tests/port/google_chrome_unittest.py:
 - Pass MockExecutive and MockUser to these manual Port instantiations.
* Scripts/webkitpy/layout_tests/port/mock_drt.py:
 - No access to a Host object here, so just using PortFactory directly.
   This is wrong, but no more wrong than the existing code was.
* Scripts/webkitpy/layout_tests/port/mock_drt_unittest.py:
 - Use a MockHost to get a mocked out PortFactory.
* Scripts/webkitpy/layout_tests/port/test.py:
 - Use our fancy _set_default_overriding_none system to clean this code up and pass a MockExecutive.
* Scripts/webkitpy/layout_tests/port/win.py:
 - Don't run cmd /c ver from WinPort.__init__ or it shows up in unittests which have logging MockExecutive
   now that we're actually passing MockExecutive to most Port instantiations during testing.
* Scripts/webkitpy/layout_tests/port/win_unittest.py:
 - Pass our new "unittesting" bool to _detect_version when actually unittesting.
* Scripts/webkitpy/layout_tests/run_webkit_tests.py:
 - Host is the future.
* Scripts/webkitpy/layout_tests/run_webkit_tests_integrationtest.py:
 - Use a MockHost to get a mocked out PortFactory.  Once we have a mocked PortFactory
   we don't need to pass MockUser explicitly, it does that automatically for us.
* Scripts/webkitpy/layout_tests/views/printing_unittest.py:
 - Use a MockHost to get a mocked out PortFactory.
* Scripts/webkitpy/style/checkers/test_expectations.py:
 - We don't have access to a Host object, so using PortFactory() directly.
* Scripts/webkitpy/style/checkers/test_expectations_unittest.py:
 - Remove unused variable.
* Scripts/webkitpy/to_be_moved/rebaseline_chromium_webkit_tests.py:
 - Host isn't accessible here, so using PortFactory() directly, which
   although unfortunate is no worse than before.
* Scripts/webkitpy/to_be_moved/rebaseline_chromium_webkit_tests_unittest.py:
 - Testing is much easier when you don't need to hack global state...
* Scripts/webkitpy/tool/commands/expectations.py:
 - Use the port_factory on the tool.
* Scripts/webkitpy/tool/commands/rebaseline.py:
 - ditto.
* Scripts/webkitpy/tool/commands/rebaseline_unittest.py:
 - This unittest was wrong.  It was trying to pass the tool object, but failing to pass
   the arguments in the right order.  Fixing that made it use a MockFileSystem
   (like it had been trying to), which then required us to actually populate
   that MockFileSystem with fake expectation files (instead of using the ones on the real disk).
* Scripts/webkitpy/tool/commands/rebaselineserver.py:
 - Get the port_factory from the tool.
* Scripts/webkitpy/tool/servers/gardeningserver.py:
 - Ditto.
* Scripts/webkitpy/tool/servers/gardeningserver_unittest.py:
 - Use a MockHost to get a mocked out Port object.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@99233 268f45cc-cd09-0410-ab3c-d52691b4dbfc

34 files changed:
Tools/ChangeLog
Tools/Scripts/webkitpy/common/checkout/baselineoptimizer_unittest.py
Tools/Scripts/webkitpy/layout_tests/controllers/manager_unittest.py
Tools/Scripts/webkitpy/layout_tests/controllers/manager_worker_broker.py
Tools/Scripts/webkitpy/layout_tests/controllers/manager_worker_broker_unittest.py
Tools/Scripts/webkitpy/layout_tests/controllers/test_expectations_editor_unittest.py
Tools/Scripts/webkitpy/layout_tests/models/test_configuration_unittest.py
Tools/Scripts/webkitpy/layout_tests/models/test_expectations_unittest.py
Tools/Scripts/webkitpy/layout_tests/port/__init__.py
Tools/Scripts/webkitpy/layout_tests/port/chromium_gpu_unittest.py
Tools/Scripts/webkitpy/layout_tests/port/chromium_unittest.py
Tools/Scripts/webkitpy/layout_tests/port/chromium_win.py
Tools/Scripts/webkitpy/layout_tests/port/dryrun.py
Tools/Scripts/webkitpy/layout_tests/port/factory.py
Tools/Scripts/webkitpy/layout_tests/port/factory_unittest.py
Tools/Scripts/webkitpy/layout_tests/port/google_chrome_unittest.py
Tools/Scripts/webkitpy/layout_tests/port/mock_drt.py
Tools/Scripts/webkitpy/layout_tests/port/mock_drt_unittest.py
Tools/Scripts/webkitpy/layout_tests/port/test.py
Tools/Scripts/webkitpy/layout_tests/port/win.py
Tools/Scripts/webkitpy/layout_tests/port/win_unittest.py
Tools/Scripts/webkitpy/layout_tests/run_webkit_tests.py
Tools/Scripts/webkitpy/layout_tests/run_webkit_tests_integrationtest.py
Tools/Scripts/webkitpy/layout_tests/views/printing_unittest.py
Tools/Scripts/webkitpy/style/checkers/test_expectations.py
Tools/Scripts/webkitpy/style/checkers/test_expectations_unittest.py
Tools/Scripts/webkitpy/to_be_moved/rebaseline_chromium_webkit_tests.py
Tools/Scripts/webkitpy/to_be_moved/rebaseline_chromium_webkit_tests_unittest.py
Tools/Scripts/webkitpy/tool/commands/expectations.py
Tools/Scripts/webkitpy/tool/commands/rebaseline.py
Tools/Scripts/webkitpy/tool/commands/rebaseline_unittest.py
Tools/Scripts/webkitpy/tool/commands/rebaselineserver.py
Tools/Scripts/webkitpy/tool/servers/gardeningserver.py
Tools/Scripts/webkitpy/tool/servers/gardeningserver_unittest.py

index 96777ee..0f0834d 100644 (file)
@@ -1,3 +1,103 @@
+2011-11-03  Eric Seidel  <eric@webkit.org>
+
+        Remove deprecated free functions in port.factory
+        https://bugs.webkit.org/show_bug.cgi?id=71494
+
+        Reviewed by Adam Barth.
+
+        I removed port.factory.get, get_all, and all_port_names -- long-since deprecated
+        free functions in factory.py.  To remove these required fixing all callsites
+        to use MockHost, Host, or PortFactory where appropriate.  After this change
+        we're only left with a handfull of places where we inappropraitely use a
+        real Executive, FileSystem or User object during unittesting.
+
+        * Scripts/webkitpy/common/checkout/baselineoptimizer_unittest.py:
+         - These PortFactory overrides were from an earlier edition of my previous patch
+           in the end, I removed MockPortFactory so all tests ended up with this same
+           real PortFactory() with a MockHost.  This was simply redundent code.
+        * Scripts/webkitpy/layout_tests/controllers/manager_unittest.py:
+         - Use MockHost to get a mocked-out PortFactory.
+        * Scripts/webkitpy/layout_tests/controllers/manager_worker_broker.py:
+         - This code has no access to a Host object, so we just use a default PortFactory
+           for now.  This will still incorrectly create real Executive/FileSystem objects
+           durring unittesting, which is wrong. :(
+        * Scripts/webkitpy/layout_tests/controllers/manager_worker_broker_unittest.py:
+         - Use a MockHost to get a mocked PortFactory.
+        * Scripts/webkitpy/layout_tests/controllers/test_expectations_editor_unittest.py:
+         - Use a MockHost to get a mocked PortFactory.
+        * Scripts/webkitpy/layout_tests/models/test_configuration_unittest.py:
+         - ditto.
+        * Scripts/webkitpy/layout_tests/models/test_expectations_unittest.py:
+         - ditto.
+        * Scripts/webkitpy/layout_tests/port/__init__.py:
+         - factory.get no longer exists.  Yay!
+        * Scripts/webkitpy/layout_tests/port/chromium_gpu_unittest.py:
+         - Use a MockHost to get a mocked PortFactory.
+           To do this efficiently, I created a helper function
+           and combined all these (mostly redundant) tests into one test
+           with several calls to the helper function.
+        * Scripts/webkitpy/layout_tests/port/chromium_unittest.py:
+         - Pass MockUser and MockExecutive in these port testing subclasses.
+         - I also removed a bunch of unecessary uses of mocktool. namespacing.
+        * Scripts/webkitpy/layout_tests/port/chromium_win.py:
+         - Awesome windows hacks should only happen on win32.  Once we started
+           using MockExecutives these 'svn help' commands started printing in
+           other tests, which is how I found this bug.
+        * Scripts/webkitpy/layout_tests/port/dryrun.py:
+         - DryRunPort has no Host, so just use a PortFactory() directly.
+           This will do the wrong thing if we're unittesting the DryRun port
+           but it's no worse than the existing code.
+        * Scripts/webkitpy/layout_tests/port/factory.py:
+         - Remove the free functions.
+         - Fix argument overriding to be able to override None.
+        * Scripts/webkitpy/layout_tests/port/factory_unittest.py:
+         - Use a mocked-out PortFactory during testing.
+        * Scripts/webkitpy/layout_tests/port/google_chrome_unittest.py:
+         - Pass MockExecutive and MockUser to these manual Port instantiations.
+        * Scripts/webkitpy/layout_tests/port/mock_drt.py:
+         - No access to a Host object here, so just using PortFactory directly.
+           This is wrong, but no more wrong than the existing code was.
+        * Scripts/webkitpy/layout_tests/port/mock_drt_unittest.py:
+         - Use a MockHost to get a mocked out PortFactory.
+        * Scripts/webkitpy/layout_tests/port/test.py:
+         - Use our fancy _set_default_overriding_none system to clean this code up and pass a MockExecutive.
+        * Scripts/webkitpy/layout_tests/port/win.py:
+         - Don't run cmd /c ver from WinPort.__init__ or it shows up in unittests which have logging MockExecutive
+           now that we're actually passing MockExecutive to most Port instantiations during testing.
+        * Scripts/webkitpy/layout_tests/port/win_unittest.py:
+         - Pass our new "unittesting" bool to _detect_version when actually unittesting.
+        * Scripts/webkitpy/layout_tests/run_webkit_tests.py:
+         - Host is the future.
+        * Scripts/webkitpy/layout_tests/run_webkit_tests_integrationtest.py:
+         - Use a MockHost to get a mocked out PortFactory.  Once we have a mocked PortFactory
+           we don't need to pass MockUser explicitly, it does that automatically for us.
+        * Scripts/webkitpy/layout_tests/views/printing_unittest.py:
+         - Use a MockHost to get a mocked out PortFactory.
+        * Scripts/webkitpy/style/checkers/test_expectations.py:
+         - We don't have access to a Host object, so using PortFactory() directly.
+        * Scripts/webkitpy/style/checkers/test_expectations_unittest.py:
+         - Remove unused variable.
+        * Scripts/webkitpy/to_be_moved/rebaseline_chromium_webkit_tests.py:
+         - Host isn't accessible here, so using PortFactory() directly, which
+           although unfortunate is no worse than before.
+        * Scripts/webkitpy/to_be_moved/rebaseline_chromium_webkit_tests_unittest.py:
+         - Testing is much easier when you don't need to hack global state...
+        * Scripts/webkitpy/tool/commands/expectations.py:
+         - Use the port_factory on the tool.
+        * Scripts/webkitpy/tool/commands/rebaseline.py:
+         - ditto.
+        * Scripts/webkitpy/tool/commands/rebaseline_unittest.py:
+         - This unittest was wrong.  It was trying to pass the tool object, but failing to pass
+           the arguments in the right order.  Fixing that made it use a MockFileSystem
+           (like it had been trying to), which then required us to actually populate
+           that MockFileSystem with fake expectation files (instead of using the ones on the real disk).
+        * Scripts/webkitpy/tool/commands/rebaselineserver.py:
+         - Get the port_factory from the tool.
+        * Scripts/webkitpy/tool/servers/gardeningserver.py:
+         - Ditto.
+        * Scripts/webkitpy/tool/servers/gardeningserver_unittest.py:
+         - Use a MockHost to get a mocked out Port object.
+
 2011-11-03  Raphael Kubo da Costa  <kubo@profusion.mobi>
 
         [EFL] DRT: Allow choosing which backing store to use.
index 1d3e573..72d7a7e 100644 (file)
@@ -31,14 +31,12 @@ import unittest
 
 from webkitpy.common.checkout.baselineoptimizer import BaselineOptimizer
 from webkitpy.common.system.filesystem_mock import MockFileSystem
-from webkitpy.layout_tests.port.factory import PortFactory
 from webkitpy.common.host_mock import MockHost
 
 
 class TestBaselineOptimizer(BaselineOptimizer):
     def __init__(self, mock_results_by_directory):
         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
 
@@ -56,7 +54,6 @@ class BaselineOptimizerTest(unittest.TestCase):
 
     def test_move_baselines(self):
         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')
index 70c9026..e1eed08 100644 (file)
@@ -38,7 +38,6 @@ from webkitpy.common.system.filesystem_mock import MockFileSystem
 from webkitpy.common.system import outputcapture
 from webkitpy.thirdparty.mock import Mock
 from webkitpy import layout_tests
-from webkitpy.layout_tests import port
 from webkitpy.layout_tests.port import port_testcase
 
 from webkitpy import layout_tests
@@ -49,6 +48,7 @@ from webkitpy.layout_tests.views import printing
 from webkitpy.tool.mocktool import MockOptions
 from webkitpy.common.system.executive_mock import MockExecutive
 from webkitpy.common.system.user_mock import MockUser
+from webkitpy.common.host_mock import MockHost
 
 
 class ManagerWrapper(Manager):
@@ -71,7 +71,8 @@ class ShardingTests(unittest.TestCase):
 
     def get_shards(self, num_workers, fully_parallel, test_list=None):
         test_list = test_list or self.test_list
-        port = layout_tests.port.get(port_name='test')
+        host = MockHost()
+        port = host.port_factory.get(port_name='test')
         port._filesystem = MockFileSystem()
         # FIXME: This should use MockOptions() instead of Mock()
         self.manager = ManagerWrapper(port=port, options=Mock(), printer=Mock())
@@ -159,8 +160,8 @@ class ManagerTest(unittest.TestCase):
 
     def test_fallback_path_in_config(self):
         options = self.get_options()
-
-        port = layout_tests.port.get('test-mac-leopard', options=options)
+        host = MockHost()
+        port = host.port_factory.get('test-mac-leopard', options=options)
         printer = self.get_printer()
         manager = Manager(port, port.options, printer)
         manager.print_config()
@@ -186,8 +187,8 @@ class ManagerTest(unittest.TestCase):
                     self._finished_list_called = True
 
         options, args = run_webkit_tests.parse_args(['--platform=test', '--print=nothing', 'http/tests/passes', 'passes'])
-        # Note we do not pass a filesystem as the "test port" magically suplies its own mock filesystem.
-        port = layout_tests.port.get(port_name=options.platform, options=options, user=MockUser(), executive=MockExecutive())
+        host = MockHost()
+        port = host.port_factory.get(port_name=options.platform, options=options, user=MockUser(), executive=MockExecutive())
         run_webkit_tests._set_up_derived_options(port, options)
         printer = printing.Printer(port, options, StringIO.StringIO(), StringIO.StringIO(), configure_logging=True)
         manager = LockCheckingManager(port, options, printer)
@@ -243,7 +244,8 @@ class ManagerTest(unittest.TestCase):
 
     def integration_test_needs_servers(self):
         def get_manager_with_tests(test_names):
-            port = layout_tests.port.get()
+            host = MockHost()
+            port = host.port_factory.get()
             manager = Manager(port, options=MockOptions(test_list=None, http=True), printer=Mock())
             manager.collect_tests(test_names)
             return manager
@@ -286,7 +288,8 @@ class NaturalCompareTest(unittest.TestCase):
 
 class KeyCompareTest(unittest.TestCase):
     def setUp(self):
-        self.port = layout_tests.port.get('test')
+        host = MockHost()
+        self.port = host.port_factory.get('test')
 
     def assert_cmp(self, x, y, result):
         self.assertEquals(cmp(test_key(self.port, x), test_key(self.port, y)), result)
index e431f53..e8a5114 100755 (executable)
@@ -52,7 +52,7 @@ try:
 except ImportError:
     multiprocessing = None
 
-from webkitpy import layout_tests
+from webkitpy.layout_tests.port.factory import PortFactory
 from webkitpy.layout_tests.controllers import message_broker
 from webkitpy.layout_tests.views import printing
 
@@ -99,8 +99,7 @@ def get(port, options, client, worker_class):
         queue_class = multiprocessing.Queue
         manager_class = _MultiProcessManager
     else:
-        raise ValueError("unsupported value for --worker-model: %s" %
-                         worker_model)
+        raise ValueError("unsupported value for --worker-model: %s" % worker_model)
 
     broker = message_broker.Broker(options, queue_class)
     return manager_class(broker, port, options, client, worker_class)
@@ -253,7 +252,8 @@ if multiprocessing:
 
         def run(self):
             options = self._options
-            port_obj = layout_tests.port.get(self._platform_name, options)
+            # FIXME: This should get the PortFactory from the Host.
+            port_obj = PortFactory().get(self._platform_name, options)
 
             # The unix multiprocessing implementation clones the
             # log handler configuration into the child processes,
@@ -263,8 +263,7 @@ if multiprocessing:
             # FIXME: this won't work if the calling process is logging
             # somewhere other than sys.stderr and sys.stdout, but I'm not sure
             # if this will be an issue in practice.
-            printer = printing.Printer(port_obj, options, sys.stderr, sys.stdout,
-                configure_logging)
+            printer = printing.Printer(port_obj, options, sys.stderr, sys.stdout, configure_logging)
             self._client.run(port_obj)
             printer.cleanup()
 
index b224c1d..e80765a 100644 (file)
@@ -38,12 +38,14 @@ except ImportError:
 
 
 from webkitpy.common.system import outputcapture
+from webkitpy.common.host_mock import MockHost
 
 from webkitpy.layout_tests import port
 from webkitpy.layout_tests.controllers import manager_worker_broker
 from webkitpy.layout_tests.controllers import message_broker
 from webkitpy.layout_tests.views import printing
 
+
 # In order to reliably control when child workers are starting and stopping,
 # we use a pair of global variables to hold queues used for messaging. Ideally
 # we wouldn't need globals, but we can't pass these through a lexical closure
@@ -59,7 +61,9 @@ def make_broker(manager, worker_model, start_queue=None, stop_queue=None):
     starting_queue = start_queue
     stopping_queue = stop_queue
     options = get_options(worker_model)
-    return manager_worker_broker.get(port.get("test"), options, manager, _TestWorker)
+    host = MockHost()
+    test_port = host.port_factory.get("test")
+    return manager_worker_broker.get(test_port, options, manager, _TestWorker)
 
 
 class _TestWorker(manager_worker_broker.AbstractWorker):
index a819fae..f365d77 100644 (file)
 
 import unittest
 
-from webkitpy.layout_tests import port
+from webkitpy.common.host_mock import MockHost
+
 from webkitpy.layout_tests.controllers.test_expectations_editor import *
 from webkitpy.layout_tests.models.test_configuration import *
 from webkitpy.layout_tests.models.test_expectations import *
 from webkitpy.layout_tests.models.test_configuration import *
-from webkitpy.layout_tests.port import base
 
 
 class MockBugManager(object):
@@ -70,7 +70,8 @@ class TestExpectationEditorTests(unittest.TestCase):
     ])
 
     def __init__(self, testFunc):
-        self.test_port = port.get('test-win-xp', None)
+        host = MockHost()
+        self.test_port = host.port_factory.get('test-win-xp', None)
         self.full_test_list = ['failures/expected/keyboard.html', 'failures/expected/audio.html']
         unittest.TestCase.__init__(self, testFunc)
 
index c4d7e8a..da0643e 100644 (file)
@@ -28,7 +28,8 @@
 
 import unittest
 
-from webkitpy.layout_tests import port
+from webkitpy.common.host_mock import MockHost
+
 from webkitpy.layout_tests.models.test_configuration import *
 
 
@@ -90,7 +91,9 @@ class TestConfigurationTest(unittest.TestCase):
 
     def test_eq(self):
         self.assertEquals(TestConfiguration('xp', 'x86', 'release', 'cpu'), TestConfiguration('xp', 'x86', 'release', 'cpu'))
-        self.assertEquals(TestConfiguration.from_port(port.get('test-win-xp', None)), TestConfiguration('xp', 'x86', 'release', 'cpu'))
+        host = MockHost()
+        test_port = host.port_factory.get('test-win-xp', None)
+        self.assertEquals(TestConfiguration.from_port(test_port), TestConfiguration('xp', 'x86', 'release', 'cpu'))
         self.assertNotEquals(TestConfiguration('xp', 'x86', 'release', 'gpu'), TestConfiguration('xp', 'x86', 'release', 'cpu'))
         self.assertNotEquals(TestConfiguration('xp', 'x86', 'debug', 'cpu'), TestConfiguration('xp', 'x86', 'release', 'cpu'))
 
@@ -102,7 +105,9 @@ class TestConfigurationTest(unittest.TestCase):
         self.assertEquals(set(['xp', 'x86', 'release', 'cpu']), set(result_config_values))
 
     def test_from_port(self):
-        config = TestConfiguration.from_port(port.get('test-win-xp', None))
+        host = MockHost()
+        test_port = host.port_factory.get('test-win-xp', None)
+        config = TestConfiguration.from_port(test_port)
         self.assertEquals('<xp, x86, release, cpu>', str(config))
 
 
index ccf4ba5..1a64f21 100644 (file)
@@ -29,8 +29,8 @@
 
 import unittest
 
-from webkitpy.layout_tests import port
-from webkitpy.layout_tests.port import base
+from webkitpy.common.host_mock import MockHost
+
 from webkitpy.layout_tests.models.test_configuration import *
 from webkitpy.layout_tests.models.test_expectations import *
 from webkitpy.layout_tests.models.test_configuration import *
@@ -92,7 +92,8 @@ class Base(unittest.TestCase):
     # being tested is Windows XP, Release build.
 
     def __init__(self, testFunc, setUp=None, tearDown=None, description=None):
-        self._port = port.get('test-win-xp', None)
+        host = MockHost()
+        self._port = host.port_factory.get('test-win-xp', None)
         self._fs = self._port._filesystem
         self._exp = None
         unittest.TestCase.__init__(self, testFunc)
@@ -453,7 +454,8 @@ class TestExpectationParserTests(unittest.TestCase):
         self.assertEqual(len(expectation.errors), 0)
 
     def test_parse_empty_string(self):
-        test_port = port.get('test-win-xp', None)
+        host = MockHost()
+        test_port = host.port_factory.get('test-win-xp', None)
         test_port.test_exists = lambda test: True
         test_config = test_port.test_configuration()
         full_test_list = []
@@ -465,7 +467,8 @@ class TestExpectationParserTests(unittest.TestCase):
 
 class TestExpectationSerializerTests(unittest.TestCase):
     def __init__(self, testFunc):
-        test_port = port.get('test-win-xp', None)
+        host = MockHost()
+        test_port = host.port_factory.get('test-win-xp', None)
         self._converter = TestConfigurationConverter(test_port.all_test_configurations(), test_port.configuration_specifier_macros())
         self._serializer = TestExpectationSerializer(self._converter)
         unittest.TestCase.__init__(self, testFunc)
index bc70c72..e584698 100644 (file)
@@ -29,8 +29,6 @@
 
 """Port-specific entrypoints for the layout tests test infrastructure."""
 
-from factory import get
-
 import builders  # Why is this in port?
 
 from base import Port  # It's possible we don't need to export this virtual baseclass outside the module.
index 789d72f..7015c4a 100755 (executable)
 import sys
 import unittest
 
-from webkitpy.tool import mocktool
 import chromium_gpu
 
-from webkitpy.layout_tests.port import factory
+from webkitpy.tool.mocktool import MockOptions
+from webkitpy.common.host_mock import MockHost
 from webkitpy.layout_tests.port import port_testcase
 
+
 class ChromiumGpuTest(unittest.TestCase):
     def integration_test_chromium_gpu_linux(self):
         if sys.platform not in ('linux2', 'linux3'):
@@ -58,7 +59,7 @@ class ChromiumGpuTest(unittest.TestCase):
 
     def assert_port_works(self, port_name, input_name=None, platform=None):
         # test that we got the right port
-        mock_options = mocktool.MockOptions(accelerated_compositing=None,
+        mock_options = MockOptions(accelerated_compositing=None,
                                             accelerated_2d_canvas=None,
                                             builder_name='foo',
                                             child_processes=None)
@@ -102,35 +103,24 @@ class ChromiumGpuTest(unittest.TestCase):
             self.assertTrue(port._filesystem.exists(port.abspath_for_test(path)))
             self.assertFalse(path in files)
 
-    def test_chromium_gpu__vista(self):
-        port = factory.get('chromium-gpu-win-vista')
-        self.assertEquals(port.name(), 'chromium-gpu-win-vista')
-        self.assertEquals(port.baseline_path(), port._webkit_baseline_path('chromium-gpu-win'))
-
-    def test_chromium_gpu__xp(self):
-        port = factory.get('chromium-gpu-win-xp')
-        self.assertEquals(port.name(), 'chromium-gpu-win-xp')
-        self.assertEquals(port.baseline_path(), port._webkit_baseline_path('chromium-gpu-win'))
-
-    def test_chromium_gpu__win7(self):
-        port = factory.get('chromium-gpu-win-win7')
-        self.assertEquals(port.name(), 'chromium-gpu-win-win7')
-        self.assertEquals(port.baseline_path(), port._webkit_baseline_path('chromium-gpu-win'))
-
-    def test_chromium_gpu__leopard(self):
-        port = factory.get('chromium-gpu-cg-mac-leopard')
-        self.assertEquals(port.name(), 'chromium-gpu-cg-mac-leopard')
-        self.assertEquals(port.baseline_path(), port._webkit_baseline_path('chromium-gpu-cg-mac'))
+    def _assert_baseline_path(self, port_name, baseline_path):
+        host = MockHost()
+        port = host.port_factory.get(port_name)
+        self.assertEquals(port.name(), port_name)
+        self.assertEquals(port.baseline_path(), port._webkit_baseline_path(baseline_path))
 
-    def test_chromium_gpu__snowleopard(self):
-        port = factory.get('chromium-gpu-cg-mac-snowleopard')
-        self.assertEquals(port.name(), 'chromium-gpu-cg-mac-snowleopard')
-        self.assertEquals(port.baseline_path(), port._webkit_baseline_path('chromium-gpu-cg-mac'))
+    def test_baseline_paths(self):
+        self._assert_baseline_path('chromium-gpu-win-vista', 'chromium-gpu-win')
+        self._assert_baseline_path('chromium-gpu-win-xp', 'chromium-gpu-win')
+        self._assert_baseline_path('chromium-gpu-win-win7', 'chromium-gpu-win')
+        self._assert_baseline_path('chromium-gpu-cg-mac-leopard', 'chromium-gpu-cg-mac')
+        self._assert_baseline_path('chromium-gpu-cg-mac-snowleopard', 'chromium-gpu-cg-mac')
 
     def test_graphics_type(self):
-        port = factory.get('chromium-gpu-cg-mac')
+        host = MockHost()
+        port = host.port_factory.get('chromium-gpu-cg-mac')
         self.assertEquals('gpu-cg', port.graphics_type())
-        port = factory.get('chromium-gpu-mac')
+        port = host.port_factory.get('chromium-gpu-mac')
         self.assertEquals('gpu', port.graphics_type())
 
 
index dec09c4..de0e982 100644 (file)
@@ -30,11 +30,11 @@ import unittest
 import StringIO
 
 from webkitpy.common.system import logtesting
-from webkitpy.common.system import executive_mock
-from webkitpy.common.system import filesystem_mock
-from webkitpy.tool import mocktool
+from webkitpy.common.system.executive_mock import MockExecutive, MockExecutive2
+from webkitpy.common.system.filesystem_mock import MockFileSystem
+from webkitpy.common.system.user_mock import MockUser
 from webkitpy.thirdparty.mock import Mock
-
+from webkitpy.tool.mocktool import MockOptions
 
 import chromium
 import chromium_linux
@@ -184,10 +184,8 @@ class ChromiumPortTest(port_testcase.PortTestCase):
 
     class TestMacPort(chromium_mac.ChromiumMacPort):
         def __init__(self, options):
-            # FIXME: This should use MockExecutive and MockUser as well.
-            chromium_mac.ChromiumMacPort.__init__(self,
-                                                  options=options,
-                                                  filesystem=filesystem_mock.MockFileSystem())
+            chromium_mac.ChromiumMacPort.__init__(self, options=options,
+                filesystem=MockFileSystem(), user=MockUser(), executive=MockExecutive())
 
         def default_configuration(self):
             self.default_configuration_called = True
@@ -195,10 +193,8 @@ class ChromiumPortTest(port_testcase.PortTestCase):
 
     class TestLinuxPort(chromium_linux.ChromiumLinuxPort):
         def __init__(self, options):
-            # FIXME: This should use MockExecutive and MockUser as well.
-            chromium_linux.ChromiumLinuxPort.__init__(self,
-                                                      options=options,
-                                                      filesystem=filesystem_mock.MockFileSystem())
+            chromium_linux.ChromiumLinuxPort.__init__(self, options=options,
+                filesystem=MockFileSystem(), user=MockUser(), executive=MockExecutive())
 
         def default_configuration(self):
             self.default_configuration_called = True
@@ -206,29 +202,25 @@ class ChromiumPortTest(port_testcase.PortTestCase):
 
     class TestWinPort(chromium_win.ChromiumWinPort):
         def __init__(self, options):
-            # FIXME: This should use MockExecutive and MockUser as well.
-            chromium_win.ChromiumWinPort.__init__(self,
-                                                  options=options,
-                                                  filesystem=filesystem_mock.MockFileSystem())
+            chromium_win.ChromiumWinPort.__init__(self, options=options,
+                filesystem=MockFileSystem(), user=MockUser(), executive=MockExecutive())
 
         def default_configuration(self):
             self.default_configuration_called = True
             return 'default'
 
     def test_path_to_image_diff(self):
-        mock_options = mocktool.MockOptions()
+        mock_options = MockOptions()
         port = ChromiumPortTest.TestLinuxPort(options=mock_options)
-        self.assertTrue(port._path_to_image_diff().endswith(
-            '/out/default/ImageDiff'))
+        # FIXME: These don't need to use endswith now that the port uses a MockFileSystem.
+        self.assertTrue(port._path_to_image_diff().endswith('/out/default/ImageDiff'))
         port = ChromiumPortTest.TestMacPort(options=mock_options)
-        self.assertTrue(port._path_to_image_diff().endswith(
-            '/xcodebuild/default/ImageDiff'))
+        self.assertTrue(port._path_to_image_diff().endswith('/xcodebuild/default/ImageDiff'))
         port = ChromiumPortTest.TestWinPort(options=mock_options)
-        self.assertTrue(port._path_to_image_diff().endswith(
-            '/default/ImageDiff.exe'))
+        self.assertTrue(port._path_to_image_diff().endswith('/default/ImageDiff.exe'))
 
     def test_skipped_layout_tests(self):
-        mock_options = mocktool.MockOptions()
+        mock_options = MockOptions()
         mock_options.configuration = 'release'
         port = ChromiumPortTest.TestLinuxPort(options=mock_options)
 
@@ -244,12 +236,12 @@ LINUX WIN : fast/js/very-good.js = TIMEOUT PASS"""
         self.assertTrue("fast/js/not-good.js" in skipped_tests)
 
     def test_default_configuration(self):
-        mock_options = mocktool.MockOptions()
+        mock_options = MockOptions()
         port = ChromiumPortTest.TestLinuxPort(options=mock_options)
         self.assertEquals(mock_options.configuration, 'default')
         self.assertTrue(port.default_configuration_called)
 
-        mock_options = mocktool.MockOptions(configuration=None)
+        mock_options = MockOptions(configuration=None)
         port = ChromiumPortTest.TestLinuxPort(mock_options)
         self.assertEquals(mock_options.configuration, 'default')
         self.assertTrue(port.default_configuration_called)
@@ -259,7 +251,7 @@ LINUX WIN : fast/js/very-good.js = TIMEOUT PASS"""
             def _path_to_image_diff(self):
                 return "/path/to/image_diff"
 
-        mock_options = mocktool.MockOptions()
+        mock_options = MockOptions()
         port = ChromiumPortTest.TestLinuxPort(mock_options)
 
         mock_image_diff = "MOCK Image Diff"
@@ -269,15 +261,15 @@ LINUX WIN : fast/js/very-good.js = TIMEOUT PASS"""
             return 1
 
         # Images are different.
-        port._executive = executive_mock.MockExecutive2(run_command_fn=mock_run_command)
+        port._executive = MockExecutive2(run_command_fn=mock_run_command)
         self.assertEquals(mock_image_diff, port.diff_image("EXPECTED", "ACTUAL")[0])
 
         # Images are the same.
-        port._executive = executive_mock.MockExecutive2(exit_code=0)
+        port._executive = MockExecutive2(exit_code=0)
         self.assertEquals(None, port.diff_image("EXPECTED", "ACTUAL")[0])
 
         # There was some error running image_diff.
-        port._executive = executive_mock.MockExecutive2(exit_code=2)
+        port._executive = MockExecutive2(exit_code=2)
         exception_raised = False
         try:
             port.diff_image("EXPECTED", "ACTUAL")
@@ -290,7 +282,7 @@ LINUX WIN : fast/js/very-good.js = TIMEOUT PASS"""
         if not port:
             return
 
-        filesystem = filesystem_mock.MockFileSystem()
+        filesystem = MockFileSystem()
         port._filesystem = filesystem
         port.path_from_chromium_base = lambda *comps: '/' + '/'.join(comps)
 
@@ -310,15 +302,15 @@ LINUX WIN : fast/js/very-good.js = TIMEOUT PASS"""
 
 class ChromiumPortLoggingTest(logtesting.LoggingTestCase):
     def test_check_sys_deps(self):
-        mock_options = mocktool.MockOptions()
+        mock_options = MockOptions()
         port = ChromiumPortTest.TestLinuxPort(options=mock_options)
 
         # Success
-        port._executive = executive_mock.MockExecutive2(exit_code=0)
+        port._executive = MockExecutive2(exit_code=0)
         self.assertTrue(port.check_sys_deps(needs_http=False))
 
         # Failure
-        port._executive = executive_mock.MockExecutive2(exit_code=1,
+        port._executive = MockExecutive2(exit_code=1,
             output='testing output failure')
         self.assertFalse(port.check_sys_deps(needs_http=False))
         self.assertLog([
index 1f26ced..5325a10 100755 (executable)
@@ -100,6 +100,8 @@ class ChromiumWinPort(chromium.ChromiumPort):
         self._engage_awesome_windows_hacks()
 
     def _engage_awesome_windows_hacks(self):
+        if sys.platform != "win32":
+            return
         try:
             self._executive.run_command(['svn', 'help'])
         except OSError, e:
index 93e901a..0853474 100644 (file)
@@ -64,7 +64,8 @@ class DryRunPort(object):
                 kwargs['port_name'] = kwargs['port_name'][len(pfx):]
             else:
                 kwargs['port_name'] = None
-        self.__delegate = factory.get(**kwargs)
+        # FIXME: This should get the PortFactory from a Host object.
+        self.__delegate = factory.PortFactory().get(**kwargs)
 
     def __getattr__(self, name):
         return getattr(self.__delegate, name)
index 5b1a921..29d5da9 100644 (file)
@@ -32,6 +32,8 @@
 import re
 import sys
 
+from .test import unit_test_filesystem
+
 from webkitpy.layout_tests.port import builders
 
 
@@ -67,12 +69,22 @@ class PortFactory(object):
             raise NotImplementedError('unknown port; sys.platform = "%s"' % sys.platform)
         return port_to_use
 
+    def _set_default_overriding_none(self, dictionary, key, default):
+        # dict.setdefault almost works, but won't actually override None values, which we want.
+        if not dictionary.get(key):
+            dictionary[key] = default
+        return dictionary[key]
+
     def _get_kwargs(self, **kwargs):
         port_to_use = self._port_name_from_arguments_and_options(**kwargs)
 
         if port_to_use.startswith('test'):
             import test
             maker = test.TestPort
+            # FIXME: This is a hack to override the "default" filesystem
+            # provided to the port.  The unit_test_filesystem has an extra
+            # _tests attribute which a bunch of unittests depend on.
+            self._set_default_overriding_none(kwargs, 'filesystem', unit_test_filesystem())
         elif port_to_use.startswith('dryrun'):
             import dryrun
             maker = dryrun.DryRunPort
@@ -116,9 +128,9 @@ class PortFactory(object):
         # the executive/user/filesystem from the provided host.
         # FIXME: Eventually NRWT will use a Host object and Port will no longer store these pointers.
         if self._host:
-            kwargs.setdefault('executive', self._host.executive)
-            kwargs.setdefault('user', self._host.user)
-            kwargs.setdefault('filesystem', self._host.filesystem)
+            self._set_default_overriding_none(kwargs, 'executive', self._host.executive)
+            self._set_default_overriding_none(kwargs, 'user', self._host.user)
+            self._set_default_overriding_none(kwargs, 'filesystem', self._host.filesystem)
 
         return maker(**kwargs)
 
@@ -148,15 +160,3 @@ class PortFactory(object):
         port = self.get(port_name, BuilderOptions(builder_name))
         assert(port)  # Need to update port_name_for_builder_name
         return port
-
-
-
-# FIXME: These free functions are all deprecated.  Callers should be using PortFactory instead.
-def all_port_names():
-    return PortFactory().all_port_names()
-
-def get(port_name=None, options=None, **kwargs):
-    return PortFactory().get(port_name, options, **kwargs)
-
-def get_from_builder_name(builder_name):
-    return PortFactory().get_from_builder_name(builder_name)
index 5e151ad..8daed23 100644 (file)
 import sys
 import unittest
 
-from webkitpy.common.system.filesystem_mock import MockFileSystem
 from webkitpy.tool.mocktool import MockOptions
-from webkitpy.common.system.executive_mock import MockExecutive
-from webkitpy.common.system.user_mock import MockUser
+from webkitpy.common.host_mock import MockHost
 
 import chromium_gpu
 import chromium_linux
@@ -65,6 +63,11 @@ class FactoryTest(unittest.TestCase):
     def tearDown(self):
         sys.platform = self.real_sys_platform
 
+    def make_factory(self):
+        host = MockHost()
+        # The PortFactory on MockHost is a real PortFactory with a MockFileSystem, etc.
+        return host.port_factory
+
     def assert_port(self, port_name, expected_port, port_obj=None):
         """Helper assert for port_name.
 
@@ -73,8 +76,7 @@ class FactoryTest(unittest.TestCase):
           expected_port: class of expected port object.
           port_obj: optional port object
         """
-
-        port_obj = port_obj or factory.get(port_name=port_name, filesystem=MockFileSystem(), user=MockUser(), executive=MockExecutive())
+        port_obj = port_obj or self.make_factory().get(port_name=port_name)
         self.assertTrue(isinstance(port_obj, expected_port))
 
     def assert_platform_port(self, platform, options, expected_port):
@@ -86,9 +88,10 @@ class FactoryTest(unittest.TestCase):
           expected_port: class of expected port object.
 
         """
+        # FIXME: Hacking sys.platform like this is WRONG.
         orig_platform = sys.platform
         sys.platform = platform
-        self.assertTrue(isinstance(factory.get(options=options, filesystem=MockFileSystem(), user=MockUser(), executive=MockExecutive()), expected_port))
+        self.assertTrue(isinstance(self.make_factory().get(options=options), expected_port))
         sys.platform = orig_platform
 
     def test_mac(self):
@@ -149,14 +152,13 @@ class FactoryTest(unittest.TestCase):
 
     def test_unknown_specified(self):
         # Test what happens when you specify an unknown port.
-        orig_platform = sys.platform
-        self.assertRaises(NotImplementedError, factory.get, port_name='unknown')
+        self.assertRaises(NotImplementedError, self.make_factory().get, port_name='unknown')
 
     def test_unknown_default(self):
         # Test what happens when you're running on an unknown platform.
         orig_platform = sys.platform
         sys.platform = 'unknown'
-        self.assertRaises(NotImplementedError, factory.get)
+        self.assertRaises(NotImplementedError, self.make_factory().get)
         sys.platform = orig_platform
 
 
index 6fcc908..47a904e 100644 (file)
 
 import unittest
 
-from webkitpy.common.system import filesystem_mock
+from webkitpy.common.host_mock import MockHost
+from webkitpy.common.system.filesystem_mock import MockFileSystem
+from webkitpy.common.system.user_mock import MockUser
+from webkitpy.common.system.executive_mock import MockExecutive
+
 
-import factory
 import google_chrome
 
 
 class GetGoogleChromePortTest(unittest.TestCase):
     def test_get_google_chrome_port(self):
-        test_ports = ('google-chrome-linux32', 'google-chrome-linux64',
-            'google-chrome-mac', 'google-chrome-win')
+        test_ports = ('google-chrome-linux32', 'google-chrome-linux64', 'google-chrome-mac', 'google-chrome-win')
         for port in test_ports:
             self._verify_baseline_path(port, port)
             self._verify_expectations_overrides(port)
@@ -45,8 +47,7 @@ class GetGoogleChromePortTest(unittest.TestCase):
         self._verify_baseline_path('google-chrome-win', 'google-chrome-win-vista')
 
     def _verify_baseline_path(self, expected_path, port_name):
-        port = google_chrome.GetGoogleChromePort(port_name=port_name,
-                                                 options=None)
+        port = google_chrome.GetGoogleChromePort(port_name=port_name, options=None, filesystem=MockFileSystem(), executive=MockExecutive(), user=MockUser())
         path = port.baseline_search_path()[0]
         self.assertEqual(expected_path, port._filesystem.basename(path))
 
@@ -55,18 +56,16 @@ class GetGoogleChromePortTest(unittest.TestCase):
         # we should be able to test for the files existing or not, and
         # be able to control the contents better.
 
-        chromium_port = factory.get("chromium-cg-mac")
+        host = MockHost()
+        chromium_port = host.port_factory.get("chromium-cg-mac")
         chromium_base = chromium_port.path_from_chromium_base()
-        fs = filesystem_mock.MockFileSystem()
-        port = google_chrome.GetGoogleChromePort(port_name=port_name,
-                                                 options=None, filesystem=fs)
+        fs = MockFileSystem()
+        port = google_chrome.GetGoogleChromePort(port_name=port_name, options=None, filesystem=fs, executive=MockExecutive(), user=MockUser())
 
         expected_chromium_overrides = '// chromium overrides\n'
         expected_chrome_overrides = '// chrome overrides\n'
-        chromium_path = fs.join(chromium_base, 'webkit', 'tools',
-                                'layout_tests', 'test_expectations.txt')
-        chrome_path = fs.join(chromium_base, 'webkit', 'tools',
-                              'layout_tests', 'test_expectations_chrome.txt')
+        chromium_path = fs.join(chromium_base, 'webkit', 'tools', 'layout_tests', 'test_expectations.txt')
+        chrome_path = fs.join(chromium_base, 'webkit', 'tools', 'layout_tests', 'test_expectations_chrome.txt')
 
         fs.files[chromium_path] = expected_chromium_overrides
         fs.files[chrome_path] = None
@@ -75,8 +74,7 @@ class GetGoogleChromePortTest(unittest.TestCase):
 
         fs.files[chrome_path] = expected_chrome_overrides
         actual_chrome_overrides = port.test_expectations_overrides()
-        self.assertEqual(actual_chrome_overrides,
-                         expected_chromium_overrides + expected_chrome_overrides)
+        self.assertEqual(actual_chrome_overrides, expected_chromium_overrides + expected_chrome_overrides)
 
 
 if __name__ == '__main__':
index 025290e..13229de 100644 (file)
@@ -41,7 +41,7 @@ import sys
 from webkitpy.common.system import filesystem
 
 from webkitpy.layout_tests.port import base
-from webkitpy.layout_tests.port import factory
+from webkitpy.layout_tests.port.factory import PortFactory
 from webkitpy.tool.mocktool import MockOptions
 
 
@@ -55,7 +55,8 @@ class MockDRTPort(object):
         prefix = 'mock-'
         if 'port_name' in kwargs:
             kwargs['port_name'] = kwargs['port_name'][len(prefix):]
-        self.__delegate = factory.get(**kwargs)
+        # FIXME: This should get the PortFactory from a Host object.
+        self.__delegate = PortFactory().get(**kwargs)
         self.__real_name = prefix + self.__delegate.name()
 
     def real_name(self):
@@ -184,7 +185,8 @@ class MockDRT(object):
         port_name = None
         if options.platform:
             port_name = options.platform
-        self._port = factory.get(port_name, options=options, filesystem=filesystem)
+        # FIXME: This should get the PortFactory from a Host object.
+        self._port = PortFactory().get(port_name, options=options, filesystem=filesystem)
 
     def run(self):
         while True:
index 6ff0786..9a074c1 100755 (executable)
@@ -35,10 +35,11 @@ import unittest
 from webkitpy.common import newstringio
 
 from webkitpy.layout_tests.port import mock_drt
-from webkitpy.layout_tests.port import factory
 from webkitpy.layout_tests.port import port_testcase
 from webkitpy.layout_tests.port import test
 
+from webkitpy.common.host_mock import MockHost
+
 from webkitpy.tool import mocktool
 mock_options = mocktool.MockOptions(configuration='Release')
 
@@ -136,15 +137,15 @@ class MockDRTTest(unittest.TestCase):
                     '#EOF\n',
                     '#EOF\n']
 
-    def assertTest(self, test_name, pixel_tests, expected_checksum=None,
-                   drt_output=None, filesystem=None):
-        platform = 'test'
+    def assertTest(self, test_name, pixel_tests, expected_checksum=None, drt_output=None, filesystem=None):
+        port_name = 'test'
+        host = MockHost()
         filesystem = filesystem or test.unit_test_filesystem()
-        port = factory.get(platform, filesystem=filesystem)
+        port = host.port_factory.get(port_name, filesystem=filesystem)
         drt_input, drt_output = self.make_input_output(port, test_name,
             pixel_tests, expected_checksum, drt_output)
 
-        args = ['--platform', 'test'] + self.extra_args(pixel_tests)
+        args = ['--platform', port_name] + self.extra_args(pixel_tests)
         stdin = newstringio.StringIO(drt_input)
         stdout = newstringio.StringIO()
         stderr = newstringio.StringIO()
index 2d1b452..18e0e48 100644 (file)
@@ -33,10 +33,11 @@ from __future__ import with_statement
 import base64
 import time
 
-from webkitpy.common.system import filesystem_mock
 from webkitpy.layout_tests.port import Port, Driver, DriverOutput
 from webkitpy.layout_tests.models.test_configuration import TestConfiguration
 from webkitpy.common.system.user_mock import MockUser
+from webkitpy.common.system.executive_mock import MockExecutive
+from webkitpy.common.system.filesystem_mock import MockFileSystem
 
 
 # This sets basic expectations for a test. Each individual expectation
@@ -257,7 +258,7 @@ WONTFIX SKIP : failures/expected/exception.html = CRASH
     # Add in a file should be ignored by test_files.find().
     #files[LAYOUT_TEST_DIR + '/userscripts/resources/iframe.html'] = 'iframe'
 
-    fs = filesystem_mock.MockFileSystem(files, dirs=set(['/mock-checkout']))  # Make sure at least the checkout_root exists as a directory.
+    fs = MockFileSystem(files, dirs=set(['/mock-checkout']))  # Make sure at least the checkout_root exists as a directory.
     fs._tests = test_list
     return fs
 
@@ -270,13 +271,21 @@ class TestPort(Port):
         'test-linux-x86_64',
     )
 
-    def __init__(self, port_name=None, user=None, filesystem=None, **kwargs):
+    def _set_default_overriding_none(self, dictionary, key, default):
+        # dict.setdefault almost works, but won't actually override None values, which we want.
+        if not dictionary.get(key):
+            dictionary[key] = default
+        return dictionary[key]
+
+    def __init__(self, port_name=None, **kwargs):
         if not port_name or port_name == 'test':
             port_name = 'test-mac-leopard'
-        # FIXME: This should use a MockExecutive too.
-        user = user or MockUser()
-        filesystem = filesystem or unit_test_filesystem()
-        Port.__init__(self, port_name=port_name, filesystem=filesystem, user=user, **kwargs)
+
+        self._set_default_overriding_none(kwargs, 'user', MockUser())
+        self._set_default_overriding_none(kwargs, 'executive', MockExecutive())
+        filesystem = self._set_default_overriding_none(kwargs, 'filesystem', unit_test_filesystem())
+
+        Port.__init__(self, port_name=port_name, **kwargs)
         self._results_directory = None
 
         assert filesystem._tests
index d5bd0f4..108c9d2 100644 (file)
@@ -28,6 +28,7 @@
 
 import logging
 import re
+import sys
 
 from webkitpy.common.system.executive import ScriptError
 from webkitpy.layout_tests.port.apple import ApplePort
@@ -52,10 +53,15 @@ class WinPort(ApplePort):
             return 'xp'
         return None
 
-    def _detect_version(self, os_version_string=None):
+    def _detect_version(self, os_version_string=None, run_on_non_windows_platforms=None):
         # FIXME: os_version_string is for unit testing, but may eventually be provided by factory.py instead.
         if os_version_string is not None:
             return os_version_string
+
+        # No sense in trying to detect our windows version on non-windows platforms, unless we're unittesting.
+        if sys.platform != 'cygwin' and not run_on_non_windows_platforms:
+            return None
+
         # Note, this intentionally returns None to mean that it can't detect what the current version is.
         # Callers can then decide what version they want to pretend to be.
         try:
index 7206571..5d33dd0 100644 (file)
@@ -58,14 +58,14 @@ class WinPortTest(port_testcase.PortTestCase):
             return "6.1.7600"
 
         port._executive = MockExecutive2(run_command_fn=mock_run_command)
-        self.assertEquals(port._detect_version(), '7sp0')
+        self.assertEquals(port._detect_version(run_on_non_windows_platforms=True), '7sp0')
 
         def mock_run_command(cmd):
             raise ScriptError('Failure')
 
         port._executive = MockExecutive2(run_command_fn=mock_run_command)
         # Failures log to the python error log, but we have no easy way to capture/test that.
-        self.assertEquals(port._detect_version(), None)
+        self.assertEquals(port._detect_version(run_on_non_windows_platforms=True), None)
 
     def _assert_search_path(self, expected_search_paths, version, use_webkit2=False):
         port = WinPort(os_version_string=version,
index c043869..324f8f2 100755 (executable)
@@ -38,6 +38,8 @@ import os
 import signal
 import sys
 
+from webkitpy.common.host import Host
+
 from webkitpy import layout_tests
 
 from webkitpy.layout_tests.controllers.manager import Manager, WorkerException
@@ -427,7 +429,8 @@ def parse_args(args=None):
 
 def main():
     options, args = parse_args()
-    port = layout_tests.port.get(options.platform, options)
+    host = Host()
+    port = host.port_factory.get(options.platform, options)
     return run(port, options, args)
 
 
index 47dab9a..7ab7bde 100755 (executable)
@@ -61,8 +61,8 @@ SHOULD_TEST_PROCESSES = multiprocessing and sys.platform not in ('cygwin', 'win3
 
 from webkitpy.common import array_stream
 from webkitpy.common.system import outputcapture
-from webkitpy.common.system import filesystem_mock
 from webkitpy.common.system.user_mock import MockUser
+from webkitpy.common.host_mock import MockHost
 
 from webkitpy.layout_tests import port
 from webkitpy.layout_tests import run_webkit_tests
@@ -71,8 +71,6 @@ from webkitpy.layout_tests.port.test_files import is_reference_html_file
 from webkitpy.python24.versioning import compare_version
 from webkitpy.test.skip import skip_if
 
-from webkitpy.thirdparty.mock import Mock
-
 
 def parse_args(extra_args=None, record_results=False, tests_included=False, new_results=False, print_nothing=True):
     extra_args = extra_args or []
@@ -101,8 +99,10 @@ def parse_args(extra_args=None, record_results=False, tests_included=False, new_
 
 def passing_run(extra_args=None, port_obj=None, record_results=False, tests_included=False, filesystem=None):
     options, parsed_args = parse_args(extra_args, record_results, tests_included)
+    filesystem = filesystem or unit_test_filesystem()
     if not port_obj:
-        port_obj = port.get(port_name=options.platform, options=options, user=MockUser(), filesystem=filesystem)
+        host = MockHost()
+        port_obj = host.port_factory.get(port_name=options.platform, options=options, filesystem=filesystem)
     buildbot_output = array_stream.ArrayStream()
     regular_output = array_stream.ArrayStream()
     res = run_webkit_tests.run(port_obj, options, parsed_args, buildbot_output=buildbot_output, regular_output=regular_output)
@@ -114,12 +114,13 @@ def logging_run(extra_args=None, port_obj=None, record_results=False, tests_incl
                                       record_results=record_results,
                                       tests_included=tests_included,
                                       print_nothing=False, new_results=new_results)
-    user = MockUser()
+    host = MockHost()
+    filesystem = filesystem or unit_test_filesystem()
     if not port_obj:
-        port_obj = port.get(port_name=options.platform, options=options, user=user, filesystem=filesystem)
+        port_obj = host.port_factory.get(port_name=options.platform, options=options, filesystem=filesystem)
 
     res, buildbot_output, regular_output = run_and_capture(port_obj, options, parsed_args)
-    return (res, buildbot_output, regular_output, user)
+    return (res, buildbot_output, regular_output, host.user)
 
 
 def run_and_capture(port_obj, options, parsed_args):
@@ -291,8 +292,8 @@ class MainTest(unittest.TestCase):
 
     def test_lint_test_files__errors(self):
         options, parsed_args = parse_args(['--lint-test-files'])
-        user = MockUser()
-        port_obj = port.get(options.platform, options=options, user=user)
+        host = MockHost()
+        port_obj = host.port_factory.get(options.platform, options=options)
         port_obj.test_expectations = lambda: "# syntax error"
         res, out, err = run_and_capture(port_obj, options, parsed_args)
 
@@ -816,14 +817,11 @@ class DryrunTest(unittest.TestCase):
         if sys.platform != "darwin":
             return
 
-        self.assertTrue(passing_run(['--platform', 'dryrun', 'fast/html'],
-                        tests_included=True))
-        self.assertTrue(passing_run(['--platform', 'dryrun-mac', 'fast/html'],
-                        tests_included=True))
+        self.assertTrue(passing_run(['--platform', 'dryrun', 'fast/html'], tests_included=True))
+        self.assertTrue(passing_run(['--platform', 'dryrun-mac', 'fast/html'], tests_included=True))
 
     def test_test(self):
-        self.assertTrue(passing_run(['--platform', 'dryrun-test',
-                                           '--pixel-tests']))
+        self.assertTrue(passing_run(['--platform', 'dryrun-test', '--pixel-tests']))
 
 
 if __name__ == '__main__':
index c992aa4..0916e8e 100644 (file)
@@ -35,6 +35,8 @@ import time
 import unittest
 
 from webkitpy.common import array_stream
+from webkitpy.common.host_mock import MockHost
+
 from webkitpy.common.system import logtesting
 from webkitpy.layout_tests import port
 from webkitpy.layout_tests.controllers import manager
@@ -113,7 +115,8 @@ class  Testprinter(unittest.TestCase):
         printing_options = printing.print_options()
         option_parser = optparse.OptionParser(option_list=printing_options)
         options, args = option_parser.parse_args(args)
-        self._port = port.get('test', options)
+        host = MockHost()
+        self._port = host.port_factory.get('test', options)
         nproc = 2
 
         regular_output = array_stream.ArrayStream(tty=tty)
index c570791..b6daab1 100644 (file)
@@ -34,19 +34,15 @@ import re
 import sys
 
 from common import TabChecker
-from webkitpy.layout_tests import port
+from webkitpy.layout_tests.port.factory import PortFactory
 from webkitpy.layout_tests.models import test_expectations
 
 
 _log = logging.getLogger(__name__)
 
 
+# FIXME: This could use mocktool.MockOptions(chromium=True) or base.DummyOptions(chromium=True) instead.
 class ChromiumOptions(object):
-    """A mock object for creating chromium port object.
-
-    port.get() requires an options object which has 'chromium' attribute to create
-    chromium port object for each platform. This class mocks such object.
-    """
     def __init__(self):
         self.chromium = True
 
@@ -62,21 +58,25 @@ class TestExpectationsChecker(object):
         self._handle_style_error.turn_off_line_filtering()
         self._tab_checker = TabChecker(file_path, handle_style_error)
         self._output_regex = re.compile('Line:(?P<line>\d+)\s*(?P<message>.+)')
+
+        # FIXME: This should get the PortFactory from a Host object!
+        port_factory = PortFactory()
+
         # Determining the port of this expectations.
         try:
             port_name = self._file_path.split(os.sep)[-2]
             if port_name == "chromium":
                 options = ChromiumOptions()
-                self._port_obj = port.get(port_name=None, options=options)
+                self._port_obj = port_factory.get(port_name=None, options=options)
             else:
-                self._port_obj = port.get(port_name=port_name)
+                self._port_obj = port_factory.get(port_name=port_name)
         except:
             # Using 'test' port when we couldn't determine the port for this
             # expectations.
             _log.warn("Could not determine the port for %s. "
                       "Using 'test' port, but platform-specific expectations "
                       "will fail the check." % self._file_path)
-            self._port_obj = port.get('test')
+            self._port_obj = port_factory.get('test')
         # Suppress error messages of test_expectations module since they will be
         # reported later.
         log = logging.getLogger("webkitpy.layout_tests.layout_package."
index cdceb60..c9c9ace 100644 (file)
@@ -61,7 +61,6 @@ class TestExpectationsTestCase(unittest.TestCase):
 
     def setUp(self):
         self._error_collector = ErrorCollector()
-        port_obj = port.get('test')
         self._test_file = 'passes/text.html'
 
     def process_expectations(self, expectations, overrides=None):
index 9bfe825..c851ff4 100644 (file)
@@ -55,11 +55,13 @@ from webkitpy.common.system import zipfileset
 from webkitpy.common.system import path
 from webkitpy.common.system import urlfetcher
 from webkitpy.common.system.executive import ScriptError
+from webkitpy.common.host import Host
 
-from webkitpy.layout_tests import port
+from webkitpy.layout_tests.port.factory import PortFactory
 from webkitpy.layout_tests import read_checksum_from_png
 from webkitpy.layout_tests.models import test_expectations
 
+
 _log = logging.getLogger(__name__)
 
 BASELINE_SUFFIXES = ('.txt', '.png', '.checksum')
@@ -163,7 +165,9 @@ class Rebaseliner(object):
         self._filesystem = running_port._filesystem
         self._target_port = target_port
 
-        self._rebaseline_port = port.get(platform, options, filesystem=self._filesystem)
+        # FIXME: This should get its PortFactory from a Host object.
+        # Note: using running_port.executive, running_port.user since we can't get them from a host.
+        self._rebaseline_port = PortFactory().get(platform, options, filesystem=self._filesystem, executive=running_port.executive, user=running_port.user)
         self._rebaselining_tests = set()
         self._rebaselined_tests = []
         self._logged_before = logged_before
@@ -801,18 +805,18 @@ class HtmlGenerator(object):
             return 'Other'
 
 
-def get_host_port_object(options):
+def get_host_port_object(port_factory, options):
     """Return a port object for the platform we're running on."""
     # We want the ImageDiff logic to match that of the chromium bots, so we
     # force the use of a Chromium port.  We will look for either Debug or
     # Release versions.
     options.configuration = "Release"
     options.chromium = True
-    port_obj = port.get(None, options)
+    port_obj = port_factory.get(None, options)
     if not port_obj.check_image_diff(override_step=None, logging=False):
         _log.debug('No release version of the image diff binary was found.')
         options.configuration = "Debug"
-        port_obj = port.get(None, options)
+        port_obj = port_factory.get(None, options)
         if not port_obj.check_image_diff(override_step=None, logging=False):
             _log.error('No version of image diff was found. Check your build.')
             return None
@@ -939,8 +943,9 @@ def main(args):
     logger.setLevel(log_level)
     logger.addHandler(log_handler)
 
-    target_port_obj = port.get(None, target_options)
-    host_port_obj = get_host_port_object(options)
+    host = Host()
+    target_port_obj = host.port_factory.get(None, target_options)
+    host_port_obj = get_host_port_object(host.port_factory, options)
     if not host_port_obj or not target_port_obj:
         return 1
 
@@ -953,8 +958,7 @@ def main(args):
     # FIXME: SCM module doesn't handle paths that aren't relative to the checkout_root consistently.
     host_port_obj._filesystem.chdir(scm_obj.checkout_root)
 
-    ret_code = real_main(options, target_options, host_port_obj, target_port_obj, url_fetcher,
-                         zip_factory, scm_obj)
+    ret_code = real_main(options, target_options, host_port_obj, target_port_obj, url_fetcher, zip_factory, scm_obj)
     if not ret_code and log_handler.num_failures:
         ret_code = 1
     print ''
index 915e2ad..2986ebf 100644 (file)
@@ -33,7 +33,8 @@ import unittest
 
 from webkitpy.tool.mocktool import MockOptions
 from webkitpy.common.system import urlfetcher_mock
-from webkitpy.common.system import filesystem_mock
+from webkitpy.common.host_mock import MockHost
+
 from webkitpy.common.system import zipfileset_mock
 from webkitpy.common.system import outputcapture
 from webkitpy.common.system.executive import Executive, ScriptError
@@ -54,10 +55,12 @@ class MockPort(object):
         return self.image_diff_exists
 
 
-def get_mock_get(config_expectations):
-    def mock_get(port_name, options):
+class MockPortFactory(object):
+    def __init__(self, config_expectations):
+        self.config_expectations = config_expectations
+
+    def get(port_name, options):
         return MockPort(config_expectations[options.configuration])
-    return mock_get
 
 
 ARCHIVE_URL = 'http://localhost/layout_test_results'
@@ -75,12 +78,12 @@ def test_options():
 
 
 def test_host_port_and_filesystem(options, expectations):
-    filesystem = unit_test_filesystem()
-    host_port_obj = port.get('test', options, filesystem=filesystem, user=MockUser())
+    host = MockHost()
+    host_port_obj = host.port_factory.get('test', options)
 
     expectations_path = host_port_obj.path_to_test_expectations_file()
-    filesystem.write_text_file(expectations_path, expectations)
-    return (host_port_obj, filesystem)
+    host_port_obj.filesystem.write_text_file(expectations_path, expectations)
+    return (host_port_obj, host_port_obj.filesystem)
 
 
 def test_url_fetcher(filesystem):
@@ -163,20 +166,15 @@ class TestGetHostPortObject(unittest.TestCase):
     def assert_result(self, release_present, debug_present, valid_port_obj):
         # Tests whether we get a valid port object returned when we claim
         # that Image diff is (or isn't) present in the two configs.
-        port.get = get_mock_get({'Release': release_present,
-                                 'Debug': debug_present})
-        options = MockOptions(configuration=None,
-                                       html_directory='/tmp')
-        port_obj = rebaseline_chromium_webkit_tests.get_host_port_object(options)
+        port_factory = MockPortFactory({'Release': release_present, 'Debug': debug_present})
+        options = MockOptions(configuration=None, html_directory='/tmp')
+        port_obj = rebaseline_chromium_webkit_tests.get_host_port_object(port_factory, options)
         if valid_port_obj:
             self.assertNotEqual(port_obj, None)
         else:
             self.assertEqual(port_obj, None)
 
     def test_get_host_port_object(self):
-        # Save the normal port.get() function for future testing.
-        old_get = port.get
-
         # Test whether we get a valid port object back for the four
         # possible cases of having ImageDiffs built. It should work when
         # there is at least one binary present.
@@ -185,9 +183,6 @@ class TestGetHostPortObject(unittest.TestCase):
         self.assert_result(False, True, True)
         self.assert_result(True, True, True)
 
-        # Restore the normal port.get() function.
-        port.get = old_get
-
 
 class TestOptions(unittest.TestCase):
     def test_parse_options(self):
@@ -214,8 +209,8 @@ class TestRebaseliner(unittest.TestCase):
         host_port_obj, filesystem = test_host_port_and_filesystem(options, expectations)
 
         target_options = options
-        target_port_obj = port.get('test', target_options,
-                                   filesystem=filesystem)
+        host = MockHost()
+        target_port_obj = host.port_factory.get('test', target_options, filesystem=filesystem)
         target_port_obj._expectations = expectations
         platform = target_port_obj.name()
 
@@ -387,7 +382,8 @@ class TestRealMain(unittest.TestCase):
 class TestHtmlGenerator(unittest.TestCase):
     def make_generator(self, files, tests):
         options = MockOptions(configuration=None, html_directory='/tmp')
-        host_port = port.get('test', options, filesystem=unit_test_filesystem(files))
+        host = MockHost()
+        host_port = host.port_factory.get('test', options, filesystem=unit_test_filesystem(files))
         generator = rebaseline_chromium_webkit_tests.HtmlGenerator(host_port,
             target_port=None, options=options, platforms=['test-mac-leopard'], rebaselining_tests=tests)
         return generator, host_port
index 761d96e..575e80c 100644 (file)
@@ -28,7 +28,6 @@
 
 from webkitpy.layout_tests.models.test_configuration import TestConfigurationConverter
 from webkitpy.layout_tests.models.test_expectations import TestExpectationParser, TestExpectationSerializer
-from webkitpy.layout_tests.port import factory
 from webkitpy.tool.multicommandtool import AbstractDeclarativeCommand
 
 
@@ -37,7 +36,7 @@ class OptimizeExpectations(AbstractDeclarativeCommand):
     help_text = "Fixes simple style issues in test_expectations file.  (Currently works only for chromium port.)"
 
     def execute(self, options, args, tool):
-        port = factory.get("chromium-win-win7")  # FIXME: This should be selectable.
+        port = tool.port_factory.get("chromium-win-win7")  # FIXME: This should be selectable.
         expectation_lines = TestExpectationParser.tokenize_list(port.test_expectations())
         parser = TestExpectationParser(port, [], allow_rebaseline_modifier=False)
         for expectation_line in expectation_lines:
index a3bec71..b623272 100644 (file)
@@ -40,7 +40,7 @@ from webkitpy.common.system.user import User
 from webkitpy.layout_tests.layout_package.test_result_writer import TestResultWriter
 from webkitpy.layout_tests.models import test_failures
 from webkitpy.layout_tests.models.test_expectations import TestExpectations
-from webkitpy.layout_tests.port import factory, builders
+from webkitpy.layout_tests.port import builders
 from webkitpy.layout_tests.port import test_files
 from webkitpy.tool.grammar import pluralize
 from webkitpy.tool.multicommandtool import AbstractDeclarativeCommand
@@ -65,7 +65,7 @@ class RebaselineTest(AbstractDeclarativeCommand):
         return builder.accumulated_results_url()
 
     def _baseline_directory(self, builder_name):
-        port = factory.get_from_builder_name(builder_name)
+        port = self._tool.port_factory.get_from_builder_name(builder_name)
         return port.baseline_path()
 
     def _save_baseline(self, data, target_baseline):
@@ -117,7 +117,7 @@ class OptimizeBaselines(AbstractDeclarativeCommand):
 
     def execute(self, options, args, tool):
         self._baseline_optimizer = BaselineOptimizer(tool)
-        self._port = factory.get("chromium-win-win7")  # FIXME: This should be selectable.
+        self._port = tool.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)):
             print "Optimizing %s." % test_name
@@ -147,7 +147,7 @@ class AnalyzeBaselines(AbstractDeclarativeCommand):
 
     def execute(self, options, args, tool):
         self._baseline_optimizer = BaselineOptimizer(tool)
-        self._port = factory.get("chromium-win-win7")  # FIXME: This should be selectable.
+        self._port = tool.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)):
             self._analyze_baseline(test_name)
@@ -173,7 +173,7 @@ class RebaselineExpectations(AbstractDeclarativeCommand):
     def _update_expectations_file(self, port_name):
         if not self._is_supported_port(port_name):
             return
-        port = factory.get(port_name)
+        port = self._tool.port_factory.get(port_name)
         expectations = self._expectations(port)
         path = port.path_to_test_expectations_file()
         self._tool.filesystem.write_text_file(path, expectations.remove_rebaselined_tests(expectations.get_rebaselining_failures()))
@@ -188,16 +188,16 @@ class RebaselineExpectations(AbstractDeclarativeCommand):
         if not builder_name:
             return
         print "Retrieving results for %s from %s." % (port_name, builder_name)
-        for test_name in self._tests_to_rebaseline(factory.get(port_name)):
+        for test_name in self._tests_to_rebaseline(self._tool.port_factory.get(port_name)):
             self._touched_test_names.add(test_name)
             print "    %s" % test_name
             self._run_webkit_patch(['rebaseline-test', builder_name, test_name])
 
     def execute(self, options, args, tool):
         self._touched_test_names = set([])
-        for port_name in factory.all_port_names():
+        for port_name in tool.port_factory.all_port_names():
             self._rebaseline_port(port_name)
-        for port_name in factory.all_port_names():
+        for port_name in tool.port_factory.all_port_names():
             self._update_expectations_file(port_name)
         for test_name in self._touched_test_names:
             print "Optimizing baselines for %s." % test_name
@@ -236,7 +236,7 @@ class Rebaseline(AbstractDeclarativeCommand):
     def execute(self, options, args, tool):
         builder, build_number = self._builder_to_pull_from()
         build = builder.build(build_number)
-        port = factory.get_from_builder_name(builder.name())
+        port = tool.port_factory.get_from_builder_name(builder.name())
 
         for test in self._tests_to_update(build):
             results_url = self._results_url_for_test(build, test)
index a369c9f..bcb0921 100644 (file)
@@ -51,8 +51,15 @@ class TestRebaseline(unittest.TestCase):
     def test_rebaseline_expectations(self):
         command = RebaselineExpectations()
         tool = MockTool()
-        tool.executive = MockExecutive(should_log=True)
         command.bind_to_tool(tool)
+
+        for port_name in tool.port_factory.all_port_names():
+            port = tool.port_factory.get(port_name)
+            tool.filesystem.write_text_file(port.path_to_test_expectations_file(), '')
+
+        # Don't enable logging until after we create the mock expectation files as some Port.__init__'s run subcommands.
+        tool.executive = MockExecutive(should_log=True)
+
         expected_stdout = """Retrieving results for chromium-cg-mac-leopard from Webkit Mac10.5 (CG).
     userscripts/another-test.html
     userscripts/images.svg
@@ -110,4 +117,4 @@ MOCK run_command: ['echo', 'optimize-baselines', 'userscripts/another-test.html'
 MOCK run_command: ['echo', 'optimize-baselines', 'userscripts/images.svg'], cwd=/mock-checkout
 """
         command._tests_to_rebaseline = lambda port: [] if not port.name().find('-gpu-') == -1 else ['userscripts/another-test.html', 'userscripts/images.svg']
-        OutputCapture().assert_outputs(self, command.execute, [MockTool(), None, None], expected_stdout=expected_stdout, expected_stderr=expected_stderr)
+        OutputCapture().assert_outputs(self, command.execute, [None, [], tool], expected_stdout=expected_stdout, expected_stderr=expected_stderr)
index 90538f1..e7ff86a 100644 (file)
@@ -36,7 +36,6 @@ import os.path
 from webkitpy.common import system
 from webkitpy.common.net.resultsjsonparser import for_each_test, JSONTestResult
 from webkitpy.layout_tests.layout_package import json_results_generator
-from webkitpy.layout_tests.port import factory
 from webkitpy.tool.commands.abstractlocalservercommand import AbstractLocalServerCommand
 from webkitpy.tool.servers.rebaselineserver import get_test_baselines, RebaselineHTTPServer, STATE_NEEDS_REBASELINE
 
@@ -84,7 +83,7 @@ class RebaselineServer(AbstractLocalServerCommand):
         results_json_path = filesystem.join(results_directory, 'full_results.json')
         results_json = json_results_generator.load_json(filesystem, results_json_path)
 
-        port = factory.get()
+        port = tool.port_factory.get()
         layout_tests_directory = port.layout_tests_dir()
         platforms = filesystem.listdir(filesystem.join(layout_tests_directory, 'platform'))
         self._test_config = TestConfig(port, layout_tests_directory, results_directory, platforms, filesystem, scm)
index ce1bcde..425d1ce 100644 (file)
@@ -30,7 +30,6 @@ from webkitpy.tool.servers.reflectionhandler import ReflectionHandler
 from webkitpy.layout_tests.controllers.test_expectations_editor import BugManager, TestExpectationsEditor
 from webkitpy.layout_tests.models.test_expectations import TestExpectationParser, TestExpectations, TestExpectationSerializer
 from webkitpy.layout_tests.models.test_configuration import TestConfigurationConverter
-from webkitpy.layout_tests.port import factory
 from webkitpy.layout_tests.port import builders
 
 
@@ -116,7 +115,7 @@ class GardeningHTTPRequestHandler(ReflectionHandler):
     def _expectations_updater(self):
         # FIXME: Should split failure_info_list into lists per port, then edit each expectations file separately.
         # For now, assume Chromium port.
-        port = factory.get("chromium-win-win7")
+        port = self.server.tool.get("chromium-win-win7")
         return GardeningExpectationsUpdater(self.server.tool, port)
 
     def rollout(self):
index 67db7cd..34486a3 100644 (file)
@@ -35,18 +35,20 @@ except ImportError:
 import unittest
 
 from webkitpy.common.system.outputcapture import OutputCapture
-from webkitpy.layout_tests.port import factory
 from webkitpy.layout_tests.models.test_configuration import *
 from webkitpy.thirdparty.mock import Mock
 from webkitpy.tool.mocktool import MockTool
 from webkitpy.common.system.executive_mock import MockExecutive
+from webkitpy.common.host_mock import MockHost
 from webkitpy.tool.servers.gardeningserver import *
 
 
 class TestPortFactory(object):
+    # FIXME: Why is this a class method?
     @classmethod
     def create(cls):
-        return factory.get("test-win-xp")
+        host = MockHost()
+        return host.port_factory.get("test-win-xp")
 
     @classmethod
     def path_to_test_expectations_file(cls):
@@ -87,7 +89,8 @@ class TestGardeningHTTPRequestHandler(GardeningHTTPRequestHandler):
 class BuildCoverageExtrapolatorTest(unittest.TestCase):
     def test_extrapolate(self):
         # FIXME: Make this test not rely on actual (not mock) port objects.
-        port = factory.get('chromium-win-win7', None)
+        host = MockHost()
+        port = host.port_factory.get('chromium-win-win7', None)
         converter = TestConfigurationConverter(port.all_test_configurations(), port.configuration_specifier_macros())
         extrapolator = BuildCoverageExtrapolator(converter)
         self.assertEquals(extrapolator.extrapolate_test_configurations("Webkit Win"), set([TestConfiguration(version='xp', architecture='x86', build_type='release', graphics_type='cpu')]))