コード例 #1
0
    def test_fetch_current_revision_commit(self):
        host = MockHost()
        host.executive = mock_git_commands({
            'fetch': '',
            'rev-parse': '4de71d0ce799af441c1f106c5432c7fa7256be45',
            'footers': 'no-commit-position-yet'
        }, strict=True)
        data = {
            'change_id': 'Ib58c7125d85d2fd71af711ea8bbd2dc927ed02cb',
            'subject': 'fake subject',
            '_number': 638250,
            'current_revision': '1',
            'revisions': {'1': {
                'fetch': {'http': {
                    'url': 'https://chromium.googlesource.com/chromium/src',
                    'ref': 'refs/changes/50/638250/1'
                }}
            }},
            'owner': {'email': '*****@*****.**'},
        }
        gerrit_cl = GerritCL(data, MockGerritAPI())
        commit = gerrit_cl.fetch_current_revision_commit(host)

        self.assertEqual(commit.sha, '4de71d0ce799af441c1f106c5432c7fa7256be45')
        self.assertEqual(host.executive.calls, [
            ['git', 'fetch', 'https://chromium.googlesource.com/chromium/src', 'refs/changes/50/638250/1'],
            ['git', 'rev-parse', 'FETCH_HEAD'],
            ['git', 'footers', '--position', '4de71d0ce799af441c1f106c5432c7fa7256be45']
        ])
コード例 #2
0
ファイル: common_unittest.py プロジェクト: wzh220144/chromium
    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': 'some\nfiles',
            'format-patch': 'hey I\'m a patch',
            'footers': 'cr-rev-position',
        })

        commits = exportable_commits_since('beefcafe', host, MockLocalWPT())
        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', 'diff-tree', '--name-only', '--no-commit-id', '-r', 'add087a97844f4b9e307d9a216940582d96db306', '--',
             '/mock-checkout/third_party/WebKit/LayoutTests/external/wpt'],
            ['git', 'format-patch', '-1', '--stdout', 'add087a97844f4b9e307d9a216940582d96db306', '--', 'some', 'files'],
            ['git', 'show', '--format=%B', '--no-patch', 'add087a97844f4b9e307d9a216940582d96db306'],
            ['git', 'show', '--format=%B', '--no-patch', 'add087a97844f4b9e307d9a216940582d96db306']
        ])
コード例 #3
0
    def test_ignores_commits_that_start_with_import(self):
        host = MockHost()
        host.executive = mock_git_commands({
            'show': 'Import rutabaga@deadbeef',
            'rev-list': 'add087a97844f4b9e307d9a216940582d96db306',
            'rev-parse': 'add087a97844f4b9e307d9a216940582d96db306',
            'footers': 'cr-rev-position',
        })

        commits = exportable_commits_since('beefcafe', host, MockLocalWPT())
        self.assertEqual(commits, [])
        self.assertEqual(host.executive.calls, [
            ['git', 'rev-parse', '--show-toplevel'],
            [
                'git', 'rev-list', 'beefcafe..HEAD', '--reverse', '--',
                'add087a97844f4b9e307d9a216940582d96db306/third_party/WebKit/LayoutTests/external/wpt/'
            ],
            [
                'git', 'diff-tree', '--name-only', '--no-commit-id', '-r',
                'add087a97844f4b9e307d9a216940582d96db306', '--',
                '/mock-checkout/third_party/WebKit/LayoutTests/external/wpt'
            ],
            [
                'git', 'show', '--format=%B', '--no-patch',
                'add087a97844f4b9e307d9a216940582d96db306'
            ],
            [
                'git', 'show', '--format=%B', '--no-patch',
                'add087a97844f4b9e307d9a216940582d96db306'
            ],
        ])
コード例 #4
0
    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])
コード例 #5
0
    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)
コード例 #6
0
    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',
        ])
コード例 #7
0
    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',
        ])
