(self)
| 527 | self.assertEqual(ans, q) |
| 528 | |
| 529 | def test_git(self): |
| 530 | create_watcher = get_fallback_create_watcher() |
| 531 | repo = guess(path=GIT_REPO, create_watcher=create_watcher) |
| 532 | self.assertNotEqual(repo, None) |
| 533 | self.assertEqual(repo.branch(), 'master') |
| 534 | self.assertEqual(repo.status(), None) |
| 535 | self.assertEqual(repo.status('file'), None) |
| 536 | with open(os.path.join(GIT_REPO, 'file'), 'w') as f: |
| 537 | f.write('abc') |
| 538 | f.flush() |
| 539 | self.assertEqual(repo.status(), ' U') |
| 540 | self.assertEqual(repo.status('file'), '??') |
| 541 | call(['git', 'add', '.'], cwd=GIT_REPO) |
| 542 | self.assertEqual(repo.status(), ' I ') |
| 543 | self.assertEqual(repo.status('file'), 'A ') |
| 544 | f.write('def') |
| 545 | f.flush() |
| 546 | self.assertEqual(repo.status(), 'DI ') |
| 547 | self.assertEqual(repo.status('file'), 'AM') |
| 548 | os.remove(os.path.join(GIT_REPO, 'file')) |
| 549 | # Test changing branch |
| 550 | self.assertEqual(repo.branch(), 'master') |
| 551 | try: |
| 552 | call(['git', 'branch', 'branch1'], cwd=GIT_REPO) |
| 553 | call(['git', 'checkout', '-q', 'branch1'], cwd=GIT_REPO) |
| 554 | self.do_branch_rename_test(repo, 'branch1') |
| 555 | call(['git', 'branch', 'branch2'], cwd=GIT_REPO) |
| 556 | call(['git', 'checkout', '-q', 'branch2'], cwd=GIT_REPO) |
| 557 | self.do_branch_rename_test(repo, 'branch2') |
| 558 | call(['git', 'checkout', '-q', '--detach', 'branch1'], cwd=GIT_REPO) |
| 559 | self.do_branch_rename_test(repo, lambda b: re.match(r'^[a-f0-9]+$', b)) |
| 560 | finally: |
| 561 | call(['git', 'checkout', '-q', 'master'], cwd=GIT_REPO) |
| 562 | # Test stashing |
| 563 | self.assertEqual(repo.stash(), 0) |
| 564 | |
| 565 | def stash_save(): |
| 566 | with open(os.path.join(GIT_REPO, 'file'), 'w') as f: |
| 567 | f.write('abc') |
| 568 | return call(['git', 'stash', '-u'], cwd=GIT_REPO, stdout=PIPE) |
| 569 | |
| 570 | def stash_drop(): |
| 571 | return call(['git', 'stash', 'drop'], cwd=GIT_REPO, stdout=PIPE) |
| 572 | |
| 573 | def stash_list(): |
| 574 | return call(['git', 'stash', 'list'], cwd=GIT_REPO, stdout=PIPE) |
| 575 | |
| 576 | try: |
| 577 | stash_save() |
| 578 | self.assertEqual(repo.stash(), 1) |
| 579 | stash_save() |
| 580 | self.assertEqual(repo.stash(), 2) |
| 581 | stash_drop() |
| 582 | self.assertEqual(repo.stash(), 1) |
| 583 | stash_drop() |
| 584 | self.assertEqual(repo.stash(), 0) |
| 585 | finally: |
| 586 | while stash_list(): |
nothing calls this directly
no test coverage detected