class DirectoryFileSetTest(unittest.TestCase):
    def setUp(self):
        files = {}
        files['/test/some-file'] = 'contents'
        files['/test/some-other-file'] = 'other contents'
        files['/test/b/c'] = 'c'
        self._filesystem = MockFileSystem(files)
        self._fileset = DirectoryFileSet('/test', self._filesystem)

    def test_files_in_namelist(self):
        self.assertTrue('some-file' in self._fileset.namelist())
        self.assertTrue('some-other-file' in self._fileset.namelist())
        self.assertTrue('b/c' in self._fileset.namelist())

    def test_read(self):
        self.assertEquals('contents', self._fileset.read('some-file'))

    def test_open(self):
        file = self._fileset.open('some-file')
        self.assertEquals('some-file', file.name())
        self.assertEquals('contents', file.contents())

    def test_extract(self):
        self._fileset.extract('some-file', '/test-directory')
        contents = self._filesystem.read_text_file('/test-directory/some-file')
        self.assertEquals('contents', contents)

    def test_extract_deep_file(self):
        self._fileset.extract('b/c', '/test-directory')
        self.assertTrue(self._filesystem.exists('/test-directory/b/c'))

    def test_delete(self):
        self.assertTrue(self._filesystem.exists('/test/some-file'))
        self._fileset.delete('some-file')
        self.assertFalse(self._filesystem.exists('/test/some-file'))
Ejemplo n.º 2
0
    def test_set_reviewer(self):
        fs = MockFileSystem()

        changelog_contents = u"%s\n%s" % (self._new_entry_boilerplate_with_bugurl, self._example_changelog)
        reviewer_name = "Test Reviewer"
        fs.write_text_file(self._changelog_path, changelog_contents)
        ChangeLog(self._changelog_path, fs).set_reviewer(reviewer_name)
        actual_contents = fs.read_text_file(self._changelog_path)
        expected_contents = changelog_contents.replace("NOBODY (OOPS!)", reviewer_name)
        self.assertEqual(actual_contents.splitlines(), expected_contents.splitlines())

        changelog_contents_without_reviewer_line = u"%s\n%s" % (
            self._new_entry_boilerplate_without_reviewer_line,
            self._example_changelog,
        )
        fs.write_text_file(self._changelog_path, changelog_contents_without_reviewer_line)
        ChangeLog(self._changelog_path, fs).set_reviewer(reviewer_name)
        actual_contents = fs.read_text_file(self._changelog_path)
        self.assertEqual(actual_contents.splitlines(), expected_contents.splitlines())

        changelog_contents_without_reviewer_line = u"%s\n%s" % (
            self._new_entry_boilerplate_without_reviewer_multiple_bugurl,
            self._example_changelog,
        )
        fs.write_text_file(self._changelog_path, changelog_contents_without_reviewer_line)
        ChangeLog(self._changelog_path, fs).set_reviewer(reviewer_name)
        actual_contents = fs.read_text_file(self._changelog_path)
        changelog_contents = u"%s\n%s" % (self._new_entry_boilerplate_with_multiple_bugurl, self._example_changelog)
        expected_contents = changelog_contents.replace("NOBODY (OOPS!)", reviewer_name)
        self.assertEqual(actual_contents.splitlines(), expected_contents.splitlines())
Ejemplo n.º 3
0
    def test_check(self):
        errors = []

        def mock_handle_style_error(line_number, category, confidence, message):
            error = (line_number, category, confidence, message)
            errors.append(error)

        fs = MockFileSystem()

        file_path = "foo.png"
        fs.write_binary_file(file_path, "Dummy binary data")
        errors = []
        checker = PNGChecker(file_path, mock_handle_style_error, MockSystemHost(os_name='linux', filesystem=fs))
        checker.check()
        self.assertEqual(len(errors), 0)

        file_path = "foo-expected.png"
        fs.write_binary_file(file_path, "Dummy binary data")
        errors = []
        checker = PNGChecker(file_path, mock_handle_style_error, MockSystemHost(os_name='linux', filesystem=fs))
        checker.check()
        self.assertEqual(len(errors), 1)
        self.assertEqual(
            errors[0],
            (0, 'image/png', 5, 'Image lacks a checksum. Generate pngs using run-webkit-tests to ensure they have a checksum.'))
 def test_prepend_text(self):
     fs = MockFileSystem()
     fs.write_text_file(self._changelog_path, self._example_changelog)
     ChangeLog(self._changelog_path, fs).prepend_text(self._example_entry + "\n")
     actual_contents = fs.read_text_file(self._changelog_path)
     expected_contents = self._example_entry + "\n" + self._example_changelog
     self.assertEqual(actual_contents.splitlines(), expected_contents.splitlines())
Ejemplo n.º 5
0
    def test_find_log_darwin(self):
        if not SystemHost().platform.is_mac():
            return

        older_mock_crash_report = make_mock_crash_report_darwin('DumpRenderTree', 28528)
        mock_crash_report = make_mock_crash_report_darwin('DumpRenderTree', 28530)
        newer_mock_crash_report = make_mock_crash_report_darwin('DumpRenderTree', 28529)
        other_process_mock_crash_report = make_mock_crash_report_darwin('FooProcess', 28527)
        misformatted_mock_crash_report = 'Junk that should not appear in a crash report' + make_mock_crash_report_darwin('DumpRenderTree', 28526)[200:]
        files = {}
        files['/Users/mock/Library/Logs/DiagnosticReports/DumpRenderTree_2011-06-13-150718_quadzen.crash'] = older_mock_crash_report
        files['/Users/mock/Library/Logs/DiagnosticReports/DumpRenderTree_2011-06-13-150719_quadzen.crash'] = mock_crash_report
        files['/Users/mock/Library/Logs/DiagnosticReports/DumpRenderTree_2011-06-13-150720_quadzen.crash'] = newer_mock_crash_report
        files['/Users/mock/Library/Logs/DiagnosticReports/DumpRenderTree_2011-06-13-150721_quadzen.crash'] = None
        files['/Users/mock/Library/Logs/DiagnosticReports/DumpRenderTree_2011-06-13-150722_quadzen.crash'] = other_process_mock_crash_report
        files['/Users/mock/Library/Logs/DiagnosticReports/DumpRenderTree_2011-06-13-150723_quadzen.crash'] = misformatted_mock_crash_report
        filesystem = MockFileSystem(files)
        crash_logs = CrashLogs(MockSystemHost(filesystem=filesystem))
        log = crash_logs.find_newest_log("DumpRenderTree")
        self.assertLinesEqual(log, newer_mock_crash_report)
        log = crash_logs.find_newest_log("DumpRenderTree", 28529)
        self.assertLinesEqual(log, newer_mock_crash_report)
        log = crash_logs.find_newest_log("DumpRenderTree", 28530)
        self.assertLinesEqual(log, mock_crash_report)
        log = crash_logs.find_newest_log("DumpRenderTree", 28531)
        self.assertEqual(log, None)
        log = crash_logs.find_newest_log("DumpRenderTree", newer_than=1.0)
        self.assertEqual(log, None)

        def bad_read(path):
            raise IOError('No such file or directory')

        filesystem.read_text_file = bad_read
        log = crash_logs.find_newest_log("DumpRenderTree", 28531, include_errors=True)
        self.assertTrue('No such file or directory' in log)
Ejemplo n.º 6
0
    def test_additional_platform_directory(self):
        filesystem = MockFileSystem()
        port = Port(port_name='foo', filesystem=filesystem)
        port.baseline_search_path = lambda: ['LayoutTests/platform/foo']
        layout_test_dir = port.layout_tests_dir()
        test_file = 'fast/test.html'

        # No additional platform directory
        self.assertEqual(
            port.expected_baselines(test_file, '.txt'),
            [(None, 'fast/test-expected.txt')])
        self.assertEqual(port.baseline_path(), 'LayoutTests/platform/foo')

        # Simple additional platform directory
        port._options.additional_platform_directory = ['/tmp/local-baselines']
        filesystem.files = {
            '/tmp/local-baselines/fast/test-expected.txt': 'foo',
        }
        self.assertEqual(
            port.expected_baselines(test_file, '.txt'),
            [('/tmp/local-baselines', 'fast/test-expected.txt')])
        self.assertEqual(port.baseline_path(), '/tmp/local-baselines')

        # Multiple additional platform directories
        port._options.additional_platform_directory = ['/foo', '/tmp/local-baselines']
        self.assertEqual(
            port.expected_baselines(test_file, '.txt'),
            [('/tmp/local-baselines', 'fast/test-expected.txt')])
        self.assertEqual(port.baseline_path(), '/foo')