コード例 #8
0
    def test_ignores_reverted_commits_with_noexport_true(self):
        host = MockHost()
        host.executive = mock_git_commands(
            {
                'show': 'Commit message\n> NOEXPORT=true',
                'rev-list': 'add087a97844f4b9e307d9a216940582d96db306',
                'rev-parse': 'add087a97844f4b9e307d9a216940582d96db306',
                'footers': 'cr-rev-position',
                'diff-tree': '',
            },
            strict=True)

        commits = exportable_commits_since(
            'add087a97844f4b9e307d9a216940582d96db306', host, MockLocalWPT())
        self.assertEqual(len(commits), 0)
        self.assertEqual(host.executive.calls, [
            ['git', 'rev-parse', '--show-toplevel'],
            [
                'git', 'rev-list',
                'add087a97844f4b9e307d9a216940582d96db306..HEAD', '--reverse',
                '--',
                'add087a97844f4b9e307d9a216940582d96db306/third_party/WebKit/LayoutTests/external/wpt/'
            ],
            [
                'git', 'diff-tree', '--name-only', '--no-commit-id', '-r',
                'add087a97844f4b9e307d9a216940582d96db306', '--',
                '/mock-checkout/third_party/WebKit/LayoutTests/external/wpt'
            ],
            [
                'git', 'show', '--format=%B', '--no-patch',
                'add087a97844f4b9e307d9a216940582d96db306'
            ]
        ])
コード例 #9
0
    def test_derives_position_from_sha(self):
        host = MockHost()
        host.executive = mock_git_commands({
            'footers': 'refs/heads/master@{#789}'
        })
        chromium_commit = ChromiumCommit(host, sha='c881563d734a86f7d9cd57ac509653a61c45c240')

        self.assertEqual(chromium_commit.position, 'refs/heads/master@{#789}')
        self.assertEqual(chromium_commit.sha, 'c881563d734a86f7d9cd57ac509653a61c45c240')
コード例 #10
0
 def test_more_failures_in_baseline_same_fails(self):
     executive = mock_git_commands({
         'diff': ('diff --git a/foo-expected.txt b/foo-expected.txt\n'
                  '--- a/foo-expected.txt\n'
                  '+++ b/foo-expected.txt\n'
                  '-FAIL an old failure\n'
                  '+FAIL a new failure\n')
     })
     self.notifier.git = MockGit(executive=executive)
     self.assertFalse(
         self.notifier.more_failures_in_baseline('foo-expected.txt'))
コード例 #11
0
    def test_test_patch_empty_diff(self):
        host = MockHost()
        host.executive = mock_git_commands({
            'apply': '',
            'add': '',
            'diff': '',
            'reset': '',
            'clean': '',
            'checkout': '',
        }, strict=True)
        local_wpt = LocalWPT(host, 'token')

        self.assertEqual(local_wpt.test_patch('dummy patch'), (False, ''))
コード例 #12
0
    def test_is_commit_affecting_directory(self):
        host = MockHost()
        # return_exit_code=True is passed to run() in the method under test,
        # so the mock return value should be exit code instead of output.
        host.executive = mock_git_commands({'diff-tree': 1}, strict=True)
        local_wpt = LocalWPT(host, 'token')

        self.assertTrue(local_wpt.is_commit_affecting_directory(
            'HEAD', 'css/'))
        self.assertEqual(host.executive.calls, [[
            'git', 'diff-tree', '--quiet', '--no-commit-id', 'HEAD', '--',
            'css/'
        ]])
コード例 #13
0
    def test_last_wpt_exported_commit(self):
        host = MockHost()
        host.executive = mock_git_commands({
            'rev-list': '9ea4fc353a4b1c11c6e524270b11baa4d1ddfde8',
            'footers': 'Cr-Commit-Position: 123',
            'crrev-parse': 'add087a97844f4b9e307d9a216940582d96db306',
        }, strict=True)
        host.filesystem = MockFileSystem()
        local_wpt = LocalWPT(host, 'token')

        wpt_sha, chromium_commit = local_wpt.most_recent_chromium_commit()
        self.assertEqual(wpt_sha, '9ea4fc353a4b1c11c6e524270b11baa4d1ddfde8')
        self.assertEqual(chromium_commit.position, '123')
        self.assertEqual(chromium_commit.sha, 'add087a97844f4b9e307d9a216940582d96db306')
