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_commit_that_has_merged_pr_and_found_locally(self): commit = MockChromiumCommit(MockHost(), change_id='I00decade') github = MockWPTGitHub(pull_requests=[ PullRequest('PR2', 2, 'body\nChange-Id: I00decade', 'closed', []), ], merged_index=0) self.assertEqual(get_commit_export_state(commit, MockLocalWPT(change_ids=['I00decade']), github, verify_merged_pr=False), (CommitExportState.EXPORTED, '')) self.assertEqual(get_commit_export_state(commit, MockLocalWPT(change_ids=['I00decade']), github, verify_merged_pr=True), (CommitExportState.EXPORTED, ''))
def test_commit_that_has_merged_pr_but_not_found_locally(self): commit = MockChromiumCommit(MockHost(), change_id='I00decade') github = MockWPTGitHub(pull_requests=[ PullRequest('PR2', 2, 'body\nChange-Id: I00decade', 'closed', []), ], merged_index=0) # verify_merged_pr should be False by default. self.assertEqual(get_commit_export_state(commit, MockLocalWPT(), github), (CommitExportState.EXPORTED, '')) self.assertEqual(get_commit_export_state(commit, MockLocalWPT(test_patch=[(True, '')]), github, verify_merged_pr=True), (CommitExportState.EXPORTABLE_CLEAN, ''))
def test_commit_that_has_closed_but_not_merged_pr(self): commit = MockChromiumCommit(MockHost(), change_id='I00decade') github = MockWPTGitHub(pull_requests=[ PullRequest('PR2', 2, 'body\nChange-Id: I00decade', 'closed', []), ]) # Regardless of verify_merged_pr, abandoned PRs are always exported. self.assertEqual(get_commit_export_state(commit, MockLocalWPT(), github, verify_merged_pr=False), (CommitExportState.EXPORTED, '')) self.assertEqual(get_commit_export_state(commit, MockLocalWPT(), github, verify_merged_pr=True), (CommitExportState.EXPORTED, ''))
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_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(test_patch=[(True, '')]), 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_commit_that_has_open_pr_is_exportable(self): commit = MockChromiumCommit(MockHost(), change_id='I00decade') github = MockWPTGitHub(pull_requests=[ PullRequest('PR2', 2, 'body\nChange-Id: I00decade', 'open', []), ]) self.assertEqual(get_commit_export_state(commit, MockLocalWPT(test_patch=[(True, '')]), github), (CommitExportState.EXPORTABLE_CLEAN, ''))
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_commit_that_starts_with_import_is_exportable(self): commit = MockChromiumCommit(MockHost(), subject='Import message') github = MockWPTGitHub(pull_requests=[]) self.assertEqual( get_commit_export_state(commit, MockLocalWPT(test_patch=[(True, '')]), github), (CommitExportState.EXPORTABLE_CLEAN, ''))
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 setUp(self): self.host = MockHost() # Mock a virtual test suite at virtual/gpu/external/wpt/foo. self.host.filesystem = MockFileSystem({ MOCK_WEB_TESTS + 'VirtualTestSuites': '[{"prefix": "gpu", "bases": ["external/wpt/foo"], "args": ["--foo"]}]' }) self.git = self.host.git() self.local_wpt = MockLocalWPT() self.notifier = ImportNotifier(self.host, self.git, self.local_wpt)
def setUp(self): self.host = MockHost() # Mock a virtual test suite at virtual/gpu/external/wpt/foo. self.host.filesystem = MockFileSystem({ '/mock-checkout/third_party/WebKit/LayoutTests/VirtualTestSuites': '[{"prefix": "gpu", "base": "external/wpt/foo", "args": ["--foo"]}]' }) self.git = self.host.git() self.local_wpt = MockLocalWPT() self.notifier = ImportNotifier(self.host, self.git, self.local_wpt)
def test_commit_with_noexport_is_not_exportable_mixed_casing(self): # Patch is not tested if the commit is ignored based on the message, hence empty MockLocalWPT. # Make sure that the casing of the "No export" message isn't considered. commit = MockChromiumCommit(MockHost(), body='Message\nno-EXPORT: true') github = MockWPTGitHub(pull_requests=[]) self.assertEqual( get_commit_export_state(commit, MockLocalWPT(), github), (CommitExportState.IGNORED, '')) commit = MockChromiumCommit(MockHost(), body='Message\nnoexport=TRUE') github = MockWPTGitHub(pull_requests=[]) self.assertEqual( get_commit_export_state(commit, MockLocalWPT(), github), (CommitExportState.IGNORED, '')) commit = MockChromiumCommit(MockHost(), body='Message\nNO-exPORT: trUE') github = MockWPTGitHub(pull_requests=[]) self.assertEqual( get_commit_export_state(commit, MockLocalWPT(), github), (CommitExportState.IGNORED, ''))
def test_commit_that_starts_with_import_is_not_exportable(self): commit = MockChromiumCommit(MockHost(), subject='Import message') github = MockWPTGitHub(pull_requests=[]) self.assertEqual( get_commit_export_state(commit, MockLocalWPT(), github), (CommitExportState.IGNORED, ''))