~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Aaron Bentley
  • Date: 2009-04-30 14:04:38 UTC
  • mto: This revision was merged to the branch mainline in revision 4316.
  • Revision ID: aaron@aaronbentley.com-20090430140438-hpw2h918x4mpnpaw
Update from review

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2009, 2010 Canonical Ltd
 
1
# Copyright (C) 2005, 2007, 2008, 2009 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
20
20
 
21
21
import os
22
22
 
23
 
from bzrlib import (
24
 
    branch,
25
 
    bzrdir,
26
 
    foreign,
27
 
    tests,
28
 
    workingtree,
29
 
    )
30
 
from bzrlib.tests import (
31
 
    blackbox,
32
 
    script,
33
 
    test_foreign,
34
 
    )
35
 
from bzrlib.tests.blackbox import test_push
36
 
 
37
 
 
38
 
def load_tests(standard_tests, module, loader):
39
 
    """Multiply tests for the dpush 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
 
                TestDpushStrictWithChanges,
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
 
 
62
 
class TestDpush(tests.TestCaseWithTransport):
 
23
from bzrlib.branch import (
 
24
    Branch,
 
25
    )
 
26
from bzrlib.bzrdir import (
 
27
    BzrDirFormat,
 
28
    )
 
29
from bzrlib.foreign import (
 
30
    ForeignBranch,
 
31
    ForeignRepository,
 
32
    )
 
33
from bzrlib.repository import (
 
34
    Repository,
 
35
    )
 
36
from bzrlib.tests.blackbox import (
 
37
    ExternalBase,
 
38
    )
 
39
from bzrlib.tests.test_foreign import (
 
40
    DummyForeignVcsDirFormat,
 
41
    )
 
42
 
 
43
 
 
44
class TestDpush(ExternalBase):
63
45
 
64
46
    def setUp(self):
 
47
        BzrDirFormat.register_control_format(DummyForeignVcsDirFormat)
 
48
        self.addCleanup(self.unregister_format)
65
49
        super(TestDpush, self).setUp()
66
 
        test_foreign.register_dummy_foreign_for_test(self)
 
50
 
 
51
    def unregister_format(self):
 
52
        try:
 
53
            BzrDirFormat.unregister_control_format(DummyForeignVcsDirFormat)
 
54
        except ValueError:
 
55
            pass
67
56
 
68
57
    def make_dummy_builder(self, relpath):
69
 
        builder = self.make_branch_builder(
70
 
            relpath, format=test_foreign.DummyForeignVcsDirFormat())
71
 
        builder.build_snapshot('revid', None,
 
58
        builder = self.make_branch_builder(relpath, 
 
59
                format=DummyForeignVcsDirFormat())
 
60
        builder.build_snapshot('revid', None, 
72
61
            [('add', ('', 'TREE_ROOT', 'directory', None)),
73
62
             ('add', ('foo', 'fooid', 'file', 'bar'))])
74
63
        return builder
78
67
        source_tree = self.make_branch_and_tree("dc")
79
68
        output, error = self.run_bzr("dpush -d dc dp", retcode=3)
80
69
        self.assertEquals("", output)
81
 
        self.assertContainsRe(error, 'in the same VCS, lossy push not necessary. Please use regular push.')
 
70
        self.assertContainsRe(error, 'not a foreign branch, use regular push')
82
71
 
83
72
    def test_dpush(self):
84
73
        branch = self.make_dummy_builder('d').get_branch()
87
76
        self.build_tree(("dc/foo", "blaaaa"))
88
77
        dc.open_workingtree().commit('msg')
89
78
 
90
 
        script.run_script(self, """
91
 
            $ bzr dpush -d dc d
92
 
            2>Pushed up to revision 2.
93
 
            $ bzr status dc