コード例 #14
0
    def test_commits_in_range(self):
        host = MockHost()
        host.executive = mock_git_commands(
            {
                'rev-list':
                '34ab6c3f5aee8bf05207b674edbcb6affb179545 Fix presubmit errors\n'
                '8c596b820634a623dfd7a2b0f36007ce2f7a0c9f test\n'
            },
            strict=True)
        local_wpt = LocalWPT(host, 'token')

        self.assertTrue(local_wpt.commits_in_range('HEAD~2', 'HEAD'))
        self.assertEqual(
            host.executive.calls,
            [['git', 'rev-list', '--pretty=oneline', 'HEAD~2..HEAD']])
コード例 #15
0
 def test_more_failures_in_baseline_more_fails(self):
     # Replacing self.host.executive won't work here, because ImportNotifier
     # has been instantiated with a MockGit backed by an empty MockExecutive.
     executive = mock_git_commands({
         'diff': ('diff --git a/foo-expected.txt b/foo-expected.txt\n'
                  '--- a/foo-expected.txt\n'
                  '+++ b/foo-expected.txt\n'
                  '-FAIL an old failure\n'
                  '+FAIL new failure 1\n'
                  '+FAIL new failure 2\n')
     })
     self.notifier.git = MockGit(executive=executive)
     self.assertTrue(
         self.notifier.more_failures_in_baseline('foo-expected.txt'))
     self.assertEqual(
         executive.calls,
         [['git', 'diff', '-U0', 'origin/master', '--', 'foo-expected.txt']
          ])
コード例 #16
0
    def test_filtered_changed_files_blacklist(self):
        host = MockHost()

        fake_files = ['file1', 'MANIFEST.json', 'file3', 'OWNERS']
        qualified_fake_files = [CHROMIUM_WPT_DIR + f for f in fake_files]

        host.executive = mock_git_commands({
            'diff-tree': '\n'.join(qualified_fake_files),
            'crrev-parse': 'c881563d734a86f7d9cd57ac509653a61c45c240',
        })

        position_footer = 'Cr-Commit-Position: refs/heads/master@{#789}'
        chromium_commit = ChromiumCommit(host, position=position_footer)

        files = chromium_commit.filtered_changed_files()

        expected_files = ['file1', 'file3']
        qualified_expected_files = [CHROMIUM_WPT_DIR + f for f in expected_files]

        self.assertEqual(files, qualified_expected_files)