Ejemplo n.º 7
0
    def test_additional_platform_directory(self):
        filesystem = MockFileSystem()
        options, args = optparse.OptionParser().parse_args([])
        port = base.Port(port_name='foo', filesystem=filesystem, options=options)
        port.baseline_search_path = lambda: ['LayoutTests/platform/foo']
        layout_test_dir = port.layout_tests_dir()
        test_file = filesystem.join(layout_test_dir, 'fast', 'test.html')

        # No additional platform directory
        self.assertEqual(
            port.expected_baselines(test_file, '.txt'),
            [(None, 'fast/test-expected.txt')])
        self.assertEqual(port.baseline_path(), 'LayoutTests/platform/foo')

        # Simple additional platform directory
        options.additional_platform_directory = ['/tmp/local-baselines']
        filesystem.files = {
            '/tmp/local-baselines/fast/test-expected.txt': 'foo',
        }
        self.assertEqual(
            port.expected_baselines(test_file, '.txt'),
            [('/tmp/local-baselines', 'fast/test-expected.txt')])
        self.assertEqual(port.baseline_path(), '/tmp/local-baselines')

        # Multiple additional platform directories
        options.additional_platform_directory = ['/foo', '/tmp/local-baselines']
        self.assertEqual(
            port.expected_baselines(test_file, '.txt'),
            [('/tmp/local-baselines', 'fast/test-expected.txt')])
        self.assertEqual(port.baseline_path(), '/foo')
Ejemplo n.º 8
0
    def assert_interpreter_for_content(self, intepreter, content):
        fs = MockFileSystem()

        tempfile, temp_name = fs.open_binary_tempfile('')
        tempfile.write(content)
        tempfile.close()
        file_interpreter = Executive.interpreter_for_script(temp_name, fs)

        self.assertEqual(file_interpreter, intepreter)
Ejemplo n.º 9
0
 def test_collect_tests(self):
     runner = self.create_runner()
     runner._base_path = '/test.checkout/PerformanceTests'
     filesystem = MockFileSystem()
     filename = filesystem.join(runner._base_path, 'inspector', 'a_file.html')
     filesystem.maybe_make_directory(runner._base_path, 'inspector')
     filesystem.files[filename] = 'a content'
     runner._host.filesystem = filesystem
     tests = runner._collect_tests()
     self.assertEqual(len(tests), 1)
Ejemplo n.º 10
0
def unit_test_filesystem(files=None):
    """Return the FileSystem object used by the unit tests."""
    test_list = unit_test_list()
    files = files or {}

    def add_file(files, test, suffix, contents):
        dirname = test.name[0:test.name.rfind('/')]
        base = test.base
        path = LAYOUT_TEST_DIR + '/' + dirname + '/' + base + suffix
        files[path] = contents

    # Add each test and the expected output, if any.
    for test in test_list.tests.values():
        add_file(files, test, '.html', '')
        if test.is_reftest:
            continue
        if test.actual_audio:
            add_file(files, test, '-expected.wav', test.expected_audio)
            continue

        add_file(files, test, '-expected.txt', test.expected_text)
        add_file(files, test, '-expected.png', test.expected_image)


    # Add the test_expectations file.
    files[LAYOUT_TEST_DIR + '/platform/test/test_expectations.txt'] = """
WONTFIX : failures/expected/checksum.html = IMAGE
WONTFIX : failures/expected/crash.html = CRASH
WONTFIX : failures/expected/image.html = IMAGE
WONTFIX : failures/expected/audio.html = AUDIO
WONTFIX : failures/expected/image_checksum.html = IMAGE
WONTFIX : failures/expected/mismatch.html = IMAGE
WONTFIX : failures/expected/missing_check.html = MISSING PASS
WONTFIX : failures/expected/missing_image.html = MISSING PASS
WONTFIX : failures/expected/missing_audio.html = MISSING PASS
WONTFIX : failures/expected/missing_text.html = MISSING PASS
WONTFIX : failures/expected/newlines_leading.html = TEXT
WONTFIX : failures/expected/newlines_trailing.html = TEXT
WONTFIX : failures/expected/newlines_with_excess_CR.html = TEXT
WONTFIX : failures/expected/reftest.html = IMAGE
WONTFIX : failures/expected/text.html = TEXT
WONTFIX : failures/expected/timeout.html = TIMEOUT
WONTFIX SKIP : failures/expected/hang.html = TIMEOUT
WONTFIX SKIP : failures/expected/keyboard.html = CRASH
WONTFIX SKIP : failures/expected/exception.html = CRASH
"""

    # FIXME: This test was only being ignored because of missing a leading '/'.
    # Fixing the typo causes several tests to assert, so disabling the test entirely.
    # Add in a file should be ignored by test_files.find().
    #files[LAYOUT_TEST_DIR + '/userscripts/resources/iframe.html'] = 'iframe'

    fs = MockFileSystem(files, dirs=set(['/mock-checkout']))  # Make sure at least the checkout_root exists as a directory.
    fs._tests = test_list
    return fs
Ejemplo n.º 11
0
    def test_find_log_darwin(self):
        if not SystemHost().platform.is_mac():
            return

        older_mock_crash_report = make_mock_crash_report_darwin("DumpRenderTree", 28528)
        mock_crash_report = make_mock_crash_report_darwin("DumpRenderTree", 28530)
        newer_mock_crash_report = make_mock_crash_report_darwin("DumpRenderTree", 28529)
        other_process_mock_crash_report = make_mock_crash_report_darwin("FooProcess", 28527)
        misformatted_mock_crash_report = (
            "Junk that should not appear in a crash report"
            + make_mock_crash_report_darwin("DumpRenderTree", 28526)[200:]
        )
        files = {
            "/Users/mock/Library/Logs/DiagnosticReports/DumpRenderTree_2011-06-13-150718_quadzen.crash": older_mock_crash_report,
            "/Users/mock/Library/Logs/DiagnosticReports/DumpRenderTree_2011-06-13-150719_quadzen.crash": mock_crash_report,
            "/Users/mock/Library/Logs/DiagnosticReports/DumpRenderTree_2011-06-13-150720_quadzen.crash": newer_mock_crash_report,
            "/Users/mock/Library/Logs/DiagnosticReports/DumpRenderTree_2011-06-13-150721_quadzen.crash": None,
            "/Users/mock/Library/Logs/DiagnosticReports/DumpRenderTree_2011-06-13-150722_quadzen.crash": other_process_mock_crash_report,
            "/Users/mock/Library/Logs/DiagnosticReports/DumpRenderTree_2011-06-13-150723_quadzen.crash": misformatted_mock_crash_report,
        }
        filesystem = MockFileSystem(files)
        crash_logs = CrashLogs(MockSystemHost(filesystem=filesystem))
        log = crash_logs.find_newest_log("DumpRenderTree")
        self.assertMultiLineEqual(log, newer_mock_crash_report)
        log = crash_logs.find_newest_log("DumpRenderTree", 28529)
        self.assertMultiLineEqual(log, newer_mock_crash_report)
        log = crash_logs.find_newest_log("DumpRenderTree", 28530)
        self.assertMultiLineEqual(log, mock_crash_report)
        log = crash_logs.find_newest_log("DumpRenderTree", 28531)
        self.assertIsNone(log)
        log = crash_logs.find_newest_log("DumpRenderTree", newer_than=1.0)
        self.assertIsNone(log)

        def bad_read(path):
            raise IOError("IOError: No such file or directory")

        def bad_mtime(path):
            raise OSError("OSError: No such file or directory")

        filesystem.read_text_file = bad_read
        log = crash_logs.find_newest_log("DumpRenderTree", 28531, include_errors=True)
        self.assertIn("IOError: No such file or directory", log)

        filesystem = MockFileSystem(files)
        crash_logs = CrashLogs(MockSystemHost(filesystem=filesystem))
        filesystem.mtime = bad_mtime
        log = crash_logs.find_newest_log("DumpRenderTree", newer_than=1.0, include_errors=True)
        self.assertIn("OSError: No such file or directory", log)
Ejemplo n.º 12
0
class MockCheckout(object):
    def __init__(self):
        # FIXME: It's unclear if a MockCheckout is very useful.  A normal Checkout
        # with a MockSCM/MockFileSystem/MockExecutive is probably better.
        self._filesystem = MockFileSystem()

    def is_path_to_changelog(self, path):
        return self._filesystem.basename(path) == "ChangeLog"

    def recent_commit_infos_for_files(self, paths):
        return [self.commit_info_for_revision(32)]

    def modified_changelogs(self, git_commit, changed_files=None):
        # Ideally we'd return something more interesting here.  The problem is
        # that LandDiff will try to actually read the patch from disk!
        return []

    def commit_message_for_this_commit(self, git_commit, changed_files=None):
        return MockCommitMessage()

    def apply_patch(self, patch):
        pass

    def apply_reverse_diffs(self, revision):
        pass
