Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(64)

Side by Side Diff: tests/git_hyper_blame_test.py

Issue 1697423004: git hyper-blame: Added automatically ignoring revs from a file. (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/depot_tools.git@master
Patch Set: Avoid too-long line. Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « man/src/git-hyper-blame.txt ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright 2016 The Chromium Authors. All rights reserved. 2 # Copyright 2016 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 """Tests for git_dates.""" 5 """Tests for git_dates."""
6 6
7 import datetime 7 import datetime
8 import os 8 import os
9 import shutil 9 import shutil
10 import StringIO 10 import StringIO
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 commit_name: The commit's schema name. 43 commit_name: The commit's schema name.
44 rest: The blame line after the timestamp. e.g., '2) file2 - merged'. 44 rest: The blame line after the timestamp. e.g., '2) file2 - merged'.
45 """ 45 """
46 short = self.repo[commit_name][:8] 46 short = self.repo[commit_name][:8]
47 start = '%s %s' % (short, filename) if filename else short 47 start = '%s %s' % (short, filename) if filename else short
48 author = self.repo.show_commit(commit_name, format_string='%an %ai') 48 author = self.repo.show_commit(commit_name, format_string='%an %ai')
49 return '%s (%s %s' % (start, author, rest) 49 return '%s (%s %s' % (start, author, rest)
50 50
51 class GitHyperBlameMainTest(GitHyperBlameTestBase): 51 class GitHyperBlameMainTest(GitHyperBlameTestBase):
52 """End-to-end tests on a very simple repo.""" 52 """End-to-end tests on a very simple repo."""
53 REPO_SCHEMA = "A B C" 53 REPO_SCHEMA = "A B C D"
54 54
55 COMMIT_A = { 55 COMMIT_A = {
56 'some/files/file': {'data': 'line 1\nline 2\n'}, 56 'some/files/file': {'data': 'line 1\nline 2\n'},
57 } 57 }
58 58
59 COMMIT_B = { 59 COMMIT_B = {
60 'some/files/file': {'data': 'line 1\nline 2.1\n'}, 60 'some/files/file': {'data': 'line 1\nline 2.1\n'},
61 } 61 }
62 62
63 COMMIT_C = { 63 COMMIT_C = {
64 'some/files/file': {'data': 'line 1.1\nline 2.1\n'}, 64 'some/files/file': {'data': 'line 1.1\nline 2.1\n'},
65 } 65 }
66 66
67 COMMIT_D = {
68 # This file should be automatically considered for ignore.
69 '.git-blame-ignore-revs': {'data': 'tag_C'},
70 # This file should not be considered.
71 'some/files/.git-blame-ignore-revs': {'data': 'tag_B'},
72 }
73
74 def setUp(self):
75 super(GitHyperBlameMainTest, self).setUp()
76 # Most tests want to check out C (so the .git-blame-ignore-revs is not
77 # used).
78 self.repo.git('checkout', '-f', 'tag_C')
79
67 def testBasicBlame(self): 80 def testBasicBlame(self):
68 """Tests the main function (simple end-to-end test with no ignores).""" 81 """Tests the main function (simple end-to-end test with no ignores)."""
69 expected_output = [self.blame_line('C', '1) line 1.1'), 82 expected_output = [self.blame_line('C', '1) line 1.1'),
70 self.blame_line('B', '2) line 2.1')] 83 self.blame_line('B', '2) line 2.1')]
71 stdout = StringIO.StringIO() 84 stdout = StringIO.StringIO()
72 stderr = StringIO.StringIO() 85 stderr = StringIO.StringIO()
73 retval = self.repo.run(self.git_hyper_blame.main, 86 retval = self.repo.run(self.git_hyper_blame.main,
74 args=['tag_C', 'some/files/file'], stdout=stdout, 87 args=['tag_C', 'some/files/file'], stdout=stdout,
75 stderr=stderr) 88 stderr=stderr)
76 self.assertEqual(0, retval) 89 self.assertEqual(0, retval)
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 args=['-i', 'tag_B', 'xxxx', 'some/files/file'], 143 args=['-i', 'tag_B', 'xxxx', 'some/files/file'],
131 stdout=stdout, stderr=stderr) 144 stdout=stdout, stderr=stderr)
132 self.assertNotEqual(0, retval) 145 self.assertNotEqual(0, retval)
133 self.assertEqual('', stdout.getvalue()) 146 self.assertEqual('', stdout.getvalue())
134 self.assertRegexpMatches(stderr.getvalue(), 147 self.assertRegexpMatches(stderr.getvalue(),
135 '^fatal: ambiguous argument \'xxxx\': unknown ' 148 '^fatal: ambiguous argument \'xxxx\': unknown '
136 'revision or path not in the working tree.') 149 'revision or path not in the working tree.')
137 150
138 def testBadIgnore(self): 151 def testBadIgnore(self):
139 """Tests the main function (bad revision passed to -i).""" 152 """Tests the main function (bad revision passed to -i)."""
153 expected_output = [self.blame_line('C', '1) line 1.1'),
154 self.blame_line('B', '2) line 2.1')]
140 stdout = StringIO.StringIO() 155 stdout = StringIO.StringIO()
141 stderr = StringIO.StringIO() 156 stderr = StringIO.StringIO()
142 retval = self.repo.run(self.git_hyper_blame.main, 157 retval = self.repo.run(self.git_hyper_blame.main,
143 args=['-i', 'xxxx', 'tag_C', 'some/files/file'], 158 args=['-i', 'xxxx', 'tag_C', 'some/files/file'],
144 stdout=stdout, stderr=stderr) 159 stdout=stdout, stderr=stderr)
145 self.assertNotEqual(0, retval) 160 self.assertEqual(0, retval)
146 self.assertEqual('', stdout.getvalue()) 161 self.assertEqual(expected_output, stdout.getvalue().rstrip().split('\n'))
147 self.assertEqual('fatal: unknown revision \'xxxx\'.\n', stderr.getvalue()) 162 self.assertEqual('warning: unknown revision \'xxxx\'.\n', stderr.getvalue())
163
164 def testIgnoreFile(self):
165 """Tests passing the ignore list in a file."""
166 expected_output = [self.blame_line('C', ' 1) line 1.1'),
167 self.blame_line('A', '2*) line 2.1')]
168 stdout = StringIO.StringIO()
169 stderr = StringIO.StringIO()
170
171 with tempfile.NamedTemporaryFile(mode='w+', prefix='ignore') as ignore_file:
172 ignore_file.write('# Line comments are allowed.\n'.format(self.repo['B']))
173 ignore_file.write('\n')
174 ignore_file.write('{}\n'.format(self.repo['B']))
175 # A revision that is not in the repo (should be ignored).
176 ignore_file.write('xxxx\n')
177 ignore_file.flush()
178 retval = self.repo.run(self.git_hyper_blame.main,
179 args=['--ignore-file', ignore_file.name, 'tag_C',
180 'some/files/file'],
181 stdout=stdout, stderr=stderr)
182
183 self.assertEqual(0, retval)
184 self.assertEqual(expected_output, stdout.getvalue().rstrip().split('\n'))
185 self.assertEqual('warning: unknown revision \'xxxx\'.\n', stderr.getvalue())
186
187 def testDefaultIgnoreFile(self):
188 """Tests automatically using a default ignore list."""
189 # Check out revision D. We expect the script to use the default ignore list
190 # that is checked out, *not* the one committed at the given revision.
191 self.repo.git('checkout', '-f', 'tag_D')
192
193 expected_output = [self.blame_line('A', '1*) line 1.1'),
194 self.blame_line('B', ' 2) line 2.1')]
195 stdout = StringIO.StringIO()
196 stderr = StringIO.StringIO()
197
198 retval = self.repo.run(self.git_hyper_blame.main,
199 args=['tag_D', 'some/files/file'],
200 stdout=stdout, stderr=stderr)
201
202 self.assertEqual(0, retval)
203 self.assertEqual(expected_output, stdout.getvalue().rstrip().split('\n'))
204 self.assertEqual('', stderr.getvalue())
205
206 # Test blame from a different revision. Despite the default ignore file
207 # *not* being committed at that revision, it should still be picked up
208 # because D is currently checked out.
209 stdout = StringIO.StringIO()
210 stderr = StringIO.StringIO()
211
212 retval = self.repo.run(self.git_hyper_blame.main,
213 args=['tag_C', 'some/files/file'],
214 stdout=stdout, stderr=stderr)
215
216 self.assertEqual(0, retval)
217 self.assertEqual(expected_output, stdout.getvalue().rstrip().split('\n'))
218 self.assertEqual('', stderr.getvalue())
148 219
149 class GitHyperBlameSimpleTest(GitHyperBlameTestBase): 220 class GitHyperBlameSimpleTest(GitHyperBlameTestBase):
150 REPO_SCHEMA = """ 221 REPO_SCHEMA = """
151 A B D E F G H 222 A B D E F G H
152 A C D 223 A C D
153 """ 224 """
154 225
155 COMMIT_A = { 226 COMMIT_A = {
156 'some/files/file1': {'data': 'file1'}, 227 'some/files/file1': {'data': 'file1'},
157 'some/files/file2': {'data': 'file2'}, 228 'some/files/file2': {'data': 'file2'},
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after
423 self.blame_line('C', ' 9) Z'), 494 self.blame_line('C', ' 9) Z'),
424 ] 495 ]
425 retval, output = self.run_hyperblame(['E'], 'file', 'tag_E') 496 retval, output = self.run_hyperblame(['E'], 'file', 'tag_E')
426 self.assertEqual(0, retval) 497 self.assertEqual(0, retval)
427 self.assertEqual(expected_output, output) 498 self.assertEqual(expected_output, output)
428 499
429 500
430 if __name__ == '__main__': 501 if __name__ == '__main__':
431 sys.exit(coverage_utils.covered_main( 502 sys.exit(coverage_utils.covered_main(
432 os.path.join(DEPOT_TOOLS_ROOT, 'git_hyper_blame.py'))) 503 os.path.join(DEPOT_TOOLS_ROOT, 'git_hyper_blame.py')))
OLDNEW
« no previous file with comments | « man/src/git-hyper-blame.txt ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698