コード例 #17
0
 def test_creates_and_merges_pull_requests(self):
     # This tests 4 exportable commits:
     # 1. #458475 has an in-flight PR associated with it but cannot be merged.
     # 2. #458476 has no PR associated with it and should have one created.
     # 3. #458477 has a closed PR associated with it and should be skipped.
     # 4. #458478 has an in-flight PR associated with it and should be merged successfully.
     host = MockHost()
     host.executive = mock_git_commands({
         'show':
         'git show text\nCr-Commit-Position: refs/heads/master@{#458476}',
         'crrev-parse':
         'c2087acb00eee7960339a0be34ea27d6b20e1131',
     })
     test_exporter = TestExporter(host,
                                  'gh-username',
                                  'gh-token',
                                  gerrit_user=None,
                                  gerrit_token=None)
     test_exporter.wpt_github = MockWPTGitHub(pull_requests=[
         PullRequest(
             title='Open PR',
             number=1234,
             body=
             'rutabaga\nCr-Commit-Position: refs/heads/master@{#458475}',
             state='open'),
         PullRequest(
             title='Merged PR',
             number=2345,
             body=
             'rutabaga\nCr-Commit-Position: refs/heads/master@{#458477}',
             state='closed'),
         PullRequest(
             title='Open PR',
             number=3456,
             body=
             'rutabaga\nCr-Commit-Position: refs/heads/master@{#458478}',
             state='open'),
     ],
                                              unsuccessful_merge_index=0)
     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}'),
         ChromiumCommit(host, position='refs/heads/master@{#458478}'),
     ]
     test_exporter.run()
     self.assertEqual(test_exporter.wpt_github.calls, [
         'pr_with_position',
         'get_pr_branch',
         'merge_pull_request',
         'pr_with_position',
         'create_pr',
         'add_label',
         'pr_with_position',
         'pr_with_position',
         'get_pr_branch',
         'merge_pull_request',
         'delete_remote_branch',
     ])
     self.assertEqual(test_exporter.wpt_github.pull_requests_created, [
         ('chromium-export-c2087acb00',
          'git show text\nCr-Commit-Position: refs/heads/master@{#458476}',
          'git show text\nCr-Commit-Position: refs/heads/master@{#458476}'),
     ])
コード例 #18
0
    def test_creates_and_merges_pull_requests(self):
        # This tests 4 exportable commits:
        # 1. #458475 has an in-flight PR associated with it but cannot be merged.
        # 2. #458476 has no PR associated with it and should have one created.
        # 3. #458477 has a closed PR associated with it and should be skipped.
        # 4. #458478 has an in-flight PR associated with it and should be merged successfully.
        host = MockHost()
        host.executive = mock_git_commands({
            'show': 'git show text\nCr-Commit-Position: refs/heads/master@{#458476}\nChange-Id: I0476',
            'crrev-parse': 'c2087acb00eee7960339a0be34ea27d6b20e1131',

        })
        test_exporter = TestExporter(host, 'gh-username', 'gh-token', gerrit_user=None, gerrit_token=None)
        test_exporter.wpt_github = MockWPTGitHub(pull_requests=[
            PullRequest(
                title='Open PR',
                number=1234,
                body='rutabaga\nCr-Commit-Position: refs/heads/master@{#458475}\nChange-Id: I0005',
                state='open',
                labels=['do not merge yet']
            ),
            PullRequest(
                title='Merged PR',
                number=2345,
                body='rutabaga\nCr-Commit-Position: refs/heads/master@{#458477}\nChange-Id: Idead',
                state='closed',
                labels=[]
            ),
            PullRequest(
                title='Open PR',
                number=3456,
                body='rutabaga\nCr-Commit-Position: refs/heads/master@{#458478}\nChange-Id: I0118',
                state='open',
                labels=[]  # It's important that this is empty.
            ),
        ], unsuccessful_merge_index=0)
        test_exporter.gerrit = MockGerritAPI(host, 'gerrit-username', 'gerrit-token')
        test_exporter.get_exportable_commits = lambda: [
            MockChromiumCommit(host, position='refs/heads/master@{#458475}', change_id='I0005'),
            MockChromiumCommit(host, position='refs/heads/master@{#458476}', change_id='I0476'),
            MockChromiumCommit(host, position='refs/heads/master@{#458477}', change_id='Idead'),
            MockChromiumCommit(host, position='refs/heads/master@{#458478}', change_id='I0118'),
        ]
        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',
            'pr_for_chromium_commit',
            'create_pr',
            'add_label "chromium-export"',
            'pr_for_chromium_commit',
            'pr_for_chromium_commit',
            # Testing the lack of remove_label here. The exporter should not
            # try to remove the provisional label from PRs it has already
            # removed it from.
            'get_pr_branch',
            'merge_pull_request',
            'delete_remote_branch',
        ])
        self.assertEqual(test_exporter.wpt_github.pull_requests_created, [
            ('chromium-export-52c3178508', 'Fake subject', 'Fake body\n\nChange-Id: I0476'),
        ])