Ejemplo n.º 13
0
    def test_find_log_darwin(self):
        if not SystemHost().platform.is_mac():
            return

        crash_logs = self.create_crash_logs_darwin()
        log = crash_logs.find_newest_log("DumpRenderTree")
        self.assertMultiLineEqual(log, self.newer_mock_crash_report)
        log = crash_logs.find_newest_log("DumpRenderTree", 28529)
        self.assertMultiLineEqual(log, self.newer_mock_crash_report)
        log = crash_logs.find_newest_log("DumpRenderTree", 28530)
        self.assertMultiLineEqual(log, self.mock_crash_report)
        log = crash_logs.find_newest_log("DumpRenderTree", 28531)
        self.assertIsNone(log)
        log = crash_logs.find_newest_log("DumpRenderTree", newer_than=1.0)
        self.assertIsNone(log)

        def bad_read(path):
            raise IOError('IOError: No such file or directory')

        def bad_mtime(path):
            raise OSError('OSError: No such file or directory')

        self.filesystem.read_text_file = bad_read
        log = crash_logs.find_newest_log("DumpRenderTree", 28531, include_errors=True)
        self.assertIn('IOError: No such file or directory', log)

        self.filesystem = MockFileSystem(self.files)
        crash_logs = CrashLogs(MockSystemHost(filesystem=self.filesystem))
        self.filesystem.mtime = bad_mtime
        log = crash_logs.find_newest_log("DumpRenderTree", newer_than=1.0, include_errors=True)
        self.assertIn('OSError: No such file or directory', log)
Ejemplo n.º 14
0
    def setUp(self):
        files = {
          '/foo/bar/baz.py': '',
          '/foo/bar/baz_unittest.py': '',
          '/foo2/bar2/baz2.py': '',
          '/foo2/bar2/baz2.pyc': '',
          '/foo2/bar2/baz2_integrationtest.py': '',
          '/foo2/bar2/missing.pyc': '',
          '/tmp/another_unittest.py': '',
        }
        self.fs = MockFileSystem(files)
        self.finder = TestFinder(self.fs)
        self.finder.add_tree('/foo', 'bar')
        self.finder.add_tree('/foo2')

        # Here we have to jump through a hoop to make sure test-webkitpy doesn't log
        # any messages from these tests :(.
        self.root_logger = logging.getLogger()
        self.log_handler = None
        for h in self.root_logger.handlers:
            if getattr(h, 'name', None) == 'webkitpy.test.main':
                self.log_handler = h
                break
        if self.log_handler:
            self.log_level = self.log_handler.level
            self.log_handler.level = logging.CRITICAL
 def setUp(self):
     files = {}
     files['/test/some-file'] = 'contents'
     files['/test/some-other-file'] = 'other contents'
     files['/test/b/c'] = 'c'
     self._filesystem = MockFileSystem(files)
     self._fileset = DirectoryFileSet('/test', self._filesystem)
Ejemplo n.º 16
0
 def setUp(self):
     self.filesystem = MockFileSystem()
     self.http_lock = HttpLock(
         None, "WebKitTestHttpd.lock.", "WebKitTest.lock", filesystem=self.filesystem, executive=MockExecutive()
     )
     # FIXME: Shouldn't we be able to get these values from the http_lock object directly?
     self.lock_file_path_prefix = self.filesystem.join(self.http_lock._lock_path, self.http_lock._lock_file_prefix)
     self.lock_file_name = self.lock_file_path_prefix + "0"
Ejemplo n.º 17
0
    def test_overrides_and_builder_names(self):
        port = self.make_port()

        filesystem = MockFileSystem()
        port._filesystem = filesystem
        port.path_from_chromium_base = lambda *comps: '/' + '/'.join(comps)

        overrides_path = port.path_from_chromium_base('webkit', 'tools', 'layout_tests', 'test_expectations.txt')
        OVERRIDES = 'foo'
        filesystem.files[overrides_path] = OVERRIDES

        port._options.builder_name = 'DUMMY_BUILDER_NAME'
        self.assertEquals(port.test_expectations_overrides(), OVERRIDES)

        port._options.builder_name = 'builder (deps)'
        self.assertEquals(port.test_expectations_overrides(), OVERRIDES)

        port._options.builder_name = 'builder'
        self.assertEquals(port.test_expectations_overrides(), None)
Ejemplo n.º 18
0
    def test_overrides_and_builder_names(self):
        port = self.make_port()

        filesystem = MockFileSystem()
        port._filesystem = filesystem
        port.path_from_chromium_base = lambda *comps: "/" + "/".join(comps)

        overrides_path = port.path_from_chromium_base("webkit", "tools", "layout_tests", "test_expectations.txt")
        OVERRIDES = "foo"
        filesystem.files[overrides_path] = OVERRIDES

        port._options.builder_name = "DUMMY_BUILDER_NAME"
        self.assertEquals(port.test_expectations_overrides(), OVERRIDES)

        port._options.builder_name = "builder (deps)"
        self.assertEquals(port.test_expectations_overrides(), OVERRIDES)

        port._options.builder_name = "builder"
        self.assertEquals(port.test_expectations_overrides(), None)
Ejemplo n.º 19
0
class MockCheckout(object):
    def __init__(self):
        # FIXME: It's unclear if a MockCheckout is very useful.  A normal Checkout
        # with a MockSCM/MockFileSystem/MockExecutive is probably better.
        self._filesystem = MockFileSystem()

    # FIXME: This should move onto the Host object, and we should use a MockCommitterList for tests.
    _committer_list = CommitterList()

    def commit_info_for_revision(self, svn_revision):
        # The real Checkout would probably throw an exception, but this is the only way tests have to get None back at the moment.
        if not svn_revision:
            return None
        return CommitInfo(svn_revision, "*****@*****.**", {
            "bug_id": 50000,
            "author_name": "Adam Barth",
            "author_email": "*****@*****.**",
            "author": self._committer_list.contributor_by_email("*****@*****.**"),
            "reviewer_text": "Darin Adler",
            "reviewer": self._committer_list.committer_by_name("Darin Adler"),
            "changed_files": [
                "path/to/file",
                "another/file",
            ],
        })

    def is_path_to_changelog(self, path):
        return self._filesystem.basename(path) == "ChangeLog"

    def bug_id_for_revision(self, svn_revision):
        return 12345

    def recent_commit_infos_for_files(self, paths):
        return [self.commit_info_for_revision(32)]

    def modified_changelogs(self, git_commit, changed_files=None):
        # Ideally we'd return something more interesting here.  The problem is
        # that LandDiff will try to actually read the patch from disk!
        return []

    def commit_message_for_this_commit(self, git_commit, changed_files=None):
        return MockCommitMessage()

    def chromium_deps(self):
        return MockDEPS()

    def apply_patch(self, patch):
        pass

    def apply_reverse_diffs(self, revision):
        pass

    def suggested_reviewers(self, git_commit, changed_files=None):
        # FIXME: We should use a shared mock commiter list.
        return [_mock_reviewers[0]]
Ejemplo n.º 20
0
class ChangeDirectoryTest(unittest.TestCase):
    _original_directory = "/original"
    _checkout_root = "/WebKit"

    def setUp(self):
        self._log = LogTesting.setUp(self)
        self.filesystem = MockFileSystem(
            dirs=[self._original_directory, self._checkout_root], cwd=self._original_directory
        )

    def tearDown(self):
        self._log.tearDown()

    def _change_directory(self, paths, checkout_root):
        return change_directory(self.filesystem, paths=paths, checkout_root=checkout_root)

    def _assert_result(
        self, actual_return_value, expected_return_value, expected_log_messages, expected_current_directory
    ):
        self.assertEqual(actual_return_value, expected_return_value)
        self._log.assertMessages(expected_log_messages)
        self.assertEqual(self.filesystem.getcwd(), expected_current_directory)

    def test_paths_none(self):
        paths = self._change_directory(checkout_root=self._checkout_root, paths=None)
        self._assert_result(paths, None, [], self._checkout_root)

    def test_paths_convertible(self):
        paths = ["/WebKit/foo1.txt", "/WebKit/foo2.txt"]
        paths = self._change_directory(checkout_root=self._checkout_root, paths=paths)
        self._assert_result(paths, ["foo1.txt", "foo2.txt"], [], self._checkout_root)

    def test_with_scm_paths_unconvertible(self):
        paths = ["/WebKit/foo1.txt", "/outside/foo2.txt"]
        paths = self._change_directory(checkout_root=self._checkout_root, paths=paths)
        log_messages = [
            """WARNING: Path-dependent style checks may not work correctly:

  One of the given paths is outside the WebKit checkout of the current
  working directory:

    Path: /outside/foo2.txt
    Checkout root: /WebKit

  Pass only files below the checkout root to ensure correct results.
  See the help documentation for more info.

"""
        ]
        self._assert_result(paths, paths, log_messages, self._original_directory)
    def test_additional_platform_directory(self):
        filesystem = MockFileSystem()
        options, args = optparse.OptionParser().parse_args([])
        port = base.Port(port_name="foo", filesystem=filesystem, options=options)
        port.baseline_search_path = lambda: []
        layout_test_dir = port.layout_tests_dir()
        test_file = filesystem.join(layout_test_dir, "fast", "test.html")

        # No additional platform directory
        self.assertEqual(port.expected_baselines(test_file, ".txt"), [(None, "fast/test-expected.txt")])

        # Simple additional platform directory
        options.additional_platform_directory = ["/tmp/local-baselines"]
        filesystem.files = {"/tmp/local-baselines/fast/test-expected.txt": "foo"}
        self.assertEqual(
            port.expected_baselines(test_file, ".txt"), [("/tmp/local-baselines", "fast/test-expected.txt")]
        )

        # Multiple additional platform directories
        options.additional_platform_directory = ["/foo", "/tmp/local-baselines"]
        self.assertEqual(
            port.expected_baselines(test_file, ".txt"), [("/tmp/local-baselines", "fast/test-expected.txt")]
        )
    def test_create_unit_test_results(self):
        host = MockHost()
        reader = LayoutTestResultsReader(host, "/mock-results", "/var/logs")
        unit_tests_results_path = '/mock-results/webkit_unit_tests_output.xml'
        no_failures_xml = """<?xml version="1.0" encoding="UTF-8"?>
<testsuites tests="3" failures="0" disabled="0" errors="0" time="11.35" name="AllTests">
  <testsuite name="RenderTableCellDeathTest" tests="3" failures="0" disabled="0" errors="0" time="0.677">
    <testcase name="CanSetColumn" status="run" time="0.168" classname="RenderTableCellDeathTest" />
    <testcase name="CrashIfSettingUnsetColumnIndex" status="run" time="0.129" classname="RenderTableCellDeathTest" />
    <testcase name="CrashIfSettingUnsetRowIndex" status="run" time="0.123" classname="RenderTableCellDeathTest" />
  </testsuite>
</testsuites>"""
        host.filesystem = MockFileSystem(
            {unit_tests_results_path: no_failures_xml})
        self.assertEqual(reader._create_unit_test_results(), [])
