/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/blackbox/test_push.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2009-06-30 10:20:58 UTC
  • mfrom: (4492.1.1 integration)
  • Revision ID: pqm@pqm.ubuntu.com-20090630102058-mkgmx4g87dkdpu63
(vila) push --strict is now the default

Show diffs side-by-side

added added

removed removed

Lines of Context:
35
35
from bzrlib.transport import memory
36
36
 
37
37
 
 
38
def load_tests(standard_tests, module, loader):
 
39
    """Multiply tests for the push command."""
 
40
    result = loader.suiteClass()
 
41
 
 
42
    # one for each king of change
 
43
    changes_tests, remaining_tests = tests.split_suite_by_condition(
 
44
        standard_tests, tests.condition_isinstance((
 
45
                TestPushStrictWithChanges,
 
46
                )))
 
47
    changes_scenarios = [
 
48
        ('uncommitted',
 
49
         dict(_changes_type= '_uncommitted_changes')),
 
50
        ('pending_merges',
 
51
         dict(_changes_type= '_pending_merges')),
 
52
        ]
 
53
    tests.multiply_tests(changes_tests, changes_scenarios, result)
 
54
    # No parametrization for the remaining tests
 
55
    result.addTests(remaining_tests)
 
56
 
 
57
    return result
 
58
 
 
59
 
38
60
class TestPush(tests.TestCaseWithTransport):
39
61
 
40
62
    def test_push_error_on_vfs_http(self):
569
591
class TestPushStrict(tests.TestCaseWithTransport):
570
592
 
571
593
    def make_local_branch_and_tree(self):
572
 
        tree = self.make_branch_and_tree('local')
 
594
        self.tree = self.make_branch_and_tree('local')
573
595
        self.build_tree_contents([('local/file', 'initial')])
574
 
        tree.add('file')
575
 
        tree.commit('adding file', rev_id='from-1')
576
 
        return tree
577
 
 
578
 
    def make_local_branch_and_tree_with_changes(self):
579
 
        tree = self.make_local_branch_and_tree()
580
 
        # Make some changes
 
596
        self.tree.add('file')
 
597
        self.tree.commit('adding file', rev_id='added')
581
598
        self.build_tree_contents([('local/file', 'modified')])
582
 
        return tree
 
599
        self.tree.commit('modify file', rev_id='modified')
583
600
 
584
 
    def set_config_push_strict(self, tree, value):
 
601
    def set_config_push_strict(self, value):
585
602
        # set config var (any of bazaar.conf, locations.conf, branch.conf
586
603
        # should do)
587
 
        conf = tree.branch.get_config()
 
604
        conf = self.tree.branch.get_config()
588
605
        conf.set_user_option('push_strict', value)
589
606
 
590
 
    def assertPushFails(self, location, *args):
 
607
    def assertPushFails(self, args):
591
608
        self.run_bzr_error(['Working tree ".*/local/"'
592
 
                            ' has uncommitted changes.$',],
593
 
                           ['push', '../' + location] + list(args),
 
609
                            ' has uncommitted changes \(See bzr status\)\.',],
 
610
                           ['push', '../to'] + args,
594
611
                           working_dir='local', retcode=3)
595
612
 
596
 
    def assertPushSucceeds(self, location, *args):
