def test_creates_pull_request_for_earliest_commit(self): host = MockHost() def mock_command(args): canned_git_outputs = { 'show': 'newer fake text' if 'cafedad5' in args else 'older fake text', 'rev-list': 'facebeef\ncafedad5', 'footers': 'fake-cr-position', 'remote': 'github', 'format-patch': 'fake patch', 'diff': 'fake patch diff', 'diff-tree': 'fake\n\files\nchanged', } return canned_git_outputs.get(args[1], '') host.executive = MockExecutive(run_command_fn=mock_command) wpt_github = MockWPTGitHub(pull_requests=[]) TestExporter(host, wpt_github).run() self.assertEqual(wpt_github.calls, ['in_flight_pull_requests', 'create_pr']) self.assertEqual( wpt_github.pull_requests_created, [('chromium-export-try', 'older fake text', 'older fake text')])
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_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_creates_pull_request_for_all_exportable_commits(self): test_exporter = TestExporter(self.host) test_exporter.wpt_github = MockWPTGitHub(pull_requests=[], create_pr_fail_index=1) test_exporter.gerrit = MockGerritAPI() test_exporter.get_exportable_commits = lambda: ([ MockChromiumCommit(self.host, position='refs/heads/master@{#1}', change_id='I001', subject='subject 1', body='body 1'), MockChromiumCommit(self.host, position='refs/heads/master@{#2}', change_id='I002', subject='subject 2', body='body 2'), MockChromiumCommit(self.host, position='refs/heads/master@{#3}', change_id='I003', subject='subject 3', body='body 3'), ], []) success = test_exporter.main(['--credentials-json', '/tmp/credentials.json']) self.assertTrue(success) self.assertEqual(test_exporter.wpt_github.calls, [ # 1 'pr_for_chromium_commit', 'create_pr', 'add_label "chromium-export"', # 2 'pr_for_chromium_commit', 'create_pr', 'add_label "chromium-export"', # 3 'pr_for_chromium_commit', 'create_pr', 'add_label "chromium-export"', ]) self.assertEqual(test_exporter.wpt_github.pull_requests_created, [ ('chromium-export-96862edfc1', 'subject 1', 'body 1\n\nChange-Id: I001\n'), ('chromium-export-ce0e78bf18', 'subject 3', 'body 3\n\nChange-Id: I003\n'), ])
def test_gerrit_cl_no_update_if_pr_with_same_revision(self): test_exporter = TestExporter(self.host) test_exporter.wpt_github = MockWPTGitHub(pull_requests=[ PullRequest(title='title1', number=1234, body='description\nWPT-Export-Revision: 1', state='open', labels=[]), ]) test_exporter.get_exportable_commits = lambda: ([], []) test_exporter.gerrit = MockGerritAPI() test_exporter.gerrit.exportable_open_cls = [MockGerritCL( data={ 'change_id': '1', 'subject': 'subject', '_number': 1, 'current_revision': '1', 'has_review_started': True, 'revisions': { '1': {'commit_with_footers': 'a commit with footers'} }, 'owner': {'email': '*****@*****.**'}, }, api=test_exporter.gerrit, chromium_commit=MockChromiumCommit(self.host) )] success = test_exporter.main(['--credentials-json', '/tmp/credentials.json']) self.assertTrue(success) self.assertEqual(test_exporter.wpt_github.calls, [ 'pr_with_change_id', ]) self.assertEqual(test_exporter.wpt_github.pull_requests_created, []) self.assertEqual(test_exporter.wpt_github.pull_requests_merged, [])
def test_does_not_create_pr_if_cl_review_has_not_started(self): test_exporter = TestExporter(self.host) test_exporter.wpt_github = MockWPTGitHub(pull_requests=[]) test_exporter.get_exportable_commits = lambda: ([], []) test_exporter.gerrit = MockGerritAPI() test_exporter.gerrit.exportable_open_cls = [MockGerritCL( data={ 'change_id': '1', 'subject': 'subject', '_number': 1, 'current_revision': '2', 'has_review_started': False, 'revisions': { '1': { 'commit_with_footers': 'a commit with footers 1', 'description': 'subject 1', }, '2': { 'commit_with_footers': 'a commit with footers 2', 'description': 'subject 2', }, }, 'owner': {'email': '*****@*****.**'}, }, api=test_exporter.gerrit, chromium_commit=MockChromiumCommit(self.host) )] success = test_exporter.main(['--credentials-json', '/tmp/credentials.json']) self.assertTrue(success) self.assertEqual(test_exporter.wpt_github.calls, []) self.assertEqual(test_exporter.wpt_github.pull_requests_created, []) self.assertEqual(test_exporter.wpt_github.pull_requests_merged, [])
def test_merges_non_provisional_pr(self): test_exporter = TestExporter(self.host) test_exporter.wpt_github = MockWPTGitHub(pull_requests=[ PullRequest( title='title1', number=1234, body='description\nWPT-Export-Revision: 9\nChange-Id: decafbad', state='open', labels=['']), ]) test_exporter.get_exportable_commits = lambda: ([ MockChromiumCommit(self.host, change_id='decafbad'), ], []) test_exporter.gerrit = MockGerritAPI(self.host, 'gerrit-username', 'gerrit-token') test_exporter.gerrit.query_exportable_open_cls = lambda: [] success = test_exporter.main( ['--credentials-json', '/tmp/credentials.json']) self.assertTrue(success) self.assertEqual(test_exporter.wpt_github.calls, [ 'pr_for_chromium_commit', 'get_pr_branch', 'merge_pull_request', 'delete_remote_branch', ]) self.assertEqual(test_exporter.wpt_github.pull_requests_created, []) self.assertEqual(test_exporter.wpt_github.pull_requests_merged, [1234])
def test_new_gerrit_cl(self): test_exporter = TestExporter(self.host) test_exporter.wpt_github = MockWPTGitHub(pull_requests=[]) test_exporter.get_exportable_commits = lambda: ([], []) test_exporter.gerrit = MockGerritAPI() test_exporter.gerrit.exportable_open_cls = [MockGerritCL( data={ 'change_id': 'I001', 'subject': 'subject', '_number': 1234, 'current_revision': '1', 'has_review_started': True, 'revisions': { '1': {'commit_with_footers': 'a commit with footers'} }, 'owner': {'email': '*****@*****.**'}, }, api=test_exporter.gerrit, chromium_commit=MockChromiumCommit(self.host, subject='subject', body='fake body', change_id='I001') )] test_exporter.main(['--credentials-json', '/tmp/credentials.json']) self.assertEqual(test_exporter.wpt_github.calls, [ 'pr_with_change_id', 'create_pr', 'add_label "chromium-export"', 'add_label "do not merge yet"', ]) self.assertEqual(test_exporter.wpt_github.pull_requests_created, [ ('chromium-export-cl-1234', 'subject', 'fake body\n\nChange-Id: I001\nReviewed-on: https://chromium-review.googlesource.com/1234\nWPT-Export-Revision: 1'), ]) self.assertEqual(test_exporter.wpt_github.pull_requests_merged, [])
def test_attempts_to_merge_landed_gerrit_cl(self): test_exporter = TestExporter(self.host) test_exporter.wpt_github = MockWPTGitHub(pull_requests=[ PullRequest( title='title1', number=1234, body='description\nWPT-Export-Revision: 9\nChange-Id: decafbad', state='open', labels=['do not merge yet']), ]) test_exporter.get_exportable_commits = lambda: ([ MockChromiumCommit(self.host, change_id='decafbad'), ], []) test_exporter.gerrit = MockGerritAPI() success = test_exporter.main( ['--credentials-json', '/tmp/credentials.json']) self.assertTrue(success) self.assertEqual(test_exporter.wpt_github.calls, [ 'pr_for_chromium_commit', 'get_pr_branch', 'update_pr', 'remove_label "do not merge yet"', ]) self.assertEqual(test_exporter.wpt_github.pull_requests_created, []) self.assertEqual(test_exporter.wpt_github.pull_requests_merged, [])
def test_dry_run_stops_before_creating_pr(self): self.host.executive = mock_git_commands({ 'crrev-parse': 'c2087acb00eee7960339a0be34ea27d6b20e1131', }) test_exporter = TestExporter(self.host) test_exporter.wpt_github = MockWPTGitHub(pull_requests=[ PullRequest( title='title1', number=1234, body='', state='open', labels=[]), ]) test_exporter.gerrit = MockGerritAPI(self.host, 'gerrit-username', 'gerrit-token') test_exporter.get_exportable_commits = lambda: ([ ChromiumCommit(self.host, position='refs/heads/master@{#458475}'), ChromiumCommit(self.host, position='refs/heads/master@{#458476}'), ChromiumCommit(self.host, position='refs/heads/master@{#458477}'), ], []) success = test_exporter.main( ['--credentials-json', '/tmp/credentials.json', '--dry-run']) self.assertTrue(success) self.assertEqual(test_exporter.wpt_github.calls, [ 'pr_for_chromium_commit', 'pr_for_chromium_commit', 'pr_for_chromium_commit', ])
def test_exportable_commits_since_not_require_clean(self): host = MockHost() host.executive = mock_git_commands({ 'diff-tree': 'third_party/WebKit/LayoutTests/external/wpt/some_files', 'footers': 'cr-rev-position', 'format-patch': 'hey I\'m a patch', 'rev-list': 'add087a97844f4b9e307d9a216940582d96db306\n' 'add087a97844f4b9e307d9a216940582d96db307\n' 'add087a97844f4b9e307d9a216940582d96db308\n' }) local_wpt = MockLocalWPT(test_patch=[ (True, ''), (False, 'patch failure'), (True, ''), ]) commits, _ = _exportable_commits_since('beefcafe', host, local_wpt, MockWPTGitHub(pull_requests=[]), require_clean=False) self.assertEqual(len(commits), 3)
def test_commit_that_produces_errors(self): commit = MockChromiumCommit(MockHost()) github = MockWPTGitHub(pull_requests=[]) self.assertEqual( get_commit_export_state( commit, MockLocalWPT(test_patch=[(False, 'error')]), github), (CommitExportState.EXPORTABLE_DIRTY, 'error'))
def test_commit_with_noexport_is_not_exportable(self): # Patch is not tested if the commit is ignored based on the message, hence empty MockLocalWPT. commit = MockChromiumCommit(MockHost(), body='Message\nNo-Export: true') github = MockWPTGitHub(pull_requests=[]) self.assertEqual( get_commit_export_state(commit, MockLocalWPT(), github), (CommitExportState.IGNORED, '')) # The older NOEXPORT tag also makes it non-exportable. old_commit = MockChromiumCommit(MockHost(), body='Message\nNOEXPORT=true') self.assertEqual( get_commit_export_state(old_commit, MockLocalWPT(), github), (CommitExportState.IGNORED, '')) # No-Export/NOEXPORT in a revert CL also makes it non-exportable. revert = MockChromiumCommit( MockHost(), body='Revert of Message\n> No-Export: true') self.assertEqual( get_commit_export_state(revert, MockLocalWPT(), github), (CommitExportState.IGNORED, '')) old_revert = MockChromiumCommit( MockHost(), body='Revert of Message\n> NOEXPORT=true') self.assertEqual( get_commit_export_state(old_revert, MockLocalWPT(), github), (CommitExportState.IGNORED, ''))
def test_attempts_to_merge_landed_gerrit_cl(self): host = MockHost() host.executive = mock_git_commands({ 'footers': 'decafbad', }) test_exporter = TestExporter(host, 'gh-username', 'gh-token', gerrit_user=None, gerrit_token=None, dry_run=False) test_exporter.wpt_github = MockWPTGitHub(pull_requests=[ PullRequest( title='title1', number=1234, body='description\nWPT-Export-Revision: 9\nChange-Id: decafbad', state='open'), ]) test_exporter.get_exportable_commits = lambda limit: [ ChromiumCommit(host, sha='c881563d734a86f7d9cd57ac509653a61c45c240'), ] test_exporter.gerrit = MockGerritAPI(host, 'gerrit-username', 'gerrit-token') test_exporter.gerrit.query_exportable_open_cls = lambda: [] test_exporter.run() self.assertEqual(test_exporter.wpt_github.calls, [ 'pr_with_position', 'get_pr_branch', 'merge_pull_request', 'delete_remote_branch', ]) self.assertEqual(test_exporter.wpt_github.pull_requests_created, []) self.assertEqual(test_exporter.wpt_github.pull_requests_merged, [1234])
def test_dry_run_stops_before_creating_pr(self): host = MockHost() host.executive = mock_git_commands({ 'crrev-parse': 'c2087acb00eee7960339a0be34ea27d6b20e1131', }) test_exporter = TestExporter(host, 'gh-username', 'gh-token', gerrit_user=None, gerrit_token=None, dry_run=True) test_exporter.wpt_github = MockWPTGitHub(pull_requests=[ PullRequest(title='title1', number=1234, body='', state='open'), ]) test_exporter.gerrit = MockGerritAPI(host, 'gerrit-username', 'gerrit-token') test_exporter.get_exportable_commits = lambda limit: [ ChromiumCommit(host, position='refs/heads/master@{#458475}'), ChromiumCommit(host, position='refs/heads/master@{#458476}'), ChromiumCommit(host, position='refs/heads/master@{#458477}'), ] test_exporter.run() self.assertEqual(test_exporter.wpt_github.calls, [ 'pr_with_position', 'pr_with_position', 'pr_with_position', ])
def test_ignores_commits_that_start_with_import(self): self.host.executive = mock_command_exec({ 'show': 'Import rutabaga@deadbeef', 'rev-list': 'badbeef8', 'rev-parse': 'badbeef8', 'footers': 'cr-rev-position', }) wpt_github = MockWPTGitHub(pull_requests=[]) test_exporter = TestExporter(self.host, wpt_github) commits = test_exporter.exportable_commits_since('beefcafe') self.assertEqual(len(commits), 0) self.assertEqual( self.host.executive.calls, [[ 'git', 'clone', 'https://chromium.googlesource.com/external/w3c/web-platform-tests.git', '/tmp/wpt' ], ['git', 'remote'], [ 'git', 'remote', 'add', 'github', '[email protected]:w3c/web-platform-tests.git' ], ['git', 'rev-parse', '--show-toplevel'], [ 'git', 'rev-list', 'beefcafe..HEAD', '--reverse', '--', 'badbeef8/third_party/WebKit/LayoutTests/external/wpt/' ], [ 'git', 'diff-tree', '--name-only', '--no-commit-id', '-r', 'badbeef8', '--', '/mock-checkout/third_party/WebKit/LayoutTests/external/wpt' ]])
def test_exportable_commits_since(self): host = MockHost() host.executive = mock_git_commands({ 'show': 'fake message', 'rev-list': 'add087a97844f4b9e307d9a216940582d96db306', 'rev-parse': 'add087a97844f4b9e307d9a216940582d96db306', 'crrev-parse': 'add087a97844f4b9e307d9a216940582d96db306', 'diff': 'fake diff', 'diff-tree': 'third_party/WebKit/LayoutTests/external/wpt/some\n' 'third_party/WebKit/LayoutTests/external/wpt/files', 'format-patch': 'hey I\'m a patch', 'footers': 'cr-rev-position', }, strict=True) commits, _ = _exportable_commits_since( 'beefcafe', host, MockLocalWPT(), MockWPTGitHub(pull_requests=[])) self.assertEqual(len(commits), 1) self.assertIsInstance(commits[0], ChromiumCommit) self.assertEqual(host.executive.calls, [ ['git', 'rev-parse', '--show-toplevel'], ['git', 'rev-list', 'beefcafe..HEAD', '--reverse', '--', 'add087a97844f4b9e307d9a216940582d96db306/third_party/WebKit/LayoutTests/external/wpt/'], ['git', 'footers', '--position', 'add087a97844f4b9e307d9a216940582d96db306'], ['git', 'show', '--format=%B', '--no-patch', 'add087a97844f4b9e307d9a216940582d96db306'], ['git', 'diff-tree', '--name-only', '--no-commit-id', '-r', 'add087a97844f4b9e307d9a216940582d96db306', '--', '/mock-checkout/third_party/WebKit/LayoutTests/external/wpt'], ['git', 'format-patch', '-1', '--stdout', 'add087a97844f4b9e307d9a216940582d96db306', '--', 'third_party/WebKit/LayoutTests/external/wpt/some', 'third_party/WebKit/LayoutTests/external/wpt/files'], ])
def test_dry_run_stops_before_creating_pr(self): host = MockHost() host.executive = MockExecutive(output='beefcafe') wpt_github = MockWPTGitHub(pull_requests=[{'number': 1, 'title': 'abc'}]) TestExporter(host, wpt_github, dry_run=True).run() self.assertEqual(wpt_github.calls, ['in_flight_pull_requests'])
def test_stops_if_more_than_one_pr_is_in_flight(self): host = MockHost() wpt_github = MockWPTGitHub(pull_requests=[{'id': 1}, {'id': 2}]) # TODO: make Exception more specific with self.assertRaises(Exception): TestExporter(host, wpt_github).run()
def test_does_not_create_pr_if_cl_review_has_not_started(self): host = MockHost() test_exporter = TestExporter(host, 'gh-username', 'gh-token', gerrit_user=None, gerrit_token=None, dry_run=False) test_exporter.wpt_github = MockWPTGitHub(pull_requests=[]) test_exporter.get_exportable_commits = lambda: [] test_exporter.gerrit = MockGerritAPI(host, 'gerrit-username', 'gerrit-token') test_exporter.gerrit.get = lambda path, raw: base64.b64encode('sample diff') # pylint: disable=unused-argument test_exporter.gerrit.query_exportable_open_cls = lambda: [ GerritCL(data={ 'change_id': '1', 'subject': 'subject', '_number': '1', 'current_revision': '2', 'has_review_started': False, 'revisions': { '1': { 'commit_with_footers': 'a commit with footers 1', 'description': 'subject 1', }, '2': { 'commit_with_footers': 'a commit with footers 2', 'description': 'subject 2', }, }, 'owner': {'email': '*****@*****.**'}, }, api=test_exporter.gerrit), ] test_exporter.run() self.assertEqual(test_exporter.wpt_github.calls, []) self.assertEqual(test_exporter.wpt_github.pull_requests_created, [])
def test_commit_that_has_closed_pr_is_not_exportable(self): commit = MockChromiumCommit(MockHost(), change_id='I00decade') github = MockWPTGitHub(pull_requests=[ PullRequest('PR1', 1, 'body\nChange-Id: I00c0ffee', 'closed', []), PullRequest('PR2', 2, 'body\nChange-Id: I00decade', 'closed', []), ]) self.assertEqual(get_commit_export_state(commit, MockLocalWPT(), github), (CommitExportState.EXPORTED, ''))
def test_attempts_to_merge_landed_gerrit_cl(self): host = MockHost() def mock_command(args): if args[1] != 'footers': return '' if args[2] == '--key': return 'decafbad\n' elif args[2] == '--position': return 'refs/heads/master@{#475994}' host.executive = MockExecutive(run_command_fn=mock_command) test_exporter = TestExporter(host, 'gh-username', 'gh-token', gerrit_user=None, gerrit_token=None, dry_run=False) test_exporter.wpt_github = MockWPTGitHub(pull_requests=[ PullRequest(title='title1', number=1234, body='description\nWPT-Export-Revision: 9\nChange-Id: decafbad', state='open', labels=['do not merge yet']), ]) test_exporter.get_exportable_commits = lambda: [ ChromiumCommit(host, sha='c881563d734a86f7d9cd57ac509653a61c45c240'), ] test_exporter.gerrit = MockGerritAPI(host, 'gerrit-username', 'gerrit-token') test_exporter.gerrit.query_exportable_open_cls = lambda: [] test_exporter.run() self.assertEqual(test_exporter.wpt_github.calls, [ 'pr_for_chromium_commit', 'remove_label "do not merge yet"', 'get_pr_branch', 'merge_pull_request', 'delete_remote_branch', ]) self.assertEqual(test_exporter.wpt_github.pull_requests_created, []) self.assertEqual(test_exporter.wpt_github.pull_requests_merged, [1234])
def test_gerrit_cl_no_update_if_pr_with_same_revision(self): host = MockHost() test_exporter = TestExporter(host, 'gh-username', 'gh-token', gerrit_user=None, gerrit_token=None, dry_run=False) test_exporter.wpt_github = MockWPTGitHub(pull_requests=[ PullRequest(title='title1', number=1234, body='description\nWPT-Export-Revision: 1', state='open', labels=[]), ]) test_exporter.get_exportable_commits = lambda: [] test_exporter.gerrit = MockGerritAPI(host, 'gerrit-username', 'gerrit-token') test_exporter.gerrit.query_exportable_open_cls = lambda: [ GerritCL(data={ 'change_id': '1', 'subject': 'subject', '_number': '1', 'current_revision': '1', 'has_review_started': True, 'revisions': { '1': {'commit_with_footers': 'a commit with footers'} }, 'owner': {'email': '*****@*****.**'}, }, api=test_exporter.gerrit), ] test_exporter.run() self.assertEqual(test_exporter.wpt_github.calls, [ 'pr_with_change_id', ]) self.assertEqual(test_exporter.wpt_github.pull_requests_created, [])
def test_new_gerrit_cl(self): host = MockHost() test_exporter = TestExporter(host, 'gh-username', 'gh-token', gerrit_user=None, gerrit_token=None, dry_run=False) test_exporter.wpt_github = MockWPTGitHub(pull_requests=[]) test_exporter.get_exportable_commits = lambda: [] test_exporter.gerrit = MockGerritAPI(host, 'gerrit-username', 'gerrit-token') test_exporter.gerrit.get = lambda path, raw: base64.b64encode('sample diff') # pylint: disable=unused-argument test_exporter.gerrit.query_exportable_open_cls = lambda: [ GerritCL(data={ 'change_id': '1', 'subject': 'subject', '_number': '1', 'current_revision': '1', 'has_review_started': True, 'revisions': { '1': {'commit_with_footers': 'a commit with footers'} }, 'owner': {'email': '*****@*****.**'}, }, api=test_exporter.gerrit), ] test_exporter.run() self.assertEqual(test_exporter.wpt_github.calls, [ 'pr_with_change_id', 'create_pr', 'add_label "chromium-export"', 'add_label "do not merge yet"', ]) self.assertEqual(test_exporter.wpt_github.pull_requests_created, [ ('chromium-export-cl-1', 'subject', 'a commit with footers\nWPT-Export-Revision: 1'), ])
def test_creates_pull_request_for_earliest_commit(self): host = MockHost() def mock_command(args): canned_git_outputs = { 'show': 'newer fake text' if 'add087a97844f4b9e307d9a216940582d96db306' in args else 'older fake text', 'rev-list': 'c881563d734a86f7d9cd57ac509653a61c45c240\nadd087a97844f4b9e307d9a216940582d96db306', 'footers': 'fake-cr-position', 'remote': 'github', 'format-patch': 'fake patch', 'diff': 'fake patch diff', 'diff-tree': 'fake\n\files\nchanged', 'crrev-parse': 'c881563d734a86f7d9cd57ac509653a61c45c240', } return canned_git_outputs.get(args[1], '') host.executive = MockExecutive(run_command_fn=mock_command) test_exporter = TestExporter(host, 'gh-username', 'gh-token') test_exporter.wpt_github = MockWPTGitHub(pull_requests=[]) test_exporter.run() self.assertEqual(test_exporter.wpt_github.calls, ['in_flight_pull_requests', 'create_pr']) self.assertEqual( test_exporter.wpt_github.pull_requests_created, [('chromium-export-try', 'older fake text', 'older fake text')])
def test_merge_failure_errors_out(self): host = MockHost() wpt_github = MockWPTGitHub(pull_requests=[{'number': 1, 'title': 'abc'}], unsuccessful_merge=True) # TODO: make Exception more specific with self.assertRaises(Exception): TestExporter(host, wpt_github).run()
def test_get_commit_export_state(self): commit = MockChromiumCommit(MockHost()) github = MockWPTGitHub(pull_requests=[]) self.assertEqual( get_commit_export_state(commit, MockLocalWPT(test_patch=[(True, '')]), github), (CommitExportState.EXPORTABLE_CLEAN, ''))
def test_if_pr_exists_merges_it(self): host = MockHost() wpt_github = MockWPTGitHub(pull_requests=[{ 'number': 1, 'title': 'abc' }]) TestExporter(host, wpt_github).run() self.assertIn('merge_pull_request', wpt_github.calls)
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_if_pr_exists_merges_it(self): host = MockHost() test_exporter = TestExporter(host, 'gh-username', 'gh-token') test_exporter.wpt_github = MockWPTGitHub(pull_requests=[{ 'number': 1, 'title': 'abc' }]) test_exporter.run() self.assertIn('merge_pull_request', test_exporter.wpt_github.calls)