Ejemplo n.º 23
0
    def test_find_log_darwin(self):
        if not SystemHost().platform.is_mac():
            return

        crash_logs = self.create_crash_logs_darwin()
        log = crash_logs.find_newest_log("DumpRenderTree")
        self.assertMultiLineEqual(log, self.newer_mock_crash_report)
        log = crash_logs.find_newest_log("DumpRenderTree", 28529)
        self.assertMultiLineEqual(log, self.newer_mock_crash_report)
        log = crash_logs.find_newest_log("DumpRenderTree", 28530)
        self.assertMultiLineEqual(log, self.mock_crash_report)
        log = crash_logs.find_newest_log("DumpRenderTree", 28531)
        self.assertIsNone(log)
        log = crash_logs.find_newest_log("DumpRenderTree", newer_than=1.0)
        self.assertIsNone(log)

        def bad_read(path):
            raise IOError('IOError: No such file or directory')

        def bad_mtime(path):
            raise OSError('OSError: No such file or directory')

        self.filesystem.read_text_file = bad_read
        log = crash_logs.find_newest_log("DumpRenderTree",
                                         28531,
                                         include_errors=True)
        self.assertIn('IOError: No such file or directory', log)

        self.filesystem = MockFileSystem(self.files)
        crash_logs = CrashLogs(MockSystemHost(filesystem=self.filesystem),
                               CrashLogsTest.DARWIN_MOCK_CRASH_DIRECTORY)
        self.filesystem.mtime = bad_mtime
        log = crash_logs.find_newest_log("DumpRenderTree",
                                         newer_than=1.0,
                                         include_errors=True)
        self.assertIn('OSError: No such file or directory', log)
Ejemplo n.º 24
0
def get_test_config(test_files=[], result_files=[]):
    # We could grab this from port.layout_tests_dir(), but instantiating a fully mocked port is a pain.
    layout_tests_directory = "/mock-checkout/LayoutTests"
    results_directory = '/WebKitBuild/Debug/layout-test-results'
    mock_filesystem = MockFileSystem()
    for file in test_files:
        file_path = mock_filesystem.join(layout_tests_directory, file)
        mock_filesystem.files[file_path] = ''
    for file in result_files:
        file_path = mock_filesystem.join(results_directory, file)
        mock_filesystem.files[file_path] = ''

    class TestMacPort(WebKitPort):
        port_name = "mac"
        def __init__(self):
            WebKitPort.__init__(self, filesystem=mock_filesystem, host=MockHost())

    return TestConfig(
        TestMacPort(),
        layout_tests_directory,
        results_directory,
        ('mac', 'mac-leopard', 'win', 'linux'),
        mock_filesystem,
        MockSCM())
Ejemplo n.º 25
0
    def test_import_dir_with_empty_init_py(self):
        FAKE_FILES = {
            '/tests/csswg/test1/__init__.py': '',
            '/tests/csswg/test2/__init__.py': 'NOTEMPTY',
        }

        host = MockHost()
        host.filesystem = MockFileSystem(files=FAKE_FILES)

        importer = TestImporter(host, FAKE_SOURCE_DIR, self._parse_options(['-n', '-d', 'w3c', '-t', '/tests/csswg']))
        importer.do_import()

        self.assertTrue(host.filesystem.exists("/mock-checkout/LayoutTests/w3c/test1/__init__.py"))
        self.assertTrue(host.filesystem.exists("/mock-checkout/LayoutTests/w3c/test2/__init__.py"))
        self.assertTrue(host.filesystem.getsize("/mock-checkout/LayoutTests/w3c/test1/__init__.py") > 0)
Ejemplo n.º 26
0
    def test_find_log_win(self):
        if not SystemHost().platform.is_win():
            return

        older_mock_crash_report = make_mock_crash_report_win('DumpRenderTree', 28528)
        mock_crash_report = make_mock_crash_report_win('DumpRenderTree', 28530)
        newer_mock_crash_report = make_mock_crash_report_win('DumpRenderTree', 28529)
        other_process_mock_crash_report = make_mock_crash_report_win('FooProcess', 28527)
        misformatted_mock_crash_report = 'Junk that should not appear in a crash report' + make_mock_crash_report_win('DumpRenderTree', 28526)[200:]
        files = {}
        files['~/CrashLog_1d58_2013-06-03_12-21-20-110.txt'] = older_mock_crash_report
        files['~/CrashLog_abcd_2013-06-03_12-22-19-129.txt'] = mock_crash_report
        files['~/CrashLog_2eff_2013-06-03_12-23-20-150.txt'] = newer_mock_crash_report
        files['~/CrashLog_31a0_2013-06-03_12-24-22-119.txt'] = None
        files['~/CrashLog_01a3_2013-06-03_12-25-23-120.txt'] = other_process_mock_crash_report
        files['~/CrashLog_aadd_2013-06-03_12-26-24-121.txt'] = misformatted_mock_crash_report
        filesystem = MockFileSystem(files)
        mock_host = MockSystemHost(os_name='win', filesystem=filesystem)
        crash_logs = CrashLogs(mock_host, "~")

        log = crash_logs.find_newest_log("DumpRenderTree", 28529)
        self.assertMultiLineEqual(log, newer_mock_crash_report)
        log = crash_logs.find_newest_log("DumpRenderTree", 28530)
        self.assertMultiLineEqual(log, mock_crash_report)
        log = crash_logs.find_newest_log("DumpRenderTree", 28531)
        self.assertIsNone(log)
        log = crash_logs.find_newest_log("DumpRenderTree", newer_than=1.0)
        self.assertIsNone(log)

        def bad_read(path):
            raise IOError('IOError: No such file or directory')

        filesystem.read_text_file = bad_read
        filesystem.read_binary_file = bad_read
        log = crash_logs.find_newest_log("DumpRenderTree", 28531, include_errors=True)
        self.assertIn('IOError: No such file or directory', log)
    def test_delete_entries(self):
        fs = MockFileSystem()
        fs.write_text_file(self._changelog_path, self._example_changelog)
        ChangeLog(self._changelog_path, fs).delete_entries(8)
        actual_contents = fs.read_text_file(self._changelog_path)
        expected_contents = """2011-10-11  Antti Koivisto  <*****@*****.**>

       Resolve regular and visited link style in a single pass
       https://bugs.webkit.org/show_bug.cgi?id=69838

       Reviewed by Darin Adler

       We can simplify and speed up selector matching by removing the recursive matching done
       to generate the style for the :visited pseudo selector. Both regular and visited link style
       can be generated in a single pass through the style selector.

== Rolled over to ChangeLog-2009-06-16 ==
"""
        self.assertEqual(actual_contents.splitlines(), expected_contents.splitlines())

        ChangeLog(self._changelog_path, fs).delete_entries(2)
        actual_contents = fs.read_text_file(self._changelog_path)
        expected_contents = "== Rolled over to ChangeLog-2009-06-16 ==\n"
        self.assertEqual(actual_contents.splitlines(), expected_contents.splitlines())
