+2011-01-20 Dirk Pranke <dpranke@chromium.org>
+
+ Reviewed by Eric Siedel.
+
+ nrwt: clean up almost all remaining port references, remove
+ unnecessary import clauses. The only remaining references are
+ in places where a mock filesystem makes no sense or can't be
+ used, and in one routine in port/google_chrome_unittest that
+ I'll rewrite in a separate patch.
+
+ https://bugs.webkit.org/show_bug.cgi?id=52771
+
+ * Scripts/webkitpy/layout_tests/layout_package/test_runner.py:
+ * Scripts/webkitpy/layout_tests/port/chromium_gpu.py:
+ * Scripts/webkitpy/layout_tests/port/chromium_gpu_unittest.py:
+ * Scripts/webkitpy/layout_tests/port/chromium_linux.py:
+ * Scripts/webkitpy/layout_tests/port/chromium_mac.py:
+ * Scripts/webkitpy/layout_tests/port/chromium_unittest.py:
+ * Scripts/webkitpy/layout_tests/port/chromium_win.py:
+ * Scripts/webkitpy/layout_tests/port/chromium_win_unittest.py:
+ * Scripts/webkitpy/layout_tests/port/google_chrome.py:
+ * Scripts/webkitpy/layout_tests/port/google_chrome_unittest.py:
+ * Scripts/webkitpy/layout_tests/port/gtk.py:
+ * Scripts/webkitpy/layout_tests/port/mac.py:
+ * Scripts/webkitpy/layout_tests/port/port_testcase.py:
+ * Scripts/webkitpy/layout_tests/port/qt.py:
+ * Scripts/webkitpy/layout_tests/port/webkit.py:
+ * Scripts/webkitpy/layout_tests/port/win.py:
+ * Scripts/webkitpy/layout_tests/test_types/image_diff.py:
+
2011-01-20 Dirk Pranke <dpranke@chromium.org>
Reviewed by Mihai Parparita.
import math
import Queue
import random
-import shutil
import sys
import time
# (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 __future__ import with_statement
-
-import codecs
-import os
import sys
import chromium_linux
'layout_tests', 'test_expectations_gpu.txt')
except AssertionError:
return None
- if not os.path.exists(overrides_path):
+ if not port._filesystem.exists(overrides_path):
return None
- with codecs.open(overrides_path, "r", "utf-8") as file:
- return file.read()
+ return port._filesystem.read_text_file(overrides_path)
class ChromiumGpuLinuxPort(chromium_linux.ChromiumLinuxPort):
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-import os
import unittest
from webkitpy.tool import mocktool
*comps)
base = self.path_from_chromium_base()
- if os.path.exists(os.path.join(base, 'sconsbuild')):
- return os.path.join(base, 'sconsbuild', *comps)
- if os.path.exists(os.path.join(base, 'out', *comps)) or self.get_option('use_test_shell'):
- return os.path.join(base, 'out', *comps)
+ if self._filesystem.exists(self._filesystem.join(base, 'sconsbuild')):
+ return self._filesystem.join(base, 'sconsbuild', *comps)
+ if self._filesystem.exists(self._filesystem.join(base, 'out', *comps)) or self.get_option('use_test_shell'):
+ return self._filesystem.join(base, 'out', *comps)
base = self.path_from_webkit_base()
- if os.path.exists(os.path.join(base, 'sconsbuild')):
- return os.path.join(base, 'sconsbuild', *comps)
- return os.path.join(base, 'out', *comps)
+ if self._filesystem.exists(self._filesystem.join(base, 'sconsbuild')):
+ return self._filesystem.join(base, 'sconsbuild', *comps)
+ return self._filesystem.join(base, 'out', *comps)
def _check_apache_install(self):
result = self._check_file_exists(self._path_to_apache(),
else:
config_name = 'apache2-debian-httpd.conf'
- return os.path.join(self.layout_tests_dir(), 'http', 'conf',
+ return self._filesystem.join(self.layout_tests_dir(), 'http', 'conf',
config_name)
def _path_to_lighttpd(self):
return '/usr/bin/wdiff'
def _is_redhat_based(self):
- return os.path.exists(os.path.join('/etc', 'redhat-release'))
+ return self._filesystem.exists(self._filesystem.join('/etc', 'redhat-release'))
def _shut_down_http_server(self, server_pid):
"""Shut down the lighttpd web server. Blocks until it's fully
*comps)
path = self.path_from_chromium_base('xcodebuild', *comps)
- if os.path.exists(path) or self.get_option('use_test_shell'):
+ if self._filesystem.exists(path) or self.get_option('use_test_shell'):
return path
return self.path_from_webkit_base(
'Source', 'WebKit', 'chromium', 'xcodebuild', *comps)
return '/usr/sbin/httpd'
def _path_to_apache_config_file(self):
- return os.path.join(self.layout_tests_dir(), 'http', 'conf',
- 'apache2-httpd.conf')
+ return self._filesystem.join(self.layout_tests_dir(), 'http', 'conf',
+ 'apache2-httpd.conf')
def _path_to_lighttpd(self):
return self._lighttpd_path('bin', 'lighttpd')
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-import os
import unittest
import StringIO
mock_options = mocktool.MockOptions()
port = ChromiumPortTest.TestLinuxPort(options=mock_options)
- fake_test = os.path.join(port.layout_tests_dir(), "fast/js/not-good.js")
+ fake_test = port._filesystem.join(port.layout_tests_dir(), "fast/js/not-good.js")
port.test_expectations = lambda: """BUG_TEST SKIP : fast/js/not-good.js = TEXT
LINUX WIN : fast/js/very-good.js = TIMEOUT PASS"""
"""Chromium Win implementation of the Port interface."""
import logging
-import os
import sys
import chromium
*comps)
p = self.path_from_chromium_base('webkit', *comps)
- if os.path.exists(p):
+ if self._filesystem.exists(p):
return p
p = self.path_from_chromium_base('chrome', *comps)
- if os.path.exists(p) or self.get_option('use_test_shell'):
+ if self._filesystem.exists(p) or self.get_option('use_test_shell'):
return p
- return os.path.join(self.path_from_webkit_base(), 'WebKit', 'chromium',
- *comps)
+ return self._filesystem.join(self.path_from_webkit_base(), 'WebKit', 'chromium', *comps)
def _lighttpd_path(self, *comps):
return self.path_from_chromium_base('third_party', 'lighttpd', 'win',
'sbin', 'httpd')
def _path_to_apache_config_file(self):
- return os.path.join(self.layout_tests_dir(), 'http', 'conf',
- 'cygwin-httpd.conf')
+ return self._filesystem.join(self.layout_tests_dir(), 'http', 'conf', 'cygwin-httpd.conf')
def _path_to_lighttpd(self):
return self._lighttpd_path('LightTPD.exe')
def tearDown(self):
sys.platform = self.orig_platform
+ self._port = None
def _mock_path_from_chromium_base(self, *comps):
- return os.path.join("/chromium/src", *comps)
+ return self._port._filesystem.join("/chromium/src", *comps)
def test_setup_environ_for_server(self):
port = chromium_win.ChromiumWinPort()
port._executive = mocktool.MockExecutive(should_log=True)
+ self._port = port
port.path_from_chromium_base = self._mock_path_from_chromium_base
output = outputcapture.OutputCapture()
orig_environ = os.environ.copy()
options=ChromiumWinTest.RegisterCygwinOption())
port._executive = mocktool.MockExecutive(should_log=True)
port.path_from_chromium_base = self._mock_path_from_chromium_base
+ self._port = port
setup_mount = self._mock_path_from_chromium_base("third_party",
"cygwin",
"setup_mount.bat")
# (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 __future__ import with_statement
-
-import codecs
-import os
-
def _test_expectations_overrides(port, super):
# The chrome ports use the regular overrides plus anything in the
# this changed in r60427. This should probably be changed back.
overrides_path = port.path_from_chromium_base('webkit', 'tools',
'layout_tests', 'test_expectations_chrome.txt')
- if not os.path.exists(overrides_path):
+ if not port._filesystem.exists(overrides_path):
return chromium_overrides
- with codecs.open(overrides_path, "r", "utf-8") as file:
- if chromium_overrides:
- return chromium_overrides + file.read()
- else:
- return file.read()
+ chromium_overrides = chromium_overrides or ''
+ return chromium_overrides + port._filesystem.read_text_file(overrides_path)
def GetGoogleChromePort(**kwargs):
"""Some tests have slightly different results when compiled as Google
port = google_chrome.GetGoogleChromePort(port_name=port_name,
options=None)
path = port.baseline_search_path()[0]
- self.assertEqual(expected_path, os.path.split(path)[1])
+ self.assertEqual(expected_path, port._filesystem.basename(path))
def _verify_expectations_overrides(self, port_name):
# FIXME: make this more robust when we have the Tree() abstraction.
def _path_to_apache_config_file(self):
# FIXME: This needs to detect the distribution and change config files.
- return os.path.join(self.layout_tests_dir(), 'http', 'conf',
- 'apache2-debian-httpd.conf')
+ return self._filesystem.join(self.layout_tests_dir(), 'http', 'conf',
+ 'apache2-debian-httpd.conf')
def _shut_down_http_server(self, server_pid):
"""Shut down the httpd web server. Blocks until it's fully
else:
config_name = 'apache2-debian-httpd.conf'
- return os.path.join(self.layout_tests_dir(), 'http', 'conf',
+ return self._filesystem.join(self.layout_tests_dir(), 'http', 'conf',
config_name)
def _path_to_wdiff(self):
return '/usr/bin/wdiff'
def _is_redhat_based(self):
- return os.path.exists(os.path.join('/etc', 'redhat-release'))
+ return self._filesystem.exists(self._filesystem.join('/etc', 'redhat-release'))
# platforms and moved into base.Port.
skipped_files = []
if self._name in ('mac-tiger', 'mac-leopard', 'mac-snowleopard'):
- skipped_files.append(os.path.join(
+ skipped_files.append(self._filesystem.join(
self._webkit_baseline_path(self._name), 'Skipped'))
- skipped_files.append(os.path.join(self._webkit_baseline_path('mac'),
+ skipped_files.append(self._filesystem.join(self._webkit_baseline_path('mac'),
'Skipped'))
return skipped_files
return ''
def _build_java_test_support(self):
- java_tests_path = os.path.join(self.layout_tests_dir(), "java")
+ java_tests_path = self._filesystem.join(self.layout_tests_dir(), "java")
build_java = ["/usr/bin/make", "-C", java_tests_path]
if self._executive.run_command(build_java, return_exit_code=True):
_log.error("Failed to build Java support files: %s" % build_java)
]
def _path_to_apache_config_file(self):
- return os.path.join(self.layout_tests_dir(), 'http', 'conf',
- 'apache2-httpd.conf')
+ return self._filesystem.join(self.layout_tests_dir(), 'http', 'conf',
+ 'apache2-httpd.conf')
# FIXME: This doesn't have anything to do with WebKit.
def _shut_down_http_server(self, server_pid):
"""Unit testing base class for Port implementations."""
-import os
-import tempfile
import unittest
from webkitpy.tool import mocktool
if not port:
return
- # FIXME: not sure why this shouldn't always be True
- #self.assertTrue(port.check_image_diff())
if not port.check_image_diff():
+ # The port hasn't been built - don't run the tests.
return
dir = port.layout_tests_dir()
- file1 = os.path.join(dir, 'fast', 'css', 'button_center.png')
- fh1 = file(file1)
- contents1 = fh1.read()
- file2 = os.path.join(dir, 'fast', 'css',
- 'remove-shorthand-expected.png')
- fh2 = file(file2)
- contents2 = fh2.read()
- tmpfile = tempfile.mktemp()
+ file1 = port._filesystem.join(dir, 'fast', 'css', 'button_center.png')
+ contents1 = port._filesystem.read_binary_file(file1)
+ file2 = port._filesystem.join(dir, 'fast', 'css',
+ 'remove-shorthand-expected.png')
+ contents2 = port._filesystem.read_binary_file(file2)
+ tmpfd, tmpfile = port._filesystem.open_binary_tempfile('')
+ tmpfd.close()
self.assertFalse(port.diff_image(contents1, contents1))
self.assertTrue(port.diff_image(contents1, contents2))
self.assertTrue(port.diff_image(contents1, contents2, tmpfile))
- fh1.close()
- fh2.close()
- # FIXME: this may not be being written?
- # self.assertTrue(os.path.exists(tmpfile))
- # os.remove(tmpfile)
+
+ port._filesystem.remove(tmpfile)
def test_websocket_server(self):
port = self.make_port()
def _path_to_apache_config_file(self):
# FIXME: This needs to detect the distribution and change config files.
- return os.path.join(self.layout_tests_dir(), 'http', 'conf',
- 'apache2-debian-httpd.conf')
+ return self._filesystem.join(self.layout_tests_dir(), 'http', 'conf',
+ 'apache2-debian-httpd.conf')
def _shut_down_http_server(self, server_pid):
"""Shut down the httpd web server. Blocks until it's fully
"""WebKit implementations of the Port interface."""
-from __future__ import with_statement
-
-import codecs
import logging
+import operator
import os
import re
-import shutil
import signal
import sys
import time
import webbrowser
-import operator
-import tempfile
-import shutil
import webkitpy.common.system.ospath as ospath
import webkitpy.layout_tests.layout_package.test_output as test_output
return [self._webkit_baseline_path(self._name)]
def path_to_test_expectations_file(self):
- return os.path.join(self._webkit_baseline_path(self._name),
- 'test_expectations.txt')
+ return self._filesystem.join(self._webkit_baseline_path(self._name),
+ 'test_expectations.txt')
# Only needed by ports which maintain versioned test expectations (like mac-tiger vs. mac-leopard)
def version(self):
def _check_driver(self):
driver_path = self._path_to_driver()
- if not os.path.exists(driver_path):
+ if not self._filesystem.exists(driver_path):
_log.error("DumpRenderTree was not found at %s" % driver_path)
return False
return True
def check_image_diff(self, override_step=None, logging=True):
image_diff_path = self._path_to_image_diff()
- if not os.path.exists(image_diff_path):
+ if not self._filesystem.exists(image_diff_path):
_log.error("ImageDiff was not found at %s" % image_diff_path)
return False
return True
if m.group(2) == 'passed':
result = False
elif output and diff_filename:
- with open(diff_filename, 'w') as file:
- file.write(output)
+ self._filesystem.write_text_file(diff_filename, output)
elif sp.timed_out:
_log.error("ImageDiff timed out")
elif sp.crashed:
return tests_to_skip
def _skipped_file_paths(self):
- return [os.path.join(self._webkit_baseline_path(self._name),
- 'Skipped')]
+ return [self._filesystem.join(self._webkit_baseline_path(self._name), 'Skipped')]
def _expectations_from_skipped_files(self):
tests_to_skip = []
for filename in self._skipped_file_paths():
- if not os.path.exists(filename):
+ if not self._filesystem.exists(filename):
_log.warn("Failed to open Skipped file: %s" % filename)
continue
- with codecs.open(filename, "r", "utf-8") as skipped_file:
- tests_to_skip.extend(self._tests_from_skipped_file(skipped_file))
+ skipped_file = self._filesystem.read_text_file(filename)
return tests_to_skip
def test_expectations(self):
# The WebKit mac port uses a combination of a test_expectations file
# and 'Skipped' files.
expectations_path = self.path_to_test_expectations_file()
- with codecs.open(expectations_path, "r", "utf-8") as file:
- return file.read() + self._skips()
+ return self._filesystem.read_text_file(expectations_path) + self._skips()
def _skips(self):
# Each Skipped file contains a list of files
# The Apache binary path can vary depending on OS and distribution
# See http://wiki.apache.org/httpd/DistrosDefaultLayout
for path in ["/usr/sbin/httpd", "/usr/sbin/apache2"]:
- if os.path.exists(path):
+ if self._filesystem.exists(path):
self._cached_apache_path = path
break
def __init__(self, port, worker_number):
self._worker_number = worker_number
self._port = port
- self._driver_tempdir = tempfile.mkdtemp(prefix='DumpRenderTree-')
+ self._driver_tempdir = port._filesystem.mkdtemp(prefix='DumpRenderTree-')
def __del__(self):
- shutil.rmtree(self._driver_tempdir)
+ self._port._filesystem.rmtree(str(self._driver_tempdir))
def cmd_line(self):
cmd = self._command_wrapper(self._port.get_option('wrapper'))
def start(self):
environment = self._port.setup_environ_for_server()
environment['DYLD_FRAMEWORK_PATH'] = self._port._build_path()
- environment['DUMPRENDERTREE_TEMP'] = self._driver_tempdir
+ environment['DUMPRENDERTREE_TEMP'] = str(self._driver_tempdir)
self._server_process = server_process.ServerProcess(self._port,
"DumpRenderTree", self.cmd_line(), environment)
"""WebKit Win implementation of the Port interface."""
import logging
-import os
from webkitpy.layout_tests.port.webkit import WebKitPort
]
def _path_to_apache_config_file(self):
- return os.path.join(self.layout_tests_dir(), 'http', 'conf',
- 'cygwin-httpd.conf')
+ return self._filesystem.join(self.layout_tests_dir(), 'http', 'conf',
+ 'cygwin-httpd.conf')
def _shut_down_http_server(self, server_pid):
"""Shut down the httpd web server. Blocks until it's fully
test results directory.
"""
-from __future__ import with_statement
-
-import codecs
import errno
import logging
-import os
-import shutil
from webkitpy.layout_tests.layout_package import test_failures
from webkitpy.layout_tests.test_types import test_type_base