def test_ref_test_with_ref_is_copied(self): host = MockHost() host.filesystem = MockFileSystem(files={ '/blink/w3c/dir1/my-ref-test.html': '<html><head><link rel="match" href="ref-file.html" />test</head></html>', '/blink/w3c/dir1/ref-file.html': '<html><head>test</head></html>', '/mock-checkout/third_party/WebKit/LayoutTests/W3CImportExpectations': '', '/mock-checkout/third_party/WebKit/Source/core/css/CSSProperties.in': '', }) importer = TestImporter(host, FAKE_SOURCE_REPO_DIR, self.options()) importer.find_importable_tests() self.assertEqual( importer.import_list, [ { 'copy_list': [ {'src': '/blink/w3c/dir1/ref-file.html', 'dest': 'ref-file.html'}, {'src': '/blink/w3c/dir1/ref-file.html', 'dest': 'my-ref-test-expected.html', 'reference_support_info': {}}, {'src': '/blink/w3c/dir1/my-ref-test.html', 'dest': 'my-ref-test.html'} ], 'dirname': '/blink/w3c/dir1', 'jstests': 0, 'reftests': 1, 'total_tests': 1 } ])
def test_harness_no_expectations(self): """Tests behavior when TestExpectations file doesn't exist. Tests that a warning is outputted if the TestExpectations file doesn't exist. """ # Set up the mock host and port. host = MockHost() host.port_factory = FakePortFactory(host) # Write the test file but not the TestExpectations file. test_expectation_path = ( host.port_factory.get().path_to_generic_test_expectations_file()) host.filesystem = MockFileSystem() self._write_tests_into_filesystem(host.filesystem) # Write out the fake builder bot results. expectation_factory = FakeBotTestExpectationsFactory() expectation_factory._all_results_by_builder = {} self.assertFalse(host.filesystem.isfile(test_expectation_path)) return_code = main(host, expectation_factory, []) self.assertEqual(return_code, 1) self.assertLog([ "WARNING: Didn't find generic expectations file at: %s\n" % test_expectation_path ]) self.assertFalse(host.filesystem.isfile(test_expectation_path))
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'")) host.filesystem = MockFileSystem(files=FAKE_FILES) importer = TestImporter(host, FAKE_SOURCE_REPO_DIR, self.options()) importer.do_import() # No exception raised.
def test_files_with_shebang_are_made_executable(self): host = MockHost() host.filesystem = MockFileSystem(files=FAKE_FILES) importer = TestImporter(host, FAKE_SOURCE_REPO_DIR, self.options()) importer.do_import() self.assertEqual( host.filesystem.executable_files, set(['/mock-checkout/third_party/WebKit/LayoutTests/w3c/blink/w3c/dir/has_shebang.txt']))
def test_clones_if_wpt_does_not_exist(self): host = MockHost() host.filesystem = MockFileSystem() LocalWPT(host) self.assertEqual(len(host.executive.calls), 1) self.assertEqual(host.executive.calls[0][1], 'clone')
def test_create_branch_with_patch(self): host = MockHost() host.filesystem = MockFileSystem() local_wpt = LocalWPT(host) local_wpt.create_branch_with_patch('branch-name', 'message', 'patch') self.assertEqual(len(host.executive.calls), 9)
def touched_files(self, touched_files, fs=None): host = MockHost() if fs: host.filesystem = fs else: fs = host.filesystem port = MockPort(host) return (fs, LayoutTestFinder(port, optparse.Values({'skipped': 'always', 'skip_failing_tests': False, 'http': True})).find_touched_tests(touched_files))
def test_last_wpt_exported_commit_not_found(self): host = MockHost() host.executive = MockExecutive2(run_command_fn=lambda _: None) host.filesystem = MockFileSystem() local_wpt = LocalWPT(host) commit = local_wpt.most_recent_chromium_commit() self.assertEqual(commit, (None, None))
def test_no_fetch_flag(self): host = MockHost() host.filesystem = MockFileSystem(files={ '/tmp/wpt': '' }) LocalWPT(host, no_fetch=True) self.assertEqual(len(host.executive.calls), 0)
def test_create_branch_with_patch(self): host = MockHost() host.filesystem = MockFileSystem() local_wpt = LocalWPT(host) local_branch_name = local_wpt.create_branch_with_patch('message', 'patch') self.assertEqual(len(host.executive.calls), 9) self.assertEqual(local_branch_name, 'chromium-export-try')
def test_filesystem_walk(self): mock_dir = 'foo' mock_files = {'foo/bar/baz': '', 'foo/a': '', 'foo/b': '', 'foo/c': ''} host = MockHost() host.filesystem = MockFileSystem(files=mock_files) self.assertEquals(host.filesystem.walk(mock_dir), [('foo', ['bar'], ['a', 'b', 'c']), ('foo/bar', [], ['baz'])])
def test_run(self): host = MockHost() host.filesystem = MockFileSystem() local_wpt = LocalWPT(host) local_wpt.run(['echo', 'rutabaga']) self.assertEqual(len(host.executive.calls), 2) self.assertEqual(host.executive.calls[1], ['echo', 'rutabaga'])
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': '', '/mock-checkout/third_party/WebKit/Source/core/css/CSSProperties.in': '', }) importer = TestImporter(host, FAKE_SOURCE_REPO_DIR, self.options()) importer.find_importable_tests() self.assertEqual(importer.import_list, [])
def test_fetches_if_wpt_exists(self): host = MockHost() host.filesystem = MockFileSystem(files={ '/tmp/wpt': '' }) LocalWPT(host) self.assertEqual(len(host.executive.calls), 2) self.assertEqual(host.executive.calls[0][1], 'fetch') self.assertEqual(host.executive.calls[1][1], 'checkout')
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())
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()
def test_last_wpt_exported_commit(self): host = MockHost() return_vals = [ '123', '9ea4fc353a4b1c11c6e524270b11baa4d1ddfde8', ] host.executive = MockExecutive2(run_command_fn=lambda _: return_vals.pop()) host.filesystem = MockFileSystem() local_wpt = LocalWPT(host, no_fetch=True) commit = local_wpt.most_recent_chromium_commit() self.assertEqual(commit, ('9ea4fc353a4b1c11c6e524270b11baa4d1ddfde8', '123'))
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, FAKE_REPO_DIR, optparse.Values({"overwrite": False})) oc = OutputCapture() oc.capture_output() try: importer.do_import() finally: oc.restore_output()
def test_main(self): host = MockHost() host.filesystem = test.unit_test_filesystem() stdin = newstringio.StringIO() stdout = newstringio.StringIO() stderr = newstringio.StringIO() res = mock_drt.main(['--platform', 'test'] + self.extra_args(False), host, stdin, stdout, stderr) self.assertEqual(res, 0) self.assertEqual(stdout.getvalue(), '') self.assertEqual(stderr.getvalue(), '') self.assertEqual(host.filesystem.written_files, {})
def test_harness_remove_all(self): """Tests that removing all expectations doesn't delete the file. Make sure we're prepared for the day when we exterminated flakes. """ self._define_builders({ "WebKit Linux Trusty": { "port_name": "linux-trusty", "specifiers": ['Trusty', 'Release'] }, "WebKit Linux Trusty (dbg)": { "port_name": "linux-trusty", "specifiers": ['Trusty', 'Debug'] }, }) # Set up the mock host and port. host = MockHost() host.port_factory = FakePortFactory( host, all_build_types=('release', 'debug'), all_systems=(('trusty', 'x86_64'),)) # Write out a fake TestExpectations file. test_expectation_path = ( host.port_factory.get().path_to_generic_test_expectations_file()) test_expectations = """ # Remove since passing on both bots. Bug(test) [ Linux ] test/a.html [ Failure Pass ]""" files = { test_expectation_path: test_expectations } host.filesystem = MockFileSystem(files) self._write_tests_into_filesystem(host.filesystem) # Write out the fake builder bot results. expectation_factory = FakeBotTestExpectationsFactory() expectation_factory._all_results_by_builder = { 'WebKit Linux Trusty': { "test/a.html": ["PASS", "PASS", "PASS"], }, 'WebKit Linux Trusty (dbg)': { "test/a.html": ["PASS", "PASS", "PASS"], }, } main(host, expectation_factory, []) self.assertTrue(host.filesystem.isfile(test_expectation_path)) self.assertEqual(host.filesystem.files[test_expectation_path], '')
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, FAKE_REPO_DIR, optparse.Values({"overwrite": False})) oc = OutputCapture() oc.capture_output() try: importer.do_import() finally: oc.restore_output()
def test_build_path(self): host = MockHost() host.filesystem = MockFileSystem(files={ '/mock-checkout/Source/WebKit/chromium/build/Release/DumpRenderTree.exe': 'exe', }) port = chromium_win.ChromiumWinPort(host) self.assertEquals( '/mock-checkout/Source/WebKit/chromium/build/Release/DumpRenderTree.exe', port._path_to_driver('Release')) self.assertEquals( '/mock-checkout/Source/WebKit/chromium/build/Debug/DumpRenderTree.exe', port._path_to_driver('Debug'))
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()
def test_update_win_future_test_expectations(self): host = MockHost() host.executive = MockExecutive2(exception=OSError()) host.filesystem = MockFileSystem(files={ '/mock-checkout/LayoutTests/platform/mac-wk1/imported/w3c/web-platform-tests/fetch/api/redirect/redirect-location-expected.txt': 'e-wk1', '/mock-checkout/LayoutTests/imported/w3c/web-platform-tests/dom/events/EventTarget-dispatchEvent-expected.txt': "g", '/mock-checkout/LayoutTests/imported/w3c/web-platform-tests/html/browsers/the-window-object/apis-for-creating-and-navigating-browsing-contexts-by-name/open-features-tokenization-001-expected.txt': "h", '/mock-checkout/LayoutTests/imported/w3c/web-platform-tests/html/browsers/windows/browsing-context-expected.txt': "i", '/mock-checkout/LayoutTests/imported/w3c/web-platform-tests/url/interfaces-expected.txt': "j-mac-wk2"}) mock_zip = MockZip() updater = TestExpectationUpdater(host, "123456", True, False, MockBugzilla(include_wk2=False, include_win_future=True), lambda content: mock_zip.unzip(content)) updater.do_update() self.assertTrue(self._is_matching(host, "platform/win/imported/w3c/web-platform-tests/url/interfaces-expected.txt", "j"))
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(), [])
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': '', '/mock-checkout/third_party/WebKit/Source/core/css/CSSProperties.in': '', }) importer = TestImporter(host, FAKE_SOURCE_REPO_DIR, self.options()) importer.find_importable_tests() self.assertEqual(importer.import_list, [])
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(), [])
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')
def test_harness_remove_all(self): """Tests that removing all expectations doesn't delete the file. Make sure we're prepared for the day when we exterminated flakes. """ self._define_builders({ "WebKit Linux Precise": { "port_name": "linux-precise", "specifiers": ['Precise', 'Release'] }, "WebKit Linux Precise (dbg)": { "port_name": "linux-precise", "specifiers": ['Precise', 'Debug'] }, }) # Setup the mock host and port. host = MockHost() host.port_factory = FakePortFactory(host) host.port_factory._all_build_types = ('release', 'debug') host.port_factory._all_systems = (('precise', 'x86_64'), ) # Write out a fake TestExpectations file. test_expectation_path = ( host.port_factory.get().path_to_generic_test_expectations_file()) test_expectations = """ # Remove since passing on both bots. Bug(test) [ Linux ] test/a.html [ Failure Pass ]""" files = {test_expectation_path: test_expectations} host.filesystem = MockFileSystem(files) self._write_tests_into_filesystem(host.filesystem) # Write out the fake builder bot results. expectation_factory = FakeBotTestExpectationsFactory() expectation_factory._all_results_by_builder = { 'WebKit Linux Precise': { "test/a.html": ["PASS", "PASS", "PASS"], }, 'WebKit Linux Precise (dbg)': { "test/a.html": ["PASS", "PASS", "PASS"], }, } main(host, expectation_factory, []) self.assertTrue(host.filesystem.isfile(test_expectation_path)) self.assertEqual(host.filesystem.files[test_expectation_path], '')
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, FAKE_REPO_DIR, optparse.Values({"overwrite": False})) oc = OutputCapture() oc.capture_output() try: importer.do_import() finally: oc.restore_output()
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)
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')
def test_manual_slow_test(self): tests_options = '{"a": ["slow"]}' FAKE_FILES = { '/mock-checkout/WebKitBuild/w3c-tests/csswg-tests/temp': '', '/mock-checkout/WebKitBuild/w3c-tests/web-platform-tests/t/new-manual.html': '<!doctype html><meta name="timeout" content="long"><script src="/resources/testharness.js"></script><script src="/resources/testharnessreport.js"></script>', '/mock-checkout/LayoutTests/tests-options.json': tests_options} 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/web-platform-tests/t/new-manual.html')) self.assertEquals(tests_options, fs.read_text_file('/mock-checkout/LayoutTests/tests-options.json'))
def test_fetch_when_wpt_dir_exists(self): host = MockHost() host.filesystem = MockFileSystem(files={'/tmp/wpt': ''}) local_wpt = LocalWPT(host) local_wpt.fetch() self.assertEqual( host.executive.calls, [['git', 'fetch', '--all'], ['git', 'checkout', 'origin/master'], ['git', 'remote'], [ 'git', 'remote', 'add', 'github', '[email protected]:w3c/web-platform-tests.git' ]])
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)
def test_filesystem_walk_deeply_nested(self): mock_dir = 'foo' mock_files = {'foo/bar/baz': '', 'foo/bar/quux': '', 'foo/a/x': '', 'foo/a/y': '', 'foo/a/z/lyrics': '', 'foo/b': '', 'foo/c': ''} host = MockHost() host.filesystem = MockFileSystem(files=mock_files) self.assertEquals(host.filesystem.walk(mock_dir), [('foo', ['a', 'bar'], ['c', 'b']), ('foo/a', ['z'], ['x', 'y']), ('foo/a/z', [], ['lyrics']), ('foo/bar', [], ['quux', 'baz'])])
def touched_files(self, touched_files, fs=None): host = MockHost() if fs: host.filesystem = fs else: fs = host.filesystem port = MockPort(host) return (fs, LayoutTestFinder( port, optparse.Values({ 'skipped': 'always', 'skip_failing_tests': False, 'http': True })).find_touched_tests(touched_files))
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)
def test_build_path(self): host = MockHost() host.filesystem = MockFileSystem( files={ '/mock-checkout/Source/WebKit/chromium/build/Release/DumpRenderTree.exe': 'exe', }) port = chromium_win.ChromiumWinPort(host) self.assertEquals( '/mock-checkout/Source/WebKit/chromium/build/Release/DumpRenderTree.exe', port._path_to_driver('Release')) self.assertEquals( '/mock-checkout/Source/WebKit/chromium/build/Debug/DumpRenderTree.exe', port._path_to_driver('Debug'))
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()
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))
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()
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())
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' ])
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 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))
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', ])
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)
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)
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))
def test_test_files(self): host = MockHost() files = { '/mock-checkout/LayoutTests/canvas/philip/test.html': '', '/mock-checkout/LayoutTests/fast/canvas/test.html': '', '/mock-checkout/LayoutTests/fast/html/test.html': '', '/mock-checkout/LayoutTests/media/test.html': '', '/mock-checkout/LayoutTests/foo/bar.html': '', } host.filesystem = MockFileSystem(files) def test_paths(port_name): return host.port_factory.get(port_name).tests([]) self.assertEqual(test_paths('chromium-gpu-linux'), set(['canvas/philip/test.html', 'fast/canvas/test.html', 'media/test.html'])) self.assertEqual(test_paths('chromium-gpu-mac-leopard'), set(['canvas/philip/test.html', 'fast/canvas/test.html'])) self.assertEqual(test_paths('chromium-gpu-cg-mac-leopard'), set(['fast/html/test.html']))
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, FAKE_REPO_DIR, optparse.Values({ "overwrite": False, 'destination': 'w3c' })) oc = OutputCapture() oc.capture_output() try: importer.do_import() finally: oc.restore_output()
def test_filesystem_walk_deeply_nested(self): mock_dir = 'foo' mock_files = { 'foo/bar/baz': '', 'foo/bar/quux': '', 'foo/a/x': '', 'foo/a/y': '', 'foo/a/z/lyrics': '', 'foo/b': '', 'foo/c': '' } host = MockHost() host.filesystem = MockFileSystem(files=mock_files) self.assertEquals(host.filesystem.walk(mock_dir), [('foo', ['a', 'bar'], ['c', 'b']), ('foo/a', ['z'], ['x', 'y']), ('foo/a/z', [], ['lyrics']), ('foo/bar', [], ['quux', 'baz'])])
def import_downloaded_tests(self, args, files): # files are passed as parameter as we cannot clone/fetch/checkout a repo in mock system. class TestDownloaderMock(TestDownloader): def __init__(self, repository_directory, host, options): TestDownloader.__init__(self, repository_directory, host, options) def _git_submodules_status(self, repository_directory): return 'adb4d391a69877d4a1eaaf51d1725c99a5b8ed84 tools/resources' host = MockHost() host.executive = MockExecutive2() host.filesystem = MockFileSystem(files=files) options, args = parse_args(args) importer = TestImporter(host, None, options) importer._test_downloader = TestDownloaderMock(importer.tests_download_path, importer.host, importer.options) importer.do_import() return host.filesystem
def test_remove_obsolete_content(self): FAKE_FILES = { '/mock-checkout/WebKitBuild/w3c-tests/csswg-tests/temp': '', '/mock-checkout/WebKitBuild/w3c-tests/web-platform-tests/t/new.html': '<!doctype html><script src="/resources/testharness.js"></script><script src="/resources/testharnessreport.js"></script>', '/mock-checkout/WebKitBuild/w3c-tests/web-platform-tests/t/w3c-import.log': 'List of files:\n/LayoutTests/w3c/web-platform-tests/t/obsolete.html', '/mock-checkout/LayoutTests/w3c/web-platform-tests/t/obsolete.html': 'obsoleted content', '/mock-checkout/LayoutTests/w3c/web-platform-tests/t/obsolete-expected.txt': 'PASS', } 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/web-platform-tests/t/obsolete.html')) self.assertFalse(fs.exists('/mock-checkout/LayoutTests/w3c/web-platform-tests/t/obsolete-expected.txt')) self.assertTrue(fs.exists('/mock-checkout/LayoutTests/w3c/web-platform-tests/t/new.html'))
def test_ref_test_with_ref_is_copied(self): host = MockHost() host.filesystem = MockFileSystem(files={ '/blink/w3c/dir1/my-ref-test.html': '<html><head><link rel="match" href="ref-file.html" />test</head></html>', '/blink/w3c/dir1/ref-file.html': '<html><head>test</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, [ { 'copy_list': [ {'src': '/blink/w3c/dir1/ref-file.html', 'dest': 'ref-file.html'}, {'src': '/blink/w3c/dir1/my-ref-test.html', 'dest': 'my-ref-test.html'} ], 'dirname': '/blink/w3c/dir1', } ])
def test_create_branch_with_patch(self): host = MockHost() host.filesystem = MockFileSystem() local_wpt = LocalWPT(host, 'token') local_wpt.fetch() local_branch_name = local_wpt.create_branch_with_patch('message', 'patch', 'author') self.assertEqual(local_branch_name, 'chromium-export-try') self.assertEqual(host.executive.calls, [ ['git', 'clone', 'https://[email protected]/w3c/web-platform-tests.git', '/tmp/wpt'], ['git', 'reset', '--hard', 'HEAD'], ['git', 'clean', '-fdx'], ['git', 'checkout', 'origin/master'], ['git', 'branch', '-a'], ['git', 'branch', '-a'], ['git', 'checkout', '-b', 'chromium-export-try'], ['git', 'apply', '-'], ['git', 'add', '.'], ['git', 'commit', '--author', 'author', '-am', 'message'], ['git', 'push', '-f', 'origin', 'chromium-export-try']])
def test_update_test_expectations(self): host = MockHost() host.executive = MockExecutive2(exception=OSError()) host.filesystem = MockFileSystem(files={ '/mock-checkout/LayoutTests/platform/mac-wk1/imported/w3c/web-platform-tests/fetch/api/redirect/redirect-location-expected.txt': 'e-wk1', '/mock-checkout/LayoutTests/imported/w3c/web-platform-tests/dom/events/EventTarget-dispatchEvent-expected.txt': "g", '/mock-checkout/LayoutTests/imported/w3c/web-platform-tests/html/browsers/the-window-object/apis-for-creating-and-navigating-browsing-contexts-by-name/open-features-tokenization-001-expected.txt': "h", '/mock-checkout/LayoutTests/imported/w3c/web-platform-tests/html/browsers/windows/browsing-context-expected.txt': "i", '/mock-checkout/LayoutTests/imported/w3c/web-platform-tests/url/interfaces-expected.txt': "j-mac-wk2"}) mock_zip = MockZip() updater = TestExpectationUpdater(host, "123456", True, False, MockBugzilla(), lambda content: mock_zip.unzip(content)) updater.do_update() # mac-wk2 expectation self.assertTrue(self._is_matching(host, "imported/w3c/web-platform-tests/fetch/api/redirect/redirect-count-cross-origin-expected.txt", "a")) # no need to add mac-wk1 specific expectation self.assertFalse(self._exists(host, "platform/mac-wk1/imported/w3c/web-platform-tests/fetch/api/redirect/redirect-count-cross-origin-expected.txt")) # mac-wk1/ios-simulator-wk2 specific expectation self.assertTrue(self._is_matching(host, "platform/mac-wk1/imported/w3c/web-platform-tests/html/browsers/windows/browsing-context-expected.txt", "f-wk1b")) self.assertTrue(self._is_matching(host, "platform/ios-wk2/imported/w3c/web-platform-tests/url/interfaces-expected.txt", "j")) # removal of mac-wk1 expectation since no longer different self.assertFalse(self._exists(host, "platform/mac-wk1/imported/w3c/web-platform-tests/fetch/api/redirect/redirect-location-expected.txt"))
def test_does_not_import_owner_files(self): host = MockHost() host.filesystem = MockFileSystem(files=FAKE_FILES) importer = TestImporter(host, FAKE_SOURCE_REPO_DIR, self.options()) importer.find_importable_tests() self.assertEqual(importer.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', 'jstests': 0, 'reftests': 0, 'total_tests': 0, }])