Ejemplo n.º 28
0
    def test_import_dir_with_empty_init_py(self):
        FAKE_FILES = {
            '/tests/csswg/test1/__init__.py': '',
            '/tests/csswg/test2/__init__.py': 'NOTEMPTY',
        }

        host = MockHost()
        host.filesystem = MockFileSystem(files=FAKE_FILES)

        importer = TestImporter(host, FAKE_SOURCE_DIR, optparse.Values({"overwrite": False, 'destination': 'w3c', 'test_paths': ['/tests/csswg']}))
        importer.do_import()

        self.assertTrue(host.filesystem.exists("/mock-checkout/LayoutTests/w3c/test1/__init__.py"))
        self.assertTrue(host.filesystem.exists("/mock-checkout/LayoutTests/w3c/test2/__init__.py"))
        self.assertTrue(host.filesystem.getsize("/mock-checkout/LayoutTests/w3c/test1/__init__.py") > 0)
Ejemplo n.º 29
0
    def test_import_dir_with_no_tests_and_no_hg(self):
        host = MockHost()
        host.executive = MockExecutive2(exception=OSError())
        host.filesystem = MockFileSystem(files=FAKE_FILES)

        importer = TestImporter(
            host, FAKE_SOURCE_DIR,
            self._parse_options(['-n', '-d', 'w3c', '-t', FAKE_TEST_PATH]))

        oc = OutputCapture()
        oc.capture_output()
        try:
            importer.do_import()
        finally:
            oc.restore_output()
Ejemplo n.º 30
0
    def test_report_flaky_tests_creating_bug(self):
        tool = MockTool()
        tool.filesystem = MockFileSystem({"/mock-results/foo/bar-diffs.txt": "mock"})
        tool.status_server = MockStatusServer(bot_id="mock-bot-id")
        reporter = FlakyTestReporter(tool, 'dummy-queue')
        reporter._lookup_bug_for_flaky_test = lambda bug_id: None
        patch = tool.bugs.fetch_attachment(10000)
        expected_logs = """Bug does not already exist for foo/bar.html, creating.
MOCK create_bug
bug_title: Flaky Test: foo/bar.html
bug_description: This is an automatically generated bug from the dummy-queue.
foo/bar.html has been flaky on the dummy-queue.

foo/bar.html was authored by [email protected].
http://trac.webkit.org/browser/trunk/LayoutTests/foo/bar.html

The dummy-queue just saw foo/bar.html flake (text diff) while processing attachment 10000 on bug 50000.
Bot: mock-bot-id  Port: MockPort  Platform: MockPlatform 1.0

The bots will update this with information from each new failure.

If you believe this bug to be fixed or invalid, feel free to close.  The bots will re-open if the flake re-occurs.

If you would like to track this test fix with another bug, please close this bug as a duplicate.  The bots will follow the duplicate chain when making future comments.

component: Tools / Tests
cc: [email protected]
blocked: 50856
MOCK add_attachment_to_bug: bug_id=60001, description=Failure diff from mock-bot-id filename=failure.diff mimetype=None
MOCK bug comment: bug_id=50000, cc=None
--- Begin comment ---
The dummy-queue encountered the following flaky tests while processing attachment 10000:

foo/bar.html bug 60001 (author: [email protected])
The dummy-queue is continuing to process your patch.
--- End comment ---

"""
        test_results = [self._mock_test_result('foo/bar.html')]

        class MockZipFile(object):
            def read(self, path):
                return ""

            def namelist(self):
                return ['foo/bar-diffs.txt']

        OutputCapture().assert_outputs(self, reporter.report_flaky_tests, [patch, test_results, MockZipFile()], expected_logs=expected_logs)
Ejemplo n.º 31
0
 def test_ref_test_without_ref_is_skipped(self):
     host = MockHost()
     host.filesystem = MockFileSystem(
         files={
             '/blink/w3c/dir1/my-ref-test.html':
             '<html><head><link rel="match" href="not-here.html" /></head></html>',
             '/mock-checkout/third_party/WebKit/LayoutTests/W3CImportExpectations':
             '',
         })
     copier = TestCopier(host, FAKE_SOURCE_REPO_DIR)
     copier.find_importable_tests()
     self.assertEqual(copier.import_list, [])
     self.assertLog([
         'WARNING: Skipping: /blink/w3c/dir1/my-ref-test.html\n',
         'WARNING:   Reason: Ref file "/blink/w3c/dir1/not-here.html" was not found.\n'
     ])
Ejemplo n.º 32
0
    def test_lock_file_list(self):
        self.http_lock._filesystem = MockFileSystem({
            self.lock_file_path_prefix + "6": "",
            self.lock_file_path_prefix + "1": "",
            self.lock_file_path_prefix + "4": "",
            self.lock_file_path_prefix + "3": "",
        })

        expected_file_list = [
            self.lock_file_path_prefix + "1",
            self.lock_file_path_prefix + "3",
            self.lock_file_path_prefix + "4",
            self.lock_file_path_prefix + "6",
        ]

        self.assertEqual(self.http_lock._lock_file_list(), expected_file_list)
Ejemplo n.º 33
0
    def test_import_dir_with_no_tests(self):
        host = MockHost()
        host.executive = MockExecutive2(exception=ScriptError(
            "abort: no repository found in '/Volumes/Source/src/wk/Tools/Scripts/webkitpy/w3c' (.hg not found)!"
        ))
        host.filesystem = MockFileSystem(files=FAKE_FILES)

        importer = TestImporter(
            host, FAKE_SOURCE_DIR,
            self._parse_options(['-n', '-d', 'w3c', '-t', FAKE_TEST_PATH]))
        oc = OutputCapture()
        oc.capture_output()
        try:
            importer.do_import()
        finally:
            oc.restore_output()
Ejemplo n.º 34
0
    def test_run(self):
        capture = OutputCapture()
        options = MockOptions(git_commit='MOCK git commit')

        files = {'/Users/mock/.subversion/config': 'enable-auto-props = yes\n*.png = svn:mime-type=image/png'}
        fs = MockFileSystem(files)
        scm = MockSCMDetector('git')

        step = AddSvnMimetypeForPng(MockTool(), options, MockSystemHost(os_name='linux', filesystem=fs), scm)
        state = {
            "changed_files": ["test.png", "test.txt"],
        }
        try:
            capture.assert_outputs(self, step.run, [state])
        except SystemExit, e:
            self.assertEqual(e.code, 1)
Ejemplo n.º 35
0
    def test(self):
        mock_filesystem = MockFileSystem({'/s/file1': 'A\nC\n', '/s/file2': 'B\n', '/s/file3': 'A\nB\n'}, dirs=['/output'])

        merger = merge_results.MergeFilesLinesSorted(mock_filesystem)

        with self.assertFilesAdded(mock_filesystem, {'/output/out1': 'A\nC\n'}):
            merger('/output/out1', ['/s/file1'])

        with self.assertFilesAdded(mock_filesystem, {'/output/out2': 'B\n'}):
            merger('/output/out2', ['/s/file2'])

        with self.assertFilesAdded(mock_filesystem, {'/output/out3': 'A\nB\nC\n'}):
            merger('/output/out3', ['/s/file1', '/s/file2'])

        with self.assertFilesAdded(mock_filesystem, {'/output/out4': 'A\nB\nB\n'}):
            merger('/output/out4', ['/s/file2', '/s/file3'])
Ejemplo n.º 36
0
    def test_test_expectations(self):
        # Check that we read both the expectations file and anything in a
        # Skipped file, and that we include the feature and platform checks.
        files = {
            '/mock-checkout/LayoutTests/platform/testwebkitport/test_expectations.txt':
            'BUG_TESTEXPECTATIONS SKIP : fast/html/article-element.html = FAIL\n',
            '/mock-checkout/LayoutTests/platform/testwebkitport/Skipped':
            'fast/html/keygen.html',
        }
        mock_fs = MockFileSystem(files)
        port = TestWebKitPort(filesystem=mock_fs)
        self.assertEqual(
            port.test_expectations(),
            """BUG_TESTEXPECTATIONS SKIP : fast/html/article-element.html = FAIL
BUG_SKIPPED SKIP : fast/html/keygen.html = FAIL
BUG_SKIPPED SKIP : media = FAIL""")
 def test_missing_layout_test_results(self):
     host = MockHost()
     reader = LayoutTestResultsReader(host, "/mock-results", "/var/logs")
     layout_tests_results_path = '/mock-results/full_results.json'
     unit_tests_results_path = '/mock-results/webkit_unit_tests_output.xml'
     host.filesystem = MockFileSystem({
         layout_tests_results_path: None,
         unit_tests_results_path: None
     })
     # Make sure that our filesystem mock functions as we expect.
     self.assertRaises(IOError, host.filesystem.read_text_file,
                       layout_tests_results_path)
     self.assertRaises(IOError, host.filesystem.read_text_file,
                       unit_tests_results_path)
     # layout_test_results shouldn't raise even if the results.json file is missing.
     self.assertIsNone(reader.results())
