+2011-01-25 Dirk Pranke <dpranke@chromium.org>
+
+ Reviewed by Tony Chang.
+
+ Minor bug fixes and cleanup for filesystem wrappers, port/* test
+ classes, test_expectations.py. This change adds "test-win" and
+ "test-mac" variants to the test port so that we can better test
+ rebaselining, and adds a MockUser() object for reuse in testing.
+
+ https://bugs.webkit.org/show_bug.cgi?id=53036
+
+ * Scripts/webkitpy/common/system/filesystem.py:
+ * Scripts/webkitpy/common/system/filesystem_mock.py:
+ * Scripts/webkitpy/layout_tests/layout_package/test_expectations.py:
+ * Scripts/webkitpy/layout_tests/port/factory.py:
+ * Scripts/webkitpy/layout_tests/port/base.py:
+ * Scripts/webkitpy/layout_tests/port/test.py:
+ * Scripts/webkitpy/layout_tests/run_webkit_tests_unittest.py:
+ * Scripts/webkitpy/layout_tests/rebaseline_chromium_webkit_tests_unittest.py:
+ * Scripts/webkitpy/tool/mocktool.py:
+
2011-01-25 Tony Chang <tony@chromium.org>
Reviewed by Dimitri Glazkov.
if e.errno != errno.EEXIST:
raise
- def move(self, src, dest):
- shutil.move(src, dest)
+ def move(self, source, destination):
+ shutil.move(source, destination)
def mtime(self, path):
return os.stat(path).st_mtime
raise IOError(errno.EISDIR, destination, os.strerror(errno.ISDIR))
self.files[destination] = self.files[source]
+ self.written_files[destination] = self.files[source]
def dirname(self, path):
return self._split(path)[0]
# FIXME: Implement such that subsequent calls to isdir() work?
pass
- def move(self, src, dst):
- if self.files[src] is None:
- self._raise_not_found(src)
- self.files[dst] = self.files[src]
- self.files[src] = None
+ def move(self, source, destination):
+ if self.files[source] is None:
+ self._raise_not_found(source)
+ self.files[destination] = self.files[source]
+ self.written_files[destination] = self.files[destination]
+ self.files[source] = None
+ self.written_files[source] = None
def normpath(self, path):
return path
- def open_binary_tempfile(self, suffix):
+ def open_binary_tempfile(self, suffix=''):
path = self._mktemp(suffix)
- return WritableFileObject(self, path), path
+ return (WritableFileObject(self, path), path)
def open_text_file_for_writing(self, path, append=False):
return WritableFileObject(self, path, append)
if self.files[path] is None:
self._raise_not_found(path)
self.files[path] = None
+ self.written_files[path] = None
def rmtree(self, path):
if not path.endswith('/'):
"""Loads and parses the test expectations given in the string.
Args:
port: handle to object containing platform-specific functionality
- test: list of all of the test files
+ tests: list of all of the test files
expectations: test expectations as a string
test_platform_name: name of the platform to match expectations
against. Note that this may be different than
Basically this string should contain the equivalent of a
test_expectations file. See test_expectations.py for more details."""
- raise NotImplementedError('Port.test_expectations')
+ return self._filesystem.read_text_file(self.path_to_test_expectations_file())
def test_expectations_overrides(self):
"""Returns an optional set of overrides for the test_expectations.
raise NotImplementedError('unknown port; sys.platform = "%s"' %
sys.platform)
- if port_to_use == 'test':
+ if port_to_use.startswith('test'):
import test
maker = test.TestPort
elif port_to_use.startswith('dryrun'):
import time
from webkitpy.common.system import filesystem_mock
+from webkitpy.tool import mocktool
from webkitpy.layout_tests.layout_package import test_output
class TestPort(base.Port):
"""Test implementation of the Port interface."""
- def __init__(self, **kwargs):
- # FIXME: what happens if we're not passed in the test filesystem
- # and the tests don't match what's in the filesystem?
- #
- # We'll leave as is for now to avoid unnecessary dependencies while
- # converting all of the unit tests over to using
- # unit_test_filesystem(). If things get out of sync the tests should
- # fail in fairly obvious ways. Eventually we want to just do:
- #
- # assert kwargs['filesystem']._tests
- # self._tests = kwargs['filesystem']._tests
-
- if 'filesystem' not in kwargs or kwargs['filesystem'] is None:
- kwargs['filesystem'] = unit_test_filesystem()
- self._tests = kwargs['filesystem']._tests
- else:
- self._tests = unit_test_list()
-
- kwargs.setdefault('port_name', 'test')
- base.Port.__init__(self, **kwargs)
+ def __init__(self, port_name=None, user=None, filesystem=None, **kwargs):
+ if not filesystem:
+ filesystem = unit_test_filesystem()
+
+ assert filesystem._tests
+ self._tests = filesystem._tests
+
+ if not user:
+ user = mocktool.MockUser()
+
+ if not port_name or port_name == 'test':
+ port_name = 'test-mac'
+
+ self._expectations_path = LAYOUT_TEST_DIR + '/platform/test/test_expectations.txt'
+ base.Port.__init__(self, port_name=port_name, filesystem=filesystem, user=user,
+ **kwargs)
def baseline_path(self):
return self._filesystem.join(self.layout_tests_dir(), 'platform',
def test_base_platform_names(self):
return ('mac', 'win')
- def test_expectations(self):
- return self._filesystem.read_text_file(LAYOUT_TEST_DIR + '/platform/test/test_expectations.txt')
+ def path_to_test_expectations_file(self):
+ return self._expectations_path
def test_platform_name(self):
+ if self._name == 'test-win':
+ return 'win'
return 'mac'
def test_platform_names(self):
return self.test_base_platform_names()
def test_platform_name_to_name(self, test_platform_name):
- return test_platform_name
+ name_map = {
+ 'mac': 'test-mac',
+ 'win': 'test-win',
+ }
+ return name_map[test_platform_name]
def version(self):
return ''
import unittest
from webkitpy.tool import mocktool
-from webkitpy.common.system import filesystem_mock
from webkitpy.common.system.executive import Executive, ScriptError
import port
def make_rebaseliner(self):
options = mocktool.MockOptions(configuration=None,
html_directory=None)
- filesystem = filesystem_mock.MockFileSystem()
+ filesystem = port.unit_test_filesystem()
host_port_obj = port.get('test', options, filesystem=filesystem)
target_options = options
target_port_obj = port.get('test', target_options, filesystem=filesystem)
- platform = 'test'
+ platform = target_port_obj.test_platform_name()
return rebaseline_chromium_webkit_tests.Rebaseliner(
host_port_obj, target_port_obj, platform, options)
class TestHtmlGenerator(unittest.TestCase):
def make_generator(self, files, tests):
options = mocktool.MockOptions(configuration=None, html_directory='/tmp')
- host_port = port.get('test', options, filesystem=filesystem_mock.MockFileSystem(files))
+ host_port = port.get('test', options, filesystem=port.unit_test_filesystem(files))
generator = rebaseline_chromium_webkit_tests.HtmlGenerator(
host_port,
target_port=None,
from webkitpy.common import array_stream
from webkitpy.common.system import outputcapture
from webkitpy.common.system import filesystem_mock
-from webkitpy.common.system import user
+from webkitpy.tool import mocktool
from webkitpy.layout_tests import port
from webkitpy.layout_tests import run_webkit_tests
from webkitpy.layout_tests.layout_package import dump_render_tree_thread
from webkitpy.thirdparty.mock import Mock
-class MockUser():
- def __init__(self):
- self.url = None
-
- def open_url(self, url):
- self.url = url
-
-
def parse_args(extra_args=None, record_results=False, tests_included=False,
print_nothing=True):
extra_args = extra_args or []
tests_included)
if not port_obj:
port_obj = port.get(port_name=options.platform, options=options,
- user=MockUser(), filesystem=filesystem)
+ user=mocktool.MockUser(), filesystem=filesystem)
res = run_webkit_tests.run(port_obj, options, parsed_args)
return res == 0
record_results=record_results,
tests_included=tests_included,
print_nothing=False)
- user = MockUser()
+ user = mocktool.MockUser()
if not port_obj:
port_obj = port.get(port_name=options.platform, options=options,
user=user, filesystem=filesystem)
extra_args = ['passes', 'failures'] + extra_args
options, parsed_args = parse_args(extra_args, tests_included=True)
- user = MockUser()
+ user = mocktool.MockUser()
test_batches = []
def test_full_results_html(self):
# FIXME: verify html?
- self.assertTrue(passing_run(['--full-results-html']))
+ res, out, err, user = logging_run(['--full-results-html'])
+ self.assertEqual(res, 0)
def test_help_printing(self):
res, out, err, user = logging_run(['--help-printing'])
def test_lint_test_files__errors(self):
options, parsed_args = parse_args(['--lint-test-files'])
- user = MockUser()
+ user = mocktool.MockUser()
port_obj = port.get(options.platform, options=options, user=user)
port_obj.test_expectations = lambda: "# syntax error"
res, out, err = run_and_capture(port_obj, options, parsed_args)
self.assertEqual(res, 3)
self.assertFalse(out.empty())
self.assertFalse(err.empty())
- self.assertEqual(user.url, '/tmp/layout-test-results/results.html')
+ self.assertEqual(user.opened_urls, ['/tmp/layout-test-results/results.html'])
def test_exit_after_n_failures(self):
# Unexpected failures should result in tests stopping.
with fs.mkdtemp() as tmpdir:
res, out, err, user = logging_run(['--results-directory=' + str(tmpdir)],
tests_included=True, filesystem=fs)
- self.assertEqual(user.url, fs.join(tmpdir, 'results.html'))
+ self.assertEqual(user.opened_urls, [fs.join(tmpdir, 'results.html')])
def test_results_directory_default(self):
# We run a configuration that should fail, to generate output, then
# This is the default location.
res, out, err, user = logging_run(tests_included=True)
- self.assertEqual(user.url, '/tmp/layout-test-results/results.html')
+ self.assertEqual(user.opened_urls, ['/tmp/layout-test-results/results.html'])
def test_results_directory_relative(self):
# We run a configuration that should fail, to generate output, then
res, out, err, user = logging_run(['--results-directory=foo'],
tests_included=True)
- self.assertEqual(user.url, '/tmp/foo/results.html')
+ self.assertEqual(user.opened_urls, ['/tmp/foo/results.html'])
def test_tolerance(self):
class ImageDiffTestPort(TestPort):
def get_port_for_run(args):
options, parsed_args = run_webkit_tests.parse_args(args)
- test_port = ImageDiffTestPort(options=options, user=MockUser())
+ test_port = ImageDiffTestPort(options=options, user=mocktool.MockUser())
passing_run(args, port_obj=test_port, tests_included=True)
return test_port
file_list.remove('/tmp/layout-test-results/tests_run.txt')
self.assertEqual(len(file_list), 6)
self.assertBaselines(file_list,
- "/platform/test/passes/image")
+ "/platform/test-mac/passes/image")
self.assertBaselines(file_list,
- "/platform/test/failures/expected/missing_image")
+ "/platform/test-mac/failures/expected/missing_image")
class DryrunTest(unittest.TestCase):
def prompt_with_list(cls, list_title, list_items, can_choose_multiple=False, raw_input=raw_input):
pass
+ def __init__(self):
+ self.opened_urls = []
+
def edit(self, files):
pass
return True
def open_url(self, url):
+ self.opened_urls.append(url)
if url.startswith("file://"):
log("MOCK: user.open_url: file://...")
return