コード例 #1
0
    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'],
        ])
コード例 #2
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)
コード例 #3
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')
コード例 #4
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/']])
コード例 #5
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'))
コード例 #6
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']])
コード例 #7
0
 def test_more_failures_in_baseline_error_to_fail(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'
          '-Harness Error. harness_status.status = 1 , harness_status.message = bad\n'
          '+FAIL a new failure\n')
     })
     self.notifier.git = MockGit(executive=executive)
     self.assertTrue(
         self.notifier.more_failures_in_baseline('foo-expected.txt'))
コード例 #8
0
 def test_more_failures_in_baseline_changing_error(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'
          '-Harness Error. harness_status.status = 1 , harness_status.message = bad\n'
          '+Harness Error. new text, still an error\n')
     })
     self.notifier.git = MockGit(executive=executive)
     self.assertFalse(
         self.notifier.more_failures_in_baseline('foo-expected.txt'))
コード例 #9
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, ''))
コード例 #10
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']])
コード例 #11
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'
                          ]])
コード例 #12
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)