/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: Martin Pool
  • Date: 2009-07-17 10:38:41 UTC
  • mfrom: (4536 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4558.
  • Revision ID: mbp@sourcefrog.net-20090717103841-z35onk04bkiw7zb6
Merge trunk

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
        ('out-of-sync-trees',
 
53
         dict(_changes_type= '_out_of_sync_trees')),
 
54
        ]
 
55
    tests.multiply_tests(changes_tests, changes_scenarios, result)
 
56
    # No parametrization for the remaining tests
 
57
    result.addTests(remaining_tests)
 
58
 
 
59
    return result
 
60
 
 
61
 
38
62
class TestPush(tests.TestCaseWithTransport):
39
63
 
40
64
    def test_push_error_on_vfs_http(self):
475
499
        # subsequent log is accurate
476
500
        self.assertNotContainsRe(out, 'rev1')
477
501
 
 
502
    def test_push_from_subdir(self):
 
503
        t = self.make_branch_and_tree('tree')
 
504
        self.build_tree(['tree/dir/', 'tree/dir/file'])
 
505
        t.add('dir', 'dir/file')
 
506
        t.commit('r1')
 
507
        out, err = self.run_bzr('push ../../pushloc', working_dir='tree/dir')
 
508
        self.assertEqual('', out)
 
509
        self.assertEqual('Created new branch.\n', err)
 
510
 
478
511
 
479
512
class RedirectingMemoryTransport(memory.MemoryTransport):
480
513
 
555
588
             % re.escape(destination_url)],
556
589
            ['push', '-d', 'tree', destination_url], retcode=3)
557
590
        self.assertEqual('', out)
 
591
 
 
592
 
 
593
class TestPushStrictMixin(object):
 
594
 
 
595
    def make_local_branch_and_tree(self):
 
596
        self.tree = self.make_branch_and_tree('local')
 
597
        self.build_tree_contents([('local/file', 'initial')])
 
598
        self.tree.add('file')
 
599
        self.tree.commit('adding file', rev_id='added')
 
600
        self.build_tree_contents([('local/file', 'modified')])
 
601
        self.tree.commit('modify file', rev_id='modified')
 
602
 
 
603
    def set_config_push_strict(self, value):
 
604
        # set config var (any of bazaar.conf, locations.conf, branch.conf
 
605
        # should do)
 
606
        conf = self.tree.branch.get_config()
 
607
        conf.set_user_option('push_strict', value)
 
608
 
 
609
    _default_command = ['push', '../to']
 
610
    _default_wd = 'local'
 
611
    _default_errors = ['Working tree ".*/local/" has uncommitted '
 
612
                       'changes \(See bzr status\)\.',]
 
613
    _default_pushed_revid = 'modified'
 
614
 
 
615
    def assertPushFails(self, args):
 
616
        self.run_bzr_error(self._default_errors, self._default_command + args,
 
617
                           working_dir=self._default_wd, retcode=3)
 
618
 
 
619
    def assertPushSucceeds(self, args, pushed_revid=None):
 
620
        self.run_bzr(self._default_command + args,
 
621
                     working_dir=self._default_wd)
 
622
        if pushed_revid is None:
 
623
            pushed_revid = self._default_pushed_revid
 
624
        tree_to = workingtree.WorkingTree.open('to')
 
625
        repo_to = tree_to.branch.repository
 
626
        self.assertTrue(repo_to.has_revision(pushed_revid))
 
627
        self.assertEqual(tree_to.branch.last_revision_info()[1], pushed_revid)
 
628
 
 
629
 
 
630
 
 
631
class TestPushStrictWithoutChanges(tests.TestCaseWithTransport,
 
632
                                   TestPushStrictMixin):
 
633
 
 
634
    def setUp(self):
 
635
        super(TestPushStrictWithoutChanges, self).setUp()
 
636
        self.make_local_branch_and_tree()
 
637
 
 
638
    def test_push_default(self):
 