Ejemplo n.º 38
0
    def test(self):
        mock_filesystem = MockFileSystem({'/s/file1': '1', '/s/file2': '2', '/s/file3': '1'}, dirs=['/output'])

        merger = merge_results.MergeFilesMatchingContents(mock_filesystem)

        with self.assertFilesAdded(mock_filesystem, {'/output/out1': '1'}):
            merger('/output/out1', ['/s/file1'])

        with self.assertFilesAdded(mock_filesystem, {'/output/out2': '2'}):
            merger('/output/out2', ['/s/file2'])

        with self.assertRaises(merge_results.MergeFailure):
            merger('/output/out3', ['/s/file1', '/s/file2'])

        with self.assertFilesAdded(mock_filesystem, {'/output/out4': '1'}):
            merger('/output/out4', ['/s/file1', '/s/file3'])
Ejemplo n.º 39
0
    def test_last_wpt_exported_commit(self):
        host = MockHost()
        return_vals = [
            'deadbeefcafe',
            '123',
            '9ea4fc353a4b1c11c6e524270b11baa4d1ddfde8',
        ]
        host.executive = MockExecutive(
            run_command_fn=lambda _: return_vals.pop())
        host.filesystem = MockFileSystem()
        local_wpt = LocalWPT(host)

        wpt_sha, chromium_commit = local_wpt.most_recent_chromium_commit()
        self.assertEqual(wpt_sha, '9ea4fc353a4b1c11c6e524270b11baa4d1ddfde8')
        self.assertEqual(chromium_commit.position, '123')
        self.assertEqual(chromium_commit.sha, 'deadbeefcafe')
Ejemplo n.º 40
0
 def test_does_not_import_reftestlist_file(self):
     host = MockHost()
     host.filesystem = MockFileSystem(files=FAKE_FILES)
     copier = TestCopier(host, FAKE_SOURCE_REPO_DIR)
     copier.find_importable_tests()
     self.assertEqual(copier.import_list, [{
         'copy_list': [{
             'dest': 'has_shebang.txt',
             'src': '/blink/w3c/dir/has_shebang.txt'
         }, {
             'dest': 'README.txt',
             'src': '/blink/w3c/dir/README.txt'
         }],
         'dirname':
         '/blink/w3c/dir',
     }])
 def _assert_message_for_revert_output(self, args, expected_entry):
     changelog_contents = u"%s\n%s" % (
         changelog_unittest.ChangeLogTest._new_entry_boilerplate,
         changelog_unittest.ChangeLogTest._example_changelog)
     changelog_path = "ChangeLog"
     fs = MockFileSystem(
         {changelog_path: changelog_contents.encode("utf-8")})
     changelog = ChangeLog(changelog_path, fs)
     changelog.update_with_unreviewed_message(
         PrepareChangeLogForRevert._message_for_revert(*args))
     actual_entry = changelog.latest_entry()
     self.assertMultiLineEqual(actual_entry.contents(), expected_entry)
     self.assertIsNone(actual_entry.reviewer_text())
     # These checks could be removed to allow this to work on other entries:
     self.assertEqual(actual_entry.author_name(), "Eric Seidel")
     self.assertEqual(actual_entry.author_email(), "*****@*****.**")
    def test_archive_last_layout_test_results(self):
        host = MockHost()
        results_directory = "/mock-results"
        reader = LayoutTestResultsReader(host, results_directory, "/var/logs")
        patch = host.bugs.fetch_attachment(10001)
        host.filesystem = MockFileSystem()
        # Should fail because the results_directory does not exist.
        expected_logs = "/mock-results does not exist, not archiving.\n"
        archive = OutputCapture().assert_outputs(self, reader.archive, [patch], expected_logs=expected_logs)
        self.assertIsNone(archive)

        host.filesystem.maybe_make_directory(results_directory)
        self.assertTrue(host.filesystem.exists(results_directory))

        self.assertIsNotNone(reader.archive(patch))
        self.assertFalse(host.filesystem.exists(results_directory))
Ejemplo n.º 43
0
 def test_missing_layout_test_results(self):
     tool = MockTool()
     reader = LayoutTestResultsReader(tool, "/var/logs")
     layout_tests_results_path = '/mock-results/full_results.json'
     unit_tests_results_path = '/mock-results/webkit_unit_tests_output.xml'
     tool.filesystem = MockFileSystem({
         layout_tests_results_path: None,
         unit_tests_results_path: None
     })
     # Make sure that our filesystem mock functions as we expect.
     self.assertRaises(IOError, tool.filesystem.read_text_file,
                       layout_tests_results_path)
     self.assertRaises(IOError, tool.filesystem.read_text_file,
                       unit_tests_results_path)
     # layout_test_results shouldn't raise even if the results.html file is missing.
     self.assertEquals(reader.results(), None)
Ejemplo n.º 44
0
class HttpLockTest(unittest.TestCase):
    def setUp(self):
        self.filesystem = MockFileSystem()
        self.http_lock = HttpLock(
            None, "WebKitTestHttpd.lock.", "WebKitTest.lock", filesystem=self.filesystem, executive=MockExecutive()
        )
        # FIXME: Shouldn't we be able to get these values from the http_lock object directly?
        self.lock_file_path_prefix = self.filesystem.join(self.http_lock._lock_path, self.http_lock._lock_file_prefix)
        self.lock_file_name = self.lock_file_path_prefix + "0"

    def test_current_lock_pid(self):
        # FIXME: Once Executive wraps getpid, we can mock this and not use a real pid.
        current_pid = os.getpid()
        self.http_lock._filesystem.write_text_file(self.lock_file_name, str(current_pid))
        self.assertEqual(self.http_lock._current_lock_pid(), current_pid)

    def test_extract_lock_number(self):
        lock_file_list = (
            self.lock_file_path_prefix + "00",
            self.lock_file_path_prefix + "9",
            self.lock_file_path_prefix + "001",
            self.lock_file_path_prefix + "021",
        )

        expected_number_list = (0, 9, 1, 21)

        for lock_file, expected in zip(lock_file_list, expected_number_list):
            self.assertEqual(self.http_lock._extract_lock_number(lock_file), expected)

    def test_lock_file_list(self):
        self.http_lock._filesystem = MockFileSystem(
            {
                self.lock_file_path_prefix + "6": "",
                self.lock_file_path_prefix + "1": "",
                self.lock_file_path_prefix + "4": "",
                self.lock_file_path_prefix + "3": "",
            }
        )

        expected_file_list = [
            self.lock_file_path_prefix + "1",
            self.lock_file_path_prefix + "3",
            self.lock_file_path_prefix + "4",
            self.lock_file_path_prefix + "6",
        ]

        self.assertEqual(self.http_lock._lock_file_list(), expected_file_list)
Ejemplo n.º 45
0
 def test_count_total_leaks(self):
     detector = self._make_detector()
     detector._filesystem = MockFileSystem({
         # The \xff is some non-utf8 characters to make sure we don't blow up trying to parse the file.
         '/mock-results/DumpRenderTree-1234-leaks.txt':
         '\xff\nProcess 1234: 12 leaks for 40 total leaked bytes.\n\xff\n',
         '/mock-results/DumpRenderTree-23423-leaks.txt':
         'Process 1235: 12341 leaks for 27934 total leaked bytes.\n',
         '/mock-results/DumpRenderTree-823-leaks.txt':
         'Process 12356: 23412 leaks for 18 total leaked bytes.\n',
     })
     leak_file_paths = [
         '/mock-results/DumpRenderTree-1234-leaks.txt',
         '/mock-results/DumpRenderTree-23423-leaks.txt',
         '/mock-results/DumpRenderTree-823-leaks.txt'
     ]
     self.assertEqual(detector.count_total_leaks(leak_file_paths), 35765)
Ejemplo n.º 46
0
 def test_files_with_long_path_are_skipped(self):
     host = MockHost()
     host.filesystem = MockFileSystem(files=FAKE_FILES)
     long_file_path = '%s/%s.html' % (FAKE_SOURCE_REPO_DIR, 'x' * 150)
     short_file_path = '%s/x.html' % FAKE_SOURCE_REPO_DIR
     host.filesystem.write_text_file(long_file_path, '<html></html>')
     host.filesystem.write_text_file(short_file_path, '<html></html>')
     copier = TestCopier(host, FAKE_SOURCE_REPO_DIR)
     copier.find_importable_tests()
     self.assertLog([
         'WARNING: Skipping: %s\n' % long_file_path,
         'WARNING:   Reason: Long path. Max length 140; see http://crbug.com/609871.\n',
         'INFO: Skipping: /blink/w3c/dir/reftest.list\n',
         'INFO:   Reason: This file may cause Chromium presubmit to fail.\n',
         'INFO: Skipping: /blink/w3c/dir/OWNERS\n',
         'INFO:   Reason: This file may cause Chromium presubmit to fail.\n',
     ])
