def test_generate_manifest_successful_run(self): # This test doesn't test any aspect of the real manifest script, it just # asserts that TestImporter._generate_manifest would invoke the script. host = MockHost() importer = TestImporter(host) blink_path = '/mock-checkout/third_party/WebKit' host.filesystem.write_text_file(blink_path + '/LayoutTests/external/wpt/MANIFEST.json', '{}') importer._generate_manifest() self.assertEqual( host.executive.calls, [ [ 'python', blink_path + '/Tools/Scripts/webkitpy/thirdparty/wpt/wpt/wpt', 'manifest', '--work', '--tests-root', blink_path + '/LayoutTests/external/wpt', ], [ 'git', 'add', blink_path + '/LayoutTests/external/WPT_BASE_MANIFEST.json', ] ])
def test_get_directory_owners_no_changed_files(self): host = MockHost() host.filesystem.write_text_file('/mock-checkout/third_party/WebKit/LayoutTests/W3CImportExpectations', '') host.filesystem.write_text_file('/mock-checkout/third_party/WebKit/LayoutTests/external/wpt/foo/OWNERS', '[email protected]\n') importer = TestImporter(host) self.assertEqual(importer.get_directory_owners(), {})
def test_run_commit_queue_for_cl_only_checks_non_blink_bots(self): host = MockHost() host.filesystem.write_text_file( '/mock-checkout/third_party/WebKit/LayoutTests/W3CImportExpectations', '') host.builders = BuilderList({ 'fakeos_blink_rel': { 'port_name': 'test-fakeos', 'specifiers': ['FakeOS', 'Release'], 'is_try_builder': True, } }) importer = TestImporter(host) importer.git_cl = MockGitCL(host, results={ Build('fakeos_blink_rel', 123): TryJobStatus('COMPLETED', 'FAILURE'), Build('cq-builder-b', 200): TryJobStatus('COMPLETED', 'SUCCESS'), }) importer.fetch_new_expectations_and_baselines = lambda: None success = importer.run_commit_queue_for_cl() self.assertTrue(success) self.assertLog([ 'INFO: Triggering CQ try jobs.\n', 'INFO: CQ appears to have passed; trying to commit.\n', 'INFO: Update completed.\n', ]) self.assertEqual(importer.git_cl.calls, [ ['git', 'cl', 'try'], ['git', 'cl', 'upload', '-f', '--send-mail'], ['git', 'cl', 'set-commit'], ])
def test_commit_message(self): importer = TestImporter(MockHost()) self.assertEqual( importer._commit_message('aaaa', '1111'), 'Import 1111\n\n' 'Using wpt-import in Chromium aaaa.\n\n' 'No-Export: true')
def test_run_commit_queue_for_cl_pass(self): host = MockHost() host.filesystem.write_text_file( '/mock-checkout/third_party/WebKit/LayoutTests/W3CImportExpectations', '') importer = TestImporter(host) # Only the latest job for each builder is counted. importer.git_cl = MockGitCL(host, results={ Build('cq-builder-a', 120): TryJobStatus('COMPLETED', 'FAILURE'), Build('cq-builder-a', 123): TryJobStatus('COMPLETED', 'SUCCESS'), }) success = importer.run_commit_queue_for_cl() self.assertTrue(success) self.assertLog([ 'INFO: Triggering CQ try jobs.\n', 'INFO: CQ appears to have passed; trying to commit.\n', 'INFO: Update completed.\n', ]) self.assertEqual(importer.git_cl.calls, [ ['git', 'cl', 'try'], ['git', 'cl', 'upload', '-f', '--send-mail'], ['git', 'cl', 'set-commit'], ])
def test_update_test_expectations(self): host = MockHost() host.filesystem.files[ '/mock-checkout/third_party/WebKit/LayoutTests/TestExpectations'] = ( 'Bug(test) some/test/a.html [ Failure ]\n' 'Bug(test) some/test/b.html [ Failure ]\n' 'Bug(test) some/test/c.html [ Failure ]\n') host.filesystem.files[ '/mock-checkout/third_party/WebKit/LayoutTests/VirtualTestSuites'] = '[]' host.filesystem.files[ '/mock-checkout/third_party/WebKit/LayoutTests/new/a.html'] = '' host.filesystem.files[ '/mock-checkout/third_party/WebKit/LayoutTests/new/b.html'] = '' importer = TestImporter(host) deleted_tests = ['some/test/b.html'] renamed_test_pairs = { 'some/test/a.html': 'new/a.html', 'some/test/c.html': 'new/c.html', } importer.update_all_test_expectations_files(deleted_tests, renamed_test_pairs) self.assertMultiLineEqual( host.filesystem.read_text_file( '/mock-checkout/third_party/WebKit/LayoutTests/TestExpectations' ), ('Bug(test) new/a.html [ Failure ]\n' 'Bug(test) new/c.html [ Failure ]\n'))
def test_run_commit_queue_for_cl_closed_cl(self): host = MockHost() host.filesystem.write_text_file( '/mock-checkout/third_party/WebKit/LayoutTests/W3CImportExpectations', '') importer = TestImporter(host) importer.git_cl = MockGitCL( host, results=CLStatus( status='closed', try_job_results={ Build('cq-builder-a', 120): TryJobStatus('COMPLETED', 'SUCCESS'), Build('cq-builder-b', 200): TryJobStatus('COMPLETED', 'SUCCESS'), }, )) success = importer.run_commit_queue_for_cl() self.assertFalse(success) self.assertLog([ 'INFO: Triggering CQ try jobs.\n', 'ERROR: The CL was closed; aborting.\n', ]) self.assertEqual(importer.git_cl.calls, [ ['git', 'cl', 'try'], ])
def test_run_commit_queue_for_cl_fails(self): host = MockHost() host.filesystem.write_text_file( '/mock-checkout/third_party/WebKit/LayoutTests/W3CImportExpectations', '') importer = TestImporter(host) importer.git_cl = MockGitCL(host, results={ Build('cq-builder-a', 120): TryJobStatus('COMPLETED', 'SUCCESS'), Build('cq-builder-a', 123): TryJobStatus('COMPLETED', 'FAILURE'), Build('cq-builder-b', 200): TryJobStatus('COMPLETED', 'SUCCESS'), }) importer.fetch_new_expectations_and_baselines = lambda: None success = importer.run_commit_queue_for_cl() self.assertFalse(success) self.assertLog([ 'INFO: Triggering CQ try jobs.\n', 'ERROR: CQ appears to have failed; aborting.\n', ]) self.assertEqual(importer.git_cl.calls, [ ['git', 'cl', 'try'], ['git', 'cl', 'set-close'], ])
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) 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_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_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_main_abort_on_exportable_commit_if_open_pr_found(self): host = MockHost() host.filesystem.write_text_file( '/tmp/creds.json', '{"GH_USER": "******", "GH_TOKEN": "y"}') wpt_github = MockWPTGitHub(pull_requests=[ PullRequest('Title', 5, 'Commit body\nChange-Id: Iba5eba11', 'open', []), ]) importer = TestImporter(host, wpt_github=wpt_github) importer.exportable_but_not_exported_commits = lambda _: [ MockChromiumCommit(host, subject='Fake PR subject', change_id='Iba5eba11') ] importer.checkout_is_okay = lambda: True return_code = importer.main(['--credentials-json=/tmp/creds.json']) self.assertEqual(return_code, 0) self.assertLog([ 'INFO: Cloning GitHub w3c/web-platform-tests into /tmp/wpt\n', 'INFO: There were exportable but not-yet-exported commits:\n', 'INFO: Commit: https://fake-chromium-commit-viewer.org/+/14fd77e88e\n', 'INFO: Subject: Fake PR subject\n', 'INFO: PR: https://github.com/w3c/web-platform-tests/pull/5\n', 'INFO: Modified files in wpt directory in this commit:\n', 'INFO: third_party/WebKit/LayoutTests/external/wpt/one.html\n', 'INFO: third_party/WebKit/LayoutTests/external/wpt/two.html\n', 'INFO: Aborting import to prevent clobbering commits.\n', ])
def test_commit_changes(self): host = MockHost() importer = TestImporter(host) importer._has_changes = lambda: True importer._commit_changes('dummy message') self.assertEqual(host.executive.calls, [['git', 'commit', '--all', '-F', '-']])
def test_tbr_reviewer_nobody_on_rotation(self): host = MockHost() yesterday = (datetime.date.fromtimestamp(host.time()) - datetime.timedelta(days=1)).isoformat() host.web.urls[ROTATIONS_URL] = json.dumps({ 'calendar': [ { 'date': yesterday, 'participants': [['some-sheriff']], }, ], 'rotations': ['ecosystem_infra'] }) importer = TestImporter(host) self.assertEqual('qyearsley', importer.tbr_reviewer()) self.assertLog([]) today = datetime.date.fromtimestamp(host.time()).isoformat() host.web.urls[ROTATIONS_URL] = json.dumps({ 'calendar': [ { 'date': today, 'participants': [[''], ['some-sheriff']], }, ], 'rotations': ['ecosystem_infra', 'other-rotation'] }) self.assertEqual('qyearsley', importer.tbr_reviewer()) self.assertLog([])
def test_apply_exportable_commits_locally(self): host = MockHost() importer = TestImporter(host, wpt_github=MockWPTGitHub(pull_requests=[])) fake_commit = MockChromiumCommit( host, subject='My fake commit', patch=( 'Fake patch contents...\n' '--- a/third_party/WebKit/LayoutTests/external/wpt/css/css-ui-3/outline-004.html\n' '+++ b/third_party/WebKit/LayoutTests/external/wpt/css/css-ui-3/outline-004.html\n' '@@ -20,7 +20,7 @@\n' '...')) importer.exportable_but_not_exported_commits = lambda _: [fake_commit] applied = importer.apply_exportable_commits_locally(LocalWPT(host)) self.assertEqual(applied, [fake_commit]) self.assertEqual(host.executive.full_calls, [ MockCall( ['git', 'apply', '-'], { 'input': ( 'Fake patch contents...\n' '--- a/css/css-ui-3/outline-004.html\n' '+++ b/css/css-ui-3/outline-004.html\n' '@@ -20,7 +20,7 @@\n' '...'), 'cwd': '/tmp/wpt', 'env': None }), MockCall( ['git', 'add', '.'], kwargs={'input': None, 'cwd': '/tmp/wpt', 'env': None}), MockCall( ['git', 'commit', '--all', '-F', '-'], kwargs={'cwd': '/tmp/wpt', 'env': None}) ])
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_tbr_reviewer_no_response_uses_backup(self): host = MockHost() importer = TestImporter(host) self.assertEqual('qyearsley', importer.tbr_reviewer()) self.assertLog([ 'ERROR: Exception while fetching current sheriff: ' 'No JSON object could be decoded\n' ])
def test_cl_description_moves_noexport_tag(self): host = MockHost() host.executive = MockExecutive(output='Summary\n\nNo-Export: true\n\n') importer = TestImporter(host) description = importer._cl_description(directory_owners={}) self.assertIn( 'No-Export: true', description)
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_files_with_shebang_are_made_executable(self): host = MockHost() host.filesystem = MockFileSystem(files=FAKE_FILES) importer = TestImporter(host, FAKE_SOURCE_REPO_DIR) importer.do_import() self.assertEqual( host.filesystem.executable_files, set(['/mock-checkout/third_party/WebKit/LayoutTests/external/blink/w3c/dir/has_shebang.txt']))
def test_cl_description_moves_noexport_tag(self): host = MockHost() host.executive = MockExecutive(output='Summary\n\nNOEXPORT=true\n\n') importer = TestImporter(host) description = importer._cl_description(directory_owners={}) self.assertEqual(description, ('Summary\n\n' '[email protected]\n' 'NOEXPORT=true'))
def import_directory(self, args, files, test_paths): host = MockHost() host.executive = MockExecutive2() host.filesystem = MockFileSystem(files=files) options, args = parse_args(args) importer = TestImporter(host, test_paths, options) importer.do_import() return host.filesystem
def test_apply_exportable_commits_locally_returns_none_on_failure(self): host = MockHost() wpt_github = MockWPTGitHub(pull_requests=[]) importer = TestImporter(host, wpt_github=wpt_github) commit = MockChromiumCommit(host, subject='My fake commit') importer.exportable_but_not_exported_commits = lambda _: [commit] local_wpt = MockLocalWPT(apply_patch=['Failed']) # Failure to apply patch. applied = importer.apply_exportable_commits_locally(local_wpt) self.assertIsNone(applied)
def test_generate_manifest_command_not_found(self): # If we're updating csswg-test, then the manifest file won't be found. host = MockHost() host.filesystem.files = {} importer = TestImporter(host) importer._generate_manifest( '/mock-checkout/third_party/WebKit/LayoutTests/external/csswg-test' ) self.assertEqual(host.executive.calls, [])
def test_only_wpt_manifest_changed(self): host = MockHost() git = host.git() git.changed_files = lambda: ['third_party/WebKit/LayoutTests/external/WPT_BASE_MANIFEST.json', 'third_party/WebKit/LayoutTests/external/wpt/foo/x.html'] importer = TestImporter(host) self.assertFalse(importer._only_wpt_manifest_changed()) git.changed_files = lambda: ['third_party/WebKit/LayoutTests/external/WPT_BASE_MANIFEST.json'] self.assertTrue(importer._only_wpt_manifest_changed())
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 import_downloaded_tests(self, args, files): # files are passed as parameter as we cannot clone/fetch/checkout a repo in mock system. host = MockHost() host.executive = MockExecutive2() host.filesystem = MockFileSystem(files=files) options, args = parse_args(args) importer = TestImporter(host, None, options) importer.do_import() return host.filesystem
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) importer.find_importable_tests() self.assertEqual(importer.import_list, [])
def test_update_expectations_for_cl_all_jobs_pass(self): host = MockHost() host.filesystem.write_text_file( '/mock-checkout/third_party/WebKit/LayoutTests/W3CImportExpectations', '') importer = TestImporter(host) importer.git_cl = MockGitCL(host, results={ Build('builder-a', 123): TryJobStatus('COMPLETED', 'SUCCESS'), }) success = importer.update_expectations_for_cl() self.assertTrue(success)
def test_get_directory_owners(self): host = MockHost() host.filesystem.write_text_file('/mock-checkout/third_party/WebKit/LayoutTests/W3CImportExpectations', '') host.filesystem.write_text_file('/mock-checkout/third_party/WebKit/LayoutTests/external/wpt/foo/OWNERS', '[email protected]\n') git = MockGit(filesystem=host.filesystem, executive=host.executive, platform=host.platform) git.changed_files = lambda: ['third_party/WebKit/LayoutTests/external/wpt/foo/x.html'] host.git = lambda: git importer = TestImporter(host) self.assertEqual(importer.get_directory_owners(), {('*****@*****.**',): ['external/wpt/foo']})
def test_cl_description_with_empty_environ(self): host = MockHost() host.executive = MockExecutive(output='Last commit message\n\n') importer = TestImporter(host) description = importer._cl_description(directory_owners={}) self.assertEqual(description, ('Last commit message\n\n' '[email protected]\n' 'NOEXPORT=true')) self.assertEqual(host.executive.calls, [['git', 'log', '-1', '--format=%B']])
def test_executablebit(self): # executable source files are executable after importing 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_delete_orphaned_baselines(self): host = MockHost() dest_path = '/mock-checkout/third_party/WebKit/LayoutTests/external/wpt' host.filesystem.write_text_file(dest_path + '/b-expected.txt', '') host.filesystem.write_text_file(dest_path + '/b.x-expected.txt', '') host.filesystem.write_text_file(dest_path + '/b.x.html', '') importer = TestImporter(host) importer._delete_orphaned_baselines(dest_path) self.assertFalse(host.filesystem.exists(dest_path + '/b-expected.txt')) self.assertTrue(host.filesystem.exists(dest_path + '/b.x-expected.txt')) self.assertTrue(host.filesystem.exists(dest_path + '/b.x.html'))
def test_cl_description_with_environ_variables(self): host = MockHost() host.executive = MockExecutive(output='Last commit message\n') importer = TestImporter(host) importer.host.environ['BUILDBOT_MASTERNAME'] = 'my.master' importer.host.environ['BUILDBOT_BUILDERNAME'] = 'b' importer.host.environ['BUILDBOT_BUILDNUMBER'] = '123' description = importer._cl_description(directory_owners={}) self.assertIn( 'Build: https://build.chromium.org/p/my.master/builders/b/builds/123\n\n', description) self.assertEqual(host.executive.calls, [['git', 'log', '-1', '--format=%B']])
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_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_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_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_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_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_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, } ])
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_should_not_try_to_convert_other_file_types(self): self.assertFalse(TestImporter.should_try_to_convert({}, 'foo.bar', 'LayoutTests/imported/csswg-test/x')) self.assertFalse(TestImporter.should_try_to_convert({}, 'foo.js', 'LayoutTests/imported/csswg-test/x')) self.assertFalse(TestImporter.should_try_to_convert({}, 'foo.md', 'LayoutTests/imported/csswg-test/x')) self.assertFalse(TestImporter.should_try_to_convert({}, 'foo.png', 'LayoutTests/imported/csswg-test/x')) self.assertFalse(TestImporter.should_try_to_convert({}, 'foo.svg', 'LayoutTests/imported/csswg-test/x')) self.assertFalse(TestImporter.should_try_to_convert({}, 'foo.svgz', 'LayoutTests/imported/csswg-test/x'))
def test_import_dir_with_no_tests(self): # FIXME: Use MockHosts instead. host = Host() host.executive = MockExecutive2(exception=ScriptError("abort: no repository found in '/Volumes/Source/src/wk/Tools/Scripts/webkitpy/w3c' (.hg not found)!")) importer = TestImporter(host, None, optparse.Values({"overwrite": False})) importer.source_directory = importer.path_from_webkit_root("Tools", "Scripts", "webkitpy", "w3c") importer.destination_directory = tempfile.mkdtemp(prefix='csswg') oc = OutputCapture() oc.capture_output() try: importer.do_import() finally: oc.restore_output() shutil.rmtree(importer.destination_directory, ignore_errors=True)
def test_import_dir_with_no_tests_and_no_hg(self): # FIXME: Use MockHosts instead. host = Host() host.executive = MockExecutive2(exception=OSError()) importer = TestImporter(host, None, optparse.Values({"overwrite": False})) importer.source_directory = importer.path_from_webkit_root("Tools", "Scripts", "webkitpy", "w3c") importer.destination_directory = tempfile.mkdtemp(prefix='csswg') oc = OutputCapture() oc.capture_output() try: importer.do_import() finally: oc.restore_output() shutil.rmtree(importer.destination_directory, ignore_errors=True)
def test_should_try_to_convert_positive_cases(self): self.assertTrue(TestImporter.should_try_to_convert({}, 'foo.css', 'LayoutTests/imported/csswg-test/x')) self.assertTrue(TestImporter.should_try_to_convert({}, 'foo.htm', 'LayoutTests/imported/csswg-test/x')) self.assertTrue(TestImporter.should_try_to_convert({}, 'foo.html', 'LayoutTests/imported/csswg-test/x')) self.assertTrue(TestImporter.should_try_to_convert({}, 'foo.xht', 'LayoutTests/imported/csswg-test/x')) self.assertTrue(TestImporter.should_try_to_convert({}, 'foo.xhtml', 'LayoutTests/imported/csswg-test/x'))
def test_should_not_try_to_convert_js_test(self): self.assertFalse(TestImporter.should_try_to_convert({'is_jstest': True}, 'foo.html', 'LayoutTests/imported/csswg-test/x'))
def test_should_not_try_to_convert_test_in_wpt(self): self.assertFalse(TestImporter.should_try_to_convert({}, 'foo.html', 'LayoutTests/imported/wpt/foo'))
def test_path_too_long_false(self): importer = TestImporter(MockHost(), FAKE_SOURCE_REPO_DIR, self.options()) self.assertFalse(importer.path_too_long(FAKE_SOURCE_REPO_DIR + '/x.html'))
def test_path_too_long_true(self): importer = TestImporter(MockHost(), FAKE_SOURCE_REPO_DIR, self.options()) self.assertTrue(importer.path_too_long(FAKE_SOURCE_REPO_DIR + '/' + ('x' * 150) + '.html'))