639
        self.assertPushSucceeds([])
 
640
 
 
641
    def test_push_strict(self):
 
642
        self.assertPushSucceeds(['--strict'])
 
643
 
 
644
    def test_push_no_strict(self):
 
645
        self.assertPushSucceeds(['--no-strict'])
 
646
 
 
647
    def test_push_config_var_strict(self):
 
648
        self.set_config_push_strict('true')
 
649
        self.assertPushSucceeds([])
 
650
 
 
651
    def test_push_config_var_no_strict(self):
 
652
        self.set_config_push_strict('false')
 
653
        self.assertPushSucceeds([])
 
654
 
 
655
 
 
656
class TestPushStrictWithChanges(tests.TestCaseWithTransport,
 
657
                                TestPushStrictMixin):
 
658
 
 
659
    _changes_type = None # Set by load_tests
 
660
 
 
661
    def setUp(self):
 
662
        super(TestPushStrictWithChanges, self).setUp()
 
663
        getattr(self, self._changes_type)()
 
664
 
 
665
    def _uncommitted_changes(self):
 
666
        self.make_local_branch_and_tree()
 
667
        # Make a change without committing it
 
668
        self.build_tree_contents([('local/file', 'in progress')])
 
669
 
 
670
    def _pending_merges(self):
 
671
        self.make_local_branch_and_tree()
 
672
        # Create 'other' branch containing a new file
 
673
        other_bzrdir = self.tree.bzrdir.sprout('other')
 
674
        other_tree = other_bzrdir.open_workingtree()
 
675
        self.build_tree_contents([('other/other-file', 'other')])
 
676
        other_tree.add('other-file')
 
677
        other_tree.commit('other commit', rev_id='other')
 
678
        # Merge and revert, leaving a pending merge
 
679
        self.tree.merge_from_branch(other_tree.branch)
 
680
        self.tree.revert(filenames=['other-file'], backups=False)
 
681
 
 
682
    def _out_of_sync_trees(self):
 
683
        self.make_local_branch_and_tree()
 
684
        self.run_bzr(['checkout', '--lightweight', 'local', 'checkout'])
 
685
        # Make a change and commit it
 
686
        self.build_tree_contents([('local/file', 'modified in local')])
 
687
        self.tree.commit('modify file', rev_id='modified-in-local')
 
688
        # Exercise commands from the checkout directory
 
689
        self._default_wd = 'checkout'
 
690
        self._default_errors = ["Working tree is out of date, please run"
 
691
                                " 'bzr update'\.",]
 
692
        self._default_pushed_revid = 'modified-in-local'
 
693
 
 
694
    def test_push_default(self):
 
695
        self.assertPushFails([])
 
696
 
 
697
    def test_push_with_revision(self):
 
698
        self.assertPushSucceeds(['-r', 'revid:added'], pushed_revid='added')
 
699
 
 
700
    def test_push_no_strict(self):
 
701
        self.assertPushSucceeds(['--no-strict'])
 
702
 
 
703
    def test_push_strict_with_changes(self):
 
704
        self.assertPushFails(['--strict'])
 
705
 
 
706
    def test_push_respect_config_var_strict(self):
 
707
        self.set_config_push_strict('true')
 
708
        self.assertPushFails([])
 
709
 
 
710
    def test_push_bogus_config_var_ignored(self):
 
711
        self.set_config_push_strict("I don't want you to be strict")
 
712
        self.assertPushFails([])
 
713
 
 
714
    def test_push_no_strict_command_line_override_config(self):
 
715
        self.set_config_push_strict('yES')
 
716
        self.assertPushFails([])
 
717
        self.assertPushSucceeds(['--no-strict'])
 
718
 
 
719
    def test_push_strict_command_line_override_config(self):
 
720
        self.set_config_push_strict('oFF')
 
721
        self.assertPushFails(['--strict'])
 
722
        self.assertPushSucceeds([])