Ejemplo n.º 47
0
    def test(self):
        mock_filesystem = MockFileSystem(
            {
                '/s1/file1': 'a',
                '/s2/file1': 'b',
                '/s3/file1': 'c'
            },
            dirs=['/output'])

        merger = merge_results.MergeFilesKeepFiles(mock_filesystem)

        with self.assertFilesAdded(mock_filesystem, {
                '/output/out_0': 'a',
                '/output/out_1': 'b',
                '/output/out_2': 'c'
        }):
            merger('/output/out', ['/s1/file1', '/s2/file1', '/s3/file1'])
Ejemplo n.º 48
0
    def test_initpy_generation(self):
        FAKE_FILES = {
            '/mock-checkout/WebKitBuild/w3c-tests/csswg-tests/.gitmodules': '[submodule "tools/resources"]\n	path = tools/resources\n	url = https://github.com/w3c/testharness.js.git\n  ignore = dirty\n',
            '/mock-checkout/WebKitBuild/w3c-tests/web-platform-tests/.gitmodules': '[submodule "tools/resources"]\n	path = tools/resources\n	url = https://github.com/w3c/testharness.js.git\n  ignore = dirty\n',
        }

        FAKE_FILES.update(FAKE_REPOSITORY)

        host = MockHost()
        host.executive = MockExecutive2()
        host.filesystem = MockFileSystem(files=FAKE_FILES)

        fs = self.import_downloaded_tests(['--no-fetch', '--import-all', '-d', 'w3c'], FAKE_FILES)

        self.assertFalse(fs.exists('/mock-checkout/LayoutTests/w3c/csswg-tests/__init__.py'))
        self.assertTrue(fs.exists('/mock-checkout/LayoutTests/w3c/web-platform-tests/__init__.py'))
        self.assertTrue(fs.getsize('/mock-checkout/LayoutTests/w3c/web-platform-tests/__init__.py') > 0)
Ejemplo n.º 49
0
 def test_find_unused_filename(self):
     filesystem = MockFileSystem({
         "dir/foo.jpg": "",
         "dir/foo-1.jpg": "",
         "dir/foo-2.jpg": "",
     })
     workspace = Workspace(filesystem, None)
     self.assertEqual(workspace.find_unused_filename("bar", "bar", "bar"),
                      "bar/bar.bar")
     self.assertIsNone(
         workspace.find_unused_filename("dir", "foo", "jpg",
                                        search_limit=1))
     self.assertIsNone(
         workspace.find_unused_filename("dir", "foo", "jpg",
                                        search_limit=2))
     self.assertEqual(workspace.find_unused_filename("dir", "foo", "jpg"),
                      "dir/foo-3.jpg")
Ejemplo n.º 50
0
    def test_stop(self):
        filesystem = MockFileSystem(files={'/tmp/.X42-lock': '1234\n'})
        port = Port(MockSystemHost(log_executive=True, filesystem=filesystem), 'xvfbdrivertestport', options=MockOptions(configuration='Release'))
        port._executive.kill_process = lambda x: _log.info("MOCK kill_process pid: " + str(x))
        driver = XvfbDriver(port, worker_number=0, pixel_tests=True)

        class FakeXvfbProcess(object):
            pid = 1234

        driver._xvfb_process = FakeXvfbProcess()
        driver._lock_file = '/tmp/.X42-lock'

        expected_logs = "MOCK kill_process pid: 1234\n"
        OutputCapture().assert_outputs(self, driver.stop, [], expected_logs=expected_logs)

        self.assertIsNone(driver._xvfb_process)
        self.assertFalse(port._filesystem.exists(driver._lock_file))
Ejemplo n.º 51
0
    def test_archive_last_layout_test_results(self):
        host = MockHost()
        results_directory = "/mock-results"
        reader = LayoutTestResultsReader(host, results_directory, "/var/logs")
        patch = host.bugs.fetch_attachment(10001)
        host.filesystem = MockFileSystem()
        # Should fail because the results_directory does not exist.
        with OutputCapture(level=logging.INFO) as captured:
            archive = reader.archive(patch)
        self.assertEqual(captured.root.log.getvalue(), '/mock-results does not exist, not archiving.\n')
        self.assertIsNone(archive)

        host.filesystem.maybe_make_directory(results_directory)
        self.assertTrue(host.filesystem.exists(results_directory))

        self.assertIsNotNone(reader.archive(patch))
        self.assertFalse(host.filesystem.exists(results_directory))
Ejemplo n.º 52
0
class ChangeDirectoryTest(unittest.TestCase):
    _original_directory = "/original"
    _checkout_root = "/WebKit"

    def setUp(self):
        self._log = LogTesting.setUp(self)
        self.filesystem = MockFileSystem(dirs=[self._original_directory, self._checkout_root], cwd=self._original_directory)

    def tearDown(self):
        self._log.tearDown()

    def _change_directory(self, paths, checkout_root):
        return change_directory(self.filesystem, paths=paths, checkout_root=checkout_root)

    def _assert_result(self, actual_return_value, expected_return_value,
                       expected_log_messages, expected_current_directory):
        self.assertEqual(actual_return_value, expected_return_value)
        self._log.assertMessages(expected_log_messages)
        self.assertEqual(self.filesystem.getcwd(), expected_current_directory)

    def test_paths_none(self):
        paths = self._change_directory(checkout_root=self._checkout_root, paths=None)
        self._assert_result(paths, None, [], self._checkout_root)

    def test_paths_convertible(self):
        paths = ["/WebKit/foo1.txt", "/WebKit/foo2.txt"]
        paths = self._change_directory(checkout_root=self._checkout_root, paths=paths)
        self._assert_result(paths, ["foo1.txt", "foo2.txt"], [], self._checkout_root)

    def test_with_scm_paths_unconvertible(self):
        paths = ["/WebKit/foo1.txt", "/outside/foo2.txt"]
        paths = self._change_directory(checkout_root=self._checkout_root, paths=paths)
        log_messages = [
"""WARNING: Path-dependent style checks may not work correctly:

  One of the given paths is outside the WebKit checkout of the current
  working directory:

    Path: /outside/foo2.txt
    Checkout root: /WebKit

  Pass only files below the checkout root to ensure correct results.
  See the help documentation for more info.

"""]
        self._assert_result(paths, paths, log_messages, self._original_directory)
 def test_ensure_bug_url(self):
     capture = OutputCapture()
     step = PrepareChangeLog(MockTool(), MockOptions())
     changelog_contents = u"%s\n%s" % (self._new_entry_boilerplate, self._example_changelog)
     changelog_path = "ChangeLog"
     state = {
         "bug_title": "Example title",
         "bug_id": 1234,
         "changelogs": [changelog_path],
     }
     step._tool.filesystem = MockFileSystem()
     step._tool.filesystem.write_text_file(changelog_path, changelog_contents)
     capture.assert_outputs(self, step._ensure_bug_url, [state])
     actual_contents = step._tool.filesystem.read_text_file(changelog_path)
     expected_message = "Example title\n        http://example.com/1234"
     expected_contents = changelog_contents.replace("Need a short description (OOPS!).\n        Need the bug URL (OOPS!).", expected_message)
     self.assertEqual(actual_contents, expected_contents)
Ejemplo n.º 54
0
 def test_is_test_file(self):
     filesystem = MockFileSystem()
     self.assertTrue(Port._is_test_file(filesystem, '', 'foo.html'))
     self.assertTrue(Port._is_test_file(filesystem, '', 'foo.shtml'))
     self.assertTrue(
         Port._is_test_file(filesystem, '', 'test-ref-test.html'))
     self.assertFalse(Port._is_test_file(filesystem, '', 'foo.png'))
     self.assertFalse(
         Port._is_test_file(filesystem, '', 'foo-expected.html'))
     self.assertFalse(
         Port._is_test_file(filesystem, '', 'foo-expected-mismatch.html'))
     self.assertFalse(Port._is_test_file(filesystem, '', 'foo-ref.html'))
     self.assertFalse(Port._is_test_file(filesystem, '', 'foo-notref.html'))
     self.assertFalse(Port._is_test_file(filesystem, '', 'foo-notref.xht'))
     self.assertFalse(Port._is_test_file(filesystem, '', 'foo-ref.xhtml'))
     self.assertFalse(Port._is_test_file(filesystem, '', 'ref-foo.html'))
     self.assertFalse(Port._is_test_file(filesystem, '', 'notref-foo.xhr'))
