| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright 2013 The Chromium Authors. All rights reserved. | 2 # Copyright 2013 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 | 5 |
| 6 """Unit tests for git_common.py""" | 6 """Unit tests for git_common.py""" |
| 7 | 7 |
| 8 import binascii | 8 import binascii |
| 9 import collections | 9 import collections |
| 10 import os | 10 import os |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 214 items = set(self.repo.commit_map.itervalues()) | 214 items = set(self.repo.commit_map.itervalues()) |
| 215 | 215 |
| 216 def testfn(): | 216 def testfn(): |
| 217 for line in self.gc.run_stream('log', '--format=%H').xreadlines(): | 217 for line in self.gc.run_stream('log', '--format=%H').xreadlines(): |
| 218 line = line.strip() | 218 line = line.strip() |
| 219 self.assertIn(line, items) | 219 self.assertIn(line, items) |
| 220 items.remove(line) | 220 items.remove(line) |
| 221 | 221 |
| 222 self.repo.run(testfn) | 222 self.repo.run(testfn) |
| 223 | 223 |
| 224 def testStreamWithRetcode(self): |
| 225 items = set(self.repo.commit_map.itervalues()) |
| 226 |
| 227 def testfn(): |
| 228 with self.gc.run_stream_with_retcode('log', '--format=%H') as stdout: |
| 229 for line in stdout.xreadlines(): |
| 230 line = line.strip() |
| 231 self.assertIn(line, items) |
| 232 items.remove(line) |
| 233 |
| 234 self.repo.run(testfn) |
| 235 |
| 236 def testStreamWithRetcodeException(self): |
| 237 import subprocess2 |
| 238 with self.assertRaises(subprocess2.CalledProcessError): |
| 239 with self.gc.run_stream_with_retcode('checkout', 'unknown-branch'): |
| 240 pass |
| 241 |
| 224 def testCurrentBranch(self): | 242 def testCurrentBranch(self): |
| 225 def cur_branch_out_of_git(): | 243 def cur_branch_out_of_git(): |
| 226 os.chdir('..') | 244 os.chdir('..') |
| 227 return self.gc.current_branch() | 245 return self.gc.current_branch() |
| 228 self.assertIsNone(self.repo.run(cur_branch_out_of_git)) | 246 self.assertIsNone(self.repo.run(cur_branch_out_of_git)) |
| 229 | 247 |
| 230 self.repo.git('checkout', 'branch_D') | 248 self.repo.git('checkout', 'branch_D') |
| 231 self.assertEqual(self.repo.run(self.gc.current_branch), 'branch_D') | 249 self.assertEqual(self.repo.run(self.gc.current_branch), 'branch_D') |
| 232 | 250 |
| 233 @unittest.skip('broken by git 2.4') | 251 @unittest.skip('broken by git 2.4') |
| (...skipping 493 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 727 self.assertEquals(self.repo.git('status', '--porcelain').stdout, STATUS_1) | 745 self.assertEquals(self.repo.git('status', '--porcelain').stdout, STATUS_1) |
| 728 | 746 |
| 729 self.repo.run(inner) | 747 self.repo.run(inner) |
| 730 | 748 |
| 731 | 749 |
| 732 if __name__ == '__main__': | 750 if __name__ == '__main__': |
| 733 sys.exit(coverage_utils.covered_main( | 751 sys.exit(coverage_utils.covered_main( |
| 734 os.path.join(DEPOT_TOOLS_ROOT, 'git_common.py'), | 752 os.path.join(DEPOT_TOOLS_ROOT, 'git_common.py'), |
| 735 required_percentage=88.0 | 753 required_percentage=88.0 |
| 736 )) | 754 )) |
| OLD | NEW |