94
 
            """)
 
79
        self.check_output("", "dpush -d dc d")
 
80
        self.check_output("", "status dc")
95
81
 
96
82
    def test_dpush_new(self):
97
 
        b = self.make_dummy_builder('d').get_branch()
 
83
        branch = self.make_dummy_builder('d').get_branch()
98
84
 
99
 
        dc = b.bzrdir.sprout('dc', force_new_repo=True)
 
85
        dc = branch.bzrdir.sprout('dc', force_new_repo=True)
100
86
        self.build_tree_contents([("dc/foofile", "blaaaa")])
101
87
        dc_tree = dc.open_workingtree()
102
88
        dc_tree.add("foofile")
103
89
        dc_tree.commit("msg")
104
90
 
105
 
        script.run_script(self, '''
106
 
            $ bzr dpush -d dc d
107
 
            $ bzr revno dc
108
 
            2
109
 
            $ bzr status dc
110
 
            ''')
 
91
        self.check_output("", "dpush -d dc d")
 
92
        self.check_output("2\n", "revno dc")
 
93
        self.check_output("", "status dc")
111
94
 
112
95
    def test_dpush_wt_diff(self):
113
 
        b = self.make_dummy_builder('d').get_branch()
 
96
        branch = self.make_dummy_builder('d').get_branch()
114
97
 
115
 
        dc = b.bzrdir.sprout('dc', force_new_repo=True)
 
98
        dc = branch.bzrdir.sprout('dc', force_new_repo=True)
116
99
        self.build_tree_contents([("dc/foofile", "blaaaa")])
117
100
        dc_tree = dc.open_workingtree()
118
101
        dc_tree.add("foofile")
119
102
        newrevid = dc_tree.commit('msg')
120
103
 
121
104
        self.build_tree_contents([("dc/foofile", "blaaaal")])
122
 
        script.run_script(self, '''
123
 
            $ bzr dpush -d dc d --no-strict
124
 
            ''')
 
105
        self.check_output("", "dpush -d dc d")
125
106
        self.assertFileEqual("blaaaal", "dc/foofile")
126
 
        # if the dummy vcs wasn't that dummy we could uncomment the line below
127
 
        # self.assertFileEqual("blaaaa", "d/foofile")
128
 
        script.run_script(self, '''
129
 
            $ bzr status dc
130
 
            modified:
131
 
              foofile
132
 
            ''')
 
107
        self.check_output('modified:\n  foofile\n', "status dc")
133
108
 
134
109
    def test_diverged(self):
135
110
        builder = self.make_dummy_builder('d')
136
111
 
137
 
        b = builder.get_branch()
 
112
        branch = builder.get_branch()
138
113
 
139
 
        dc = b.bzrdir.sprout('dc', force_new_repo=True)
 
114
        dc = branch.bzrdir.sprout('dc', force_new_repo=True)
140
115
        dc_tree = dc.open_workingtree()
141
116
 
142
117
        self.build_tree_contents([("dc/foo", "bar")])
148
123
        output, error = self.run_bzr("dpush -d dc d", retcode=3)
149
124
        self.assertEquals(output, "")
150
125
        self.assertContainsRe(error, "have diverged")
151
 
 
152
 
 
153
 
class TestDpushStrictMixin(object):
154
 
 
155
 
    def setUp(self):
156
 
        test_foreign.register_dummy_foreign_for_test(self)
157
 
        # Create an empty branch where we will be able to push
158
 
        self.foreign = self.make_branch(
159
 
            'to', format=test_foreign.DummyForeignVcsDirFormat())
160
 
 
161
 
    def set_config_push_strict(self, value):
162
 
        # set config var (any of bazaar.conf, locations.conf, branch.conf
163
 
        # should do)
164
 
        conf = self.tree.branch.get_config()
165
 
        conf.set_user_option('dpush_strict', value)
166
 
 
167
 
    _default_command = ['dpush', '../to']
168
 
 
169
 
 
170
 
class TestDpushStrictWithoutChanges(TestDpushStrictMixin,
171
 
                                    test_push.TestPushStrictWithoutChanges):
172
 
 
173
 
    def setUp(self):
174
 
        test_push.TestPushStrictWithoutChanges.setUp(self)
175
 
        TestDpushStrictMixin.setUp(self)
176
 
 
177
 
 
178
 
class TestDpushStrictWithChanges(TestDpushStrictMixin,
179
 
                                 test_push.TestPushStrictWithChanges):
180
 
 
181
 
    _changes_type = None # Set by load_tests
182
 
 
183
 
    def setUp(self):
184
 
        test_push.TestPushStrictWithChanges.setUp(self)
185
 
        TestDpushStrictMixin.setUp(self)
186
 
 
187
 
    def test_push_with_revision(self):
188
 
        raise tests.TestNotApplicable('dpush does not handle --revision')
189