597
 
        self.run_bzr(['push', '../' + location] + list(args),
 
613
    def assertPushSucceeds(self, args, pushed_revid=None):
 
614
        self.run_bzr(['push', '../to'] + args,
598
615
                     working_dir='local')
599
 
        tree_to = workingtree.WorkingTree.open(location)
 
616
        if pushed_revid is None:
 
617
            pushed_revid = 'modified'
 
618
        tree_to = workingtree.WorkingTree.open('to')
600
619
        repo_to = tree_to.branch.repository
601
 
        self.assertTrue(repo_to.has_revision('from-1'))
602
 
        self.assertEqual(tree_to.branch.last_revision_info()[1], 'from-1')
603
 
 
604
 
    def test_push_default(self):
605
 
        tree = self.make_local_branch_and_tree_with_changes()
606
 
        self.assertPushSucceeds('to')
607
 
 
608
 
    def test_push_no_strict_with_changes(self):
609
 
        tree = self.make_local_branch_and_tree_with_changes()
610
 
        self.assertPushSucceeds('to', '--no-strict')
 
620
        self.assertTrue(repo_to.has_revision(pushed_revid))
 
621
        self.assertEqual(tree_to.branch.last_revision_info()[1], pushed_revid)
 
622
 
 
623
 
 
624
 
 
625
class TestPushStrictWithoutChanges(TestPushStrict):
 
626
 
 
627
    def setUp(self):
 
628
        super(TestPushStrictWithoutChanges, self).setUp()
 
629
        self.make_local_branch_and_tree()
 
630
 
 
631
    def test_push_default(self):
 
632
        self.assertPushSucceeds([])
 
633
 
 
634
    def test_push_strict(self):
 
635
        self.assertPushSucceeds(['--strict'])
 
636
 
 
637
    def test_push_no_strict(self):
 
638
        self.assertPushSucceeds(['--no-strict'])
 
639
 
 
640
    def test_push_config_var_strict(self):
 
641
        self.set_config_push_strict('true')
 
642
        self.assertPushSucceeds([])
 
643
 
 
644
    def test_push_config_var_no_strict(self):
 
645
        self.set_config_push_strict('false')
 
646
        self.assertPushSucceeds([])
 
647
 
 
648
 
 
649
class TestPushStrictWithChanges(TestPushStrict):
 
650
 
 
651
    _changes_type = None # Set by load_tests
 
652
 
 
653
    def setUp(self):
 
654
        super(TestPushStrictWithChanges, self).setUp()
 
655
        getattr(self, self._changes_type)()
 
656
 
 
657
    def _uncommitted_changes(self):
 
658
        self.make_local_branch_and_tree()
 
659
        # Make a change without committing it
 
660
        self.build_tree_contents([('local/file', 'in progress')])
 
661
 
 
662
    def _pending_merges(self):
 
663
        self.make_local_branch_and_tree()
 
664
        # Create 'other' branch containing a new file
 
665
        other_bzrdir = self.tree.bzrdir.sprout('other')
 
666
        other_tree = other_bzrdir.open_workingtree()
 
667
        self.build_tree_contents([('other/other-file', 'other')])
 
668
        other_tree.add('other-file')
 
669
        other_tree.commit('other commit', rev_id='other')
 
670
        # Merge and revert, leaving a pending merge
 
671
        self.tree.merge_from_branch(other_tree.branch)
 
672
        self.tree.revert(filenames=['other-file'], backups=False)
 
673
 
 
674
    def test_push_default(self):
 
675
        self.assertPushFails([])
 
676
 
 
677
    def test_push_with_revision(self):
 
678
        self.assertPushSucceeds(['-r', 'revid:added'], pushed_revid='added')
 
679
 
 
680
    def test_push_no_strict(self):
 
681
        self.assertPushSucceeds(['--no-strict'])
611
682
 
612
683
    def test_push_strict_with_changes(self):
613
 
        tree = self.make_local_branch_and_tree_with_changes()
614
 
        self.assertPushFails('to', '--strict')
615
 
 
616
 
    def test_push_strict_without_changes(self):
617
 
        tree = self.make_local_branch_and_tree()
618
 
        self.assertPushSucceeds('to', '--strict')
 
684
        self.assertPushFails(['--strict'])
619
685
 
620
686
    def test_push_respect_config_var_strict(self):
621
 
        tree = self.make_local_branch_and_tree_with_changes()
622
 
        self.set_config_push_strict(tree, 'true')
623
 
        self.assertPushFails('to')
 
687
        self.set_config_push_strict('true')
 
688
        self.assertPushFails([])
624
689
 
625
690
    def test_push_bogus_config_var_ignored(self):
626
 
        tree = self.make_local_branch_and_tree_with_changes()
627
 
        self.set_config_push_strict(tree, "I don't want you to be strict")
628
 
        self.assertPushSucceeds('to')
 
691
        self.set_config_push_strict("I don't want you to be strict")
 
692
        self.assertPushFails([])
629
693
 
630
694
    def test_push_no_strict_command_line_override_config(self):
631
 
        tree = self.make_local_branch_and_tree_with_changes()
632
 
        self.set_config_push_strict(tree, 'yES')
633
 
        self.assertPushFails('to')
634
 
        self.assertPushSucceeds('to', '--no-strict')
 
695
        self.set_config_push_strict('yES')
 
696
        self.assertPushFails([])
 
697
        self.assertPushSucceeds(['--no-strict'])
635
698
 
636
699
    def test_push_strict_command_line_override_config(self):
637
 
        tree = self.make_local_branch_and_tree_with_changes()
638
 
        self.set_config_push_strict(tree, 'oFF')
639
 
        self.assertPushFails('to', '--strict')
640
 
        self.assertPushSucceeds('to')
 
700
        self.set_config_push_strict('oFF')
 
701
        self.assertPushFails(['--strict'])
 
702
        self.assertPushSucceeds([])