~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Vincent Ladeuil
  • Date: 2009-06-11 06:49:21 UTC
  • mto: (4452.1.1 integration)
  • mto: This revision was merged to the branch mainline in revision 4453.
  • Revision ID: v.ladeuil+lp@free.fr-20090611064921-on9wxymrzgkxi2a0
Start implementing jam's review feedback.

* bzrlib/tests/blackbox/test_push.py:
(TestPushStrict): Refactor and some tests.

* bzrlib/config.py:
(TreeConfig.get_option): Delete dead code.

Show diffs side-by-side

added added

removed removed

Lines of Context:
541
541
        tree.commit('adding file', rev_id='from-1')
542
542
        return tree
543
543
 
544
 
    def assertTreePushed(self, relpath):
545
 
        tree_to = workingtree.WorkingTree.open(relpath)
 
544
    def make_local_branch_and_tree_with_changes(self):
 
545
        tree = self.make_local_branch_and_tree()
 
546
        # Make some changes
 
547
        self.build_tree_contents([('local/file', 'modified')])
 
548
        return tree
 
549
 
 
550
    def set_config_push_strict(self, tree, value):
 
551
        # set config var (any of bazaar.conf, locations.conf, branch.conf
 
552
        # should do)
 
553
        conf = tree.branch.get_config()
 
554
        conf.set_user_option('push_strict', value)
 
555
 
 
556
    def assertPushFails(self, location, *args):
 
557
        self.run_bzr_error(['Working tree ".*/local/"'
 
558
                            ' has uncommitted changes.$',],
 
559
                           ['push', '../' + location] + list(args),
 
560
                           working_dir='local', retcode=3)
 
561
 
 
562
    def assertPushSucceeds(self, location, *args):
 
563
        self.run_bzr(['push', '../' + location] + list(args),
 
564
                     working_dir='local')
 
565
        tree_to = workingtree.WorkingTree.open(location)
546
566
        repo_to = tree_to.branch.repository
547
567
        self.assertTrue(repo_to.has_revision('from-1'))
548
568
        self.assertEqual(tree_to.branch.last_revision_info()[1], 'from-1')
549
569
 
550
570
    def test_push_default(self):
551
 
        tree = self.make_local_branch_and_tree()
552
 
        # Make some changes
553
 
        self.build_tree_contents([('local/file', 'modified')])
554
 
        # Push with some uncommitted changes works
555
 
        self.run_bzr(['push', '../to'], working_dir='local')
556
 
        self.assertTreePushed('to')
 
571
        tree = self.make_local_branch_and_tree_with_changes()
 
572
        self.assertPushSucceeds('to')
 
573
 
 
574
    def test_push_no_strict_with_changes(self):
 
575
        tree = self.make_local_branch_and_tree_with_changes()
 
576
        self.assertPushSucceeds('to', '--no-strict')
557
577
 
558
578
    def test_push_strict_with_changes(self):
559
 
        tree = self.make_local_branch_and_tree()
560
 
        # Make some changes
561
 
        self.build_tree_contents([('local/file', 'modified')])
562
 
        # Push with some uncommitted changes fails
563
 
        self.run_bzr_error(['Working tree ".*/local/"'
564
 
                            ' has uncommitted changes.$',],
565
 
                           ['push', '--strict', '../to'],
566
 
                           working_dir='local', retcode=3)
 
579
        tree = self.make_local_branch_and_tree_with_changes()
 
580
        self.assertPushFails('to', '--strict')
567
581
 
568
582
    def test_push_strict_without_changes(self):
569
583
        tree = self.make_local_branch_and_tree()
570
 
        self.run_bzr(['push', '--strict', '../to'], working_dir='local')
571
 
        self.assertTreePushed('to')
572
 
 
573
 
    def test_push_respect_config_var(self):
574
 
        tree = self.make_local_branch_and_tree()
575
 
        # Make some changes
576
 
        self.build_tree_contents([('local/file', 'modified')])
577
 
        # set config var (any of bazaar.conf, locations.conf, branch.conf
578
 
        # should do)
579
 
        conf = tree.branch.get_config()
580
 
        conf.set_user_option('push_strict', 'true')
581
 
        # Push --strict (inherited from config) with some uncommitted changes
582
 
        # fails
583
 
        self.run_bzr_error(['Working tree ".*/local/"'
584
 
                            ' has uncommitted changes.$',],
585
 
                           ['push', '../to'],
586
 
                           working_dir='local', retcode=3)
587
 
 
588
 
    def test_push_command_line_override_config(self):
589
 
        tree = self.make_local_branch_and_tree()
590
 
        # Make some changes
591
 
        self.build_tree_contents([('local/file', 'modified')])
592
 
        # set config var (any of bazaar.conf, locations.conf, branch.conf
593
 
        # should do)
594
 
        conf = tree.branch.get_config()
595
 
        conf.set_user_option('push_strict', 'true')
596
 
        self.run_bzr(['push', '--no-strict', '../to'], working_dir='local')
597
 
        self.assertTreePushed('to')
 
584
        self.assertPushSucceeds('to', '--strict')
 
585
 
 
586
    def test_push_respect_config_var_strict(self):
 
587
        tree = self.make_local_branch_and_tree_with_changes()
 
588
        self.set_config_push_strict(tree, 'true')
 
589
        # Push --strict (inherited from config) fails
 
590
        self.assertPushFails('to')
 
591
 
 
592
    def test_push_no_strict_command_line_override_config(self):
 
593
        tree = self.make_local_branch_and_tree_with_changes()
 
594
        self.set_config_push_strict(tree, 'true')
 
595
        self.assertPushSucceeds('to', '--no-strict')
 
596
 
 
597
    def test_push_strict_command_line_override_config(self):
 
598
        tree = self.make_local_branch_and_tree_with_changes()
 
599
        self.set_config_push_strict(tree, 'False')
 
600
        self.assertPushFails('to', '--strict')