Ejemplo n.º 55
0
    def test_last_wpt_exported_commit(self):
        host = MockHost()
        host.executive = mock_git_commands(
            {
                'rev-list': '9ea4fc353a4b1c11c6e524270b11baa4d1ddfde8',
                'footers': 'Cr-Commit-Position: 123',
                'crrev-parse': 'add087a97844f4b9e307d9a216940582d96db306',
            },
            strict=True)
        host.filesystem = MockFileSystem()
        local_wpt = LocalWPT(host, 'token')

        wpt_sha, chromium_commit = local_wpt.most_recent_chromium_commit()
        self.assertEqual(wpt_sha, '9ea4fc353a4b1c11c6e524270b11baa4d1ddfde8')
        self.assertEqual(chromium_commit.position, '123')
        self.assertEqual(chromium_commit.sha,
                         'add087a97844f4b9e307d9a216940582d96db306')
Ejemplo n.º 56
0
class MockCheckout(object):
    def __init__(self):
        # FIXME: It's unclear if a MockCheckout is very useful.  A normal Checkout
        # with a MockSCM/MockFileSystem/MockExecutive is probably better.
        self._filesystem = MockFileSystem()

    def commit_info_for_revision(self, svn_revision):
        # There are legacy tests that all expected these revision numbers to map
        # to the same commit description (now mock_revisions[1])
        if svn_revision in [32, 123, 852, 853, 854, 1234, 21654, 21655, 21656]:
            return mock_revisions[1]

        if svn_revision in mock_revisions:
            return mock_revisions[svn_revision]

        # any "unrecognized" svn_revision will return None.

    def is_path_to_changelog(self, path):
        return self._filesystem.basename(path) == "ChangeLog"

    def bug_id_for_revision(self, svn_revision):
        return 12345

    def recent_commit_infos_for_files(self, paths):
        return [self.commit_info_for_revision(32)]

    def modified_changelogs(self, git_commit, changed_files=None):
        # Ideally we'd return something more interesting here.  The problem is
        # that LandDiff will try to actually read the patch from disk!
        return []

    def commit_message_for_this_commit(self, git_commit, changed_files=None):
        return MockCommitMessage()

    def chromium_deps(self):
        return MockDEPS()

    def apply_patch(self, patch):
        pass

    def apply_reverse_diffs(self, revision):
        pass

    def suggested_reviewers(self, git_commit, changed_files=None):
        # FIXME: We should use a shared mock commiter list.
        return [_mock_reviewers[0]]
 def test_move_baselines(self):
     fs = MockFileSystem()
     fs.write_binary_file("/mock-checkout/LayoutTests/platform/chromium-win/another/test-expected.txt", "result A")
     fs.write_binary_file(
         "/mock-checkout/LayoutTests/platform/chromium-cg-mac/another/test-expected.txt", "result A"
     )
     fs.write_binary_file("/mock-checkout/LayoutTests/platform/chromium/another/test-expected.txt", "result B")
     baseline_optimizer = BaselineOptimizer(MockSCM(), fs)
     baseline_optimizer._move_baselines(
         "another/test-expected.txt",
         {
             "LayoutTests/platform/chromium-win": "aaa",
             "LayoutTests/platform/chromium-cg-mac": "aaa",
             "LayoutTests/platform/chromium": "bbb",
         },
         {"LayoutTests/platform/chromium": "aaa"},
     )
     self.assertEqual(
         fs.read_binary_file("/mock-checkout/LayoutTests/platform/chromium/another/test-expected.txt"), "result A"
     )
Ejemplo n.º 58
0
    def test_overrides_and_builder_names(self):
        port = self.make_port()

        filesystem = MockFileSystem()
        port._filesystem = filesystem
        port.path_from_chromium_base = lambda *comps: '/' + '/'.join(comps)

        chromium_overrides_path = port.path_from_chromium_base(
            'webkit', 'tools', 'layout_tests', 'test_expectations.txt')
        CHROMIUM_OVERRIDES = 'contents of %s\n' % chromium_overrides_path
        filesystem.write_text_file(chromium_overrides_path, CHROMIUM_OVERRIDES)
        skia_overrides_path = port.path_from_chromium_base(
            'skia', 'skia_test_expectations.txt')
        SKIA_OVERRIDES = 'contents of %s\n' % skia_overrides_path
        filesystem.write_text_file(skia_overrides_path, SKIA_OVERRIDES)

        additional_expectations_path = port.path_from_chromium_base(
            'additional_expectations.txt')
        ADDITIONAL_EXPECTATIONS = 'contents of %s\n' % additional_expectations_path
        filesystem.write_text_file(additional_expectations_path, ADDITIONAL_EXPECTATIONS)

        port._options.builder_name = 'DUMMY_BUILDER_NAME'
        port._options.additional_expectations = []
        self.assertEquals(port.test_expectations_overrides(),
                          SKIA_OVERRIDES + CHROMIUM_OVERRIDES)
        port._options.additional_expectations = [additional_expectations_path]
        self.assertEquals(port.test_expectations_overrides(),
                          SKIA_OVERRIDES + CHROMIUM_OVERRIDES + ADDITIONAL_EXPECTATIONS)

        port._options.builder_name = 'builder (deps)'
        port._options.additional_expectations = []
        self.assertEquals(port.test_expectations_overrides(),
                          SKIA_OVERRIDES + CHROMIUM_OVERRIDES)
        port._options.additional_expectations = [additional_expectations_path]
        self.assertEquals(port.test_expectations_overrides(),
                          SKIA_OVERRIDES + CHROMIUM_OVERRIDES + ADDITIONAL_EXPECTATIONS)

        # A builder which does NOT observe the Chromium test_expectations,
        # but still observes the Skia test_expectations...
        port._options.builder_name = 'builder'
        port._options.additional_expectations = []
        self.assertEquals(port.test_expectations_overrides(),
                          SKIA_OVERRIDES)
        port._options.additional_expectations = [additional_expectations_path]
        self.assertEquals(port.test_expectations_overrides(),
                          SKIA_OVERRIDES + ADDITIONAL_EXPECTATIONS)
Ejemplo n.º 59
0
    def create_crash_logs_darwin(self):
        if not SystemHost().platform.is_mac():
            return

        self.older_mock_crash_report = make_mock_crash_report_darwin('DumpRenderTree', 28528)
        self.mock_crash_report = make_mock_crash_report_darwin('DumpRenderTree', 28530)
        self.newer_mock_crash_report = make_mock_crash_report_darwin('DumpRenderTree', 28529)
        self.other_process_mock_crash_report = make_mock_crash_report_darwin('FooProcess', 28527)
        self.misformatted_mock_crash_report = 'Junk that should not appear in a crash report' + make_mock_crash_report_darwin('DumpRenderTree', 28526)[200:]
        self.files = {}
        self.files['/Users/mock/Library/Logs/DiagnosticReports/DumpRenderTree_2011-06-13-150718_quadzen.crash'] = self.older_mock_crash_report
        self.files['/Users/mock/Library/Logs/DiagnosticReports/DumpRenderTree_2011-06-13-150719_quadzen.crash'] = self.mock_crash_report
        self.files['/Users/mock/Library/Logs/DiagnosticReports/DumpRenderTree_2011-06-13-150720_quadzen.crash'] = self.newer_mock_crash_report
        self.files['/Users/mock/Library/Logs/DiagnosticReports/DumpRenderTree_2011-06-13-150721_quadzen.crash'] = None
        self.files['/Users/mock/Library/Logs/DiagnosticReports/DumpRenderTree_2011-06-13-150722_quadzen.crash'] = self.other_process_mock_crash_report
        self.files['/Users/mock/Library/Logs/DiagnosticReports/DumpRenderTree_2011-06-13-150723_quadzen.crash'] = self.misformatted_mock_crash_report
        self.filesystem = MockFileSystem(self.files)
        crash_logs = CrashLogs(MockSystemHost(filesystem=self.filesystem))
        logs = self.filesystem.files_under('/Users/mock/Library/Logs/DiagnosticReports/')
        for path in reversed(sorted(logs)):
            self.assertTrue(path in self.files.keys())
        return crash_logs
Ejemplo n.º 60
0
    def setUp(self):
        files = {
          '/foo/bar/baz.py': '',
          '/foo/bar/baz_unittest.py': '',
          '/foo2/bar2/baz2.py': '',
          '/foo2/bar2/baz2.pyc': '',
          '/foo2/bar2/baz2_integrationtest.py': '',
          '/foo2/bar2/missing.pyc': '',
          '/tmp/another_unittest.py': '',
        }
        self.fs = MockFileSystem(files)
        self.finder = Finder(self.fs)
        self.finder.add_tree('/foo', 'bar')
        self.finder.add_tree('/foo2')

        # Here we have to jump through a hoop to make sure test-webkitpy doesn't log
        # any messages from these tests :(.
        self.root_logger = logging.getLogger()
        self.log_levels = []
        self.log_handlers = self.root_logger.handlers[:]
        for handler in self.log_handlers:
            self.log_levels.append(handler.level)
            handler.level = logging.CRITICAL