/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
5273.1.8 by Vincent Ladeuil
Merge bzr.dev into cleanup
1
# Copyright (C) 2009, 2010 Canonical Ltd
3920.2.7 by Jelmer Vernooij
Add comments about dummy vcs.
2
#
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
7
#
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
12
#
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
3920.2.28 by Jelmer Vernooij
Fix FSF address.
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
3920.2.7 by Jelmer Vernooij
Add comments about dummy vcs.
16
3920.2.36 by Jelmer Vernooij
Fix tests after CommitBuilder changes.
17
3920.2.7 by Jelmer Vernooij
Add comments about dummy vcs.
18
"""Black-box tests for bzr dpush."""
19
3920.2.36 by Jelmer Vernooij
Fix tests after CommitBuilder changes.
20
3920.2.30 by Jelmer Vernooij
Review from John.
21
import os
22
4721.2.1 by Vincent Ladeuil
Some test cleamup.
23
from bzrlib import (
24
    branch,
25
    bzrdir,
26
    foreign,
27
    tests,
4721.2.2 by Vincent Ladeuil
Start testing and implementing --strict for dpush.
28
    workingtree,
3920.2.36 by Jelmer Vernooij
Fix tests after CommitBuilder changes.
29
    )
4721.2.1 by Vincent Ladeuil
Some test cleamup.
30
from bzrlib.tests import (
31
    blackbox,
5283.4.1 by Martin Pool
Deprecate ExternalBase.check_output and update some callers to use scripts
32
    script,
4721.2.1 by Vincent Ladeuil
Some test cleamup.
33
    test_foreign,
34
    )
4721.2.6 by Vincent Ladeuil
More agressive test sharing between push and dpush.
35
from bzrlib.tests.blackbox import test_push
4721.2.1 by Vincent Ladeuil
Some test cleamup.
36
4721.2.2 by Vincent Ladeuil
Start testing and implementing --strict for dpush.
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
5283.4.1 by Martin Pool
Deprecate ExternalBase.check_output and update some callers to use scripts
62
class TestDpush(tests.TestCaseWithTransport):
3920.2.10 by Jelmer Vernooij
More work trying to implement a dummy version control system.
63
64
    def setUp(self):
65
        super(TestDpush, self).setUp()
4721.2.5 by Vincent Ladeuil
Some refactoring.
66
        test_foreign.register_dummy_foreign_for_test(self)
3920.2.10 by Jelmer Vernooij
More work trying to implement a dummy version control system.
67
3920.2.33 by Jelmer Vernooij
Use branch_builder to create revisions in testsuite.
68
    def make_dummy_builder(self, relpath):
4721.2.1 by Vincent Ladeuil
Some test cleamup.
69
        builder = self.make_branch_builder(
70
            relpath, format=test_foreign.DummyForeignVcsDirFormat())
71
        builder.build_snapshot('revid', None,
3920.2.33 by Jelmer Vernooij
Use branch_builder to create revisions in testsuite.
72
            [('add', ('', 'TREE_ROOT', 'directory', None)),
73
             ('add', ('foo', 'fooid', 'file', 'bar'))])
74
        return builder
75
3920.2.18 by Jelmer Vernooij
make sure dpush between native branches fails.
76
    def test_dpush_native(self):
3920.2.30 by Jelmer Vernooij
Review from John.
77
        target_tree = self.make_branch_and_tree("dp")
78
        source_tree = self.make_branch_and_tree("dc")
3920.2.36 by Jelmer Vernooij
Fix tests after CommitBuilder changes.
79
        output, error = self.run_bzr("dpush -d dc dp", retcode=3)
80
        self.assertEquals("", output)
4368.2.2 by Jelmer Vernooij
s/not possible/not necessary/.
81
        self.assertContainsRe(error, 'in the same VCS, lossy push not necessary. Please use regular push.')
3920.2.18 by Jelmer Vernooij
make sure dpush between native branches fails.
82
3920.2.10 by Jelmer Vernooij
More work trying to implement a dummy version control system.
83
    def test_dpush(self):
3920.2.33 by Jelmer Vernooij
Use branch_builder to create revisions in testsuite.
84
        branch = self.make_dummy_builder('d').get_branch()
3920.2.10 by Jelmer Vernooij
More work trying to implement a dummy version control system.
85
3920.2.33 by Jelmer Vernooij
Use branch_builder to create revisions in testsuite.
86
        dc = branch.bzrdir.sprout('dc', force_new_repo=True)
3920.2.10 by Jelmer Vernooij
More work trying to implement a dummy version control system.
87
        self.build_tree(("dc/foo", "blaaaa"))
3920.2.32 by Jelmer Vernooij
Avoid run_bzr for functions other than the one being tested.
88
        dc.open_workingtree().commit('msg')
89
5283.4.1 by Martin Pool
Deprecate ExternalBase.check_output and update some callers to use scripts
90
        script.run_script(self, """
91
            $ bzr dpush -d dc d
92
            2>Pushed up to revision 2.
93
            $ bzr status dc
94
            """)
3920.2.10 by Jelmer Vernooij
More work trying to implement a dummy version control system.
95
96
    def test_dpush_new(self):
4721.2.1 by Vincent Ladeuil
Some test cleamup.
97
        b = self.make_dummy_builder('d').get_branch()
3920.2.33 by Jelmer Vernooij
Use branch_builder to create revisions in testsuite.
98
4721.2.1 by Vincent Ladeuil
Some test cleamup.
99
        dc = b.bzrdir.sprout('dc', force_new_repo=True)
3920.2.36 by Jelmer Vernooij
Fix tests after CommitBuilder changes.
100
        self.build_tree_contents([("dc/foofile", "blaaaa")])
3920.2.32 by Jelmer Vernooij
Avoid run_bzr for functions other than the one being tested.
101
        dc_tree = dc.open_workingtree()
3920.2.33 by Jelmer Vernooij
Use branch_builder to create revisions in testsuite.
102
        dc_tree.add("foofile")
103
        dc_tree.commit("msg")
3920.2.32 by Jelmer Vernooij
Avoid run_bzr for functions other than the one being tested.
104
5283.4.1 by Martin Pool
Deprecate ExternalBase.check_output and update some callers to use scripts
105
        script.run_script(self, '''
106
            $ bzr dpush -d dc d
5422.3.2 by Martin Pool
Update existing script tests to not ignore their output
107
            2>Pushed up to revision 2.
5283.4.1 by Martin Pool
Deprecate ExternalBase.check_output and update some callers to use scripts
108
            $ bzr revno dc
109
            2
110
            $ bzr status dc
111
            ''')
3920.2.10 by Jelmer Vernooij
More work trying to implement a dummy version control system.
112
113
    def test_dpush_wt_diff(self):
4721.2.1 by Vincent Ladeuil
Some test cleamup.
114
        b = self.make_dummy_builder('d').get_branch()
3920.2.10 by Jelmer Vernooij
More work trying to implement a dummy version control system.
115
4721.2.1 by Vincent Ladeuil
Some test cleamup.
116
        dc = b.bzrdir.sprout('dc', force_new_repo=True)
3920.2.20 by Jelmer Vernooij
Fix dpush tests.
117
        self.build_tree_contents([("dc/foofile", "blaaaa")])
3920.2.32 by Jelmer Vernooij
Avoid run_bzr for functions other than the one being tested.
118
        dc_tree = dc.open_workingtree()
3920.2.33 by Jelmer Vernooij
Use branch_builder to create revisions in testsuite.
119
        dc_tree.add("foofile")
120
        newrevid = dc_tree.commit('msg')
3920.2.32 by Jelmer Vernooij
Avoid run_bzr for functions other than the one being tested.
121
3920.2.20 by Jelmer Vernooij
Fix dpush tests.
122
        self.build_tree_contents([("dc/foofile", "blaaaal")])
5283.4.1 by Martin Pool
Deprecate ExternalBase.check_output and update some callers to use scripts
123
        script.run_script(self, '''
124
            $ bzr dpush -d dc d --no-strict
5422.3.2 by Martin Pool
Update existing script tests to not ignore their output
125
            2>Pushed up to revision 2.
5283.4.1 by Martin Pool
Deprecate ExternalBase.check_output and update some callers to use scripts
126
            ''')
3920.2.20 by Jelmer Vernooij
Fix dpush tests.
127
        self.assertFileEqual("blaaaal", "dc/foofile")
4721.2.3 by Vincent Ladeuil
Make all test pass by implement --strict for dpush.
128
        # if the dummy vcs wasn't that dummy we could uncomment the line below
129
        # self.assertFileEqual("blaaaa", "d/foofile")
5283.4.1 by Martin Pool
Deprecate ExternalBase.check_output and update some callers to use scripts
130
        script.run_script(self, '''
131
            $ bzr status dc
132
            modified:
133
              foofile
134
            ''')
3920.2.20 by Jelmer Vernooij
Fix dpush tests.
135
136
    def test_diverged(self):
3920.2.33 by Jelmer Vernooij
Use branch_builder to create revisions in testsuite.
137
        builder = self.make_dummy_builder('d')
138
4721.2.1 by Vincent Ladeuil
Some test cleamup.
139
        b = builder.get_branch()
3920.2.33 by Jelmer Vernooij
Use branch_builder to create revisions in testsuite.
140
4721.2.1 by Vincent Ladeuil
Some test cleamup.
141
        dc = b.bzrdir.sprout('dc', force_new_repo=True)
3920.2.32 by Jelmer Vernooij
Avoid run_bzr for functions other than the one being tested.
142
        dc_tree = dc.open_workingtree()
3920.2.20 by Jelmer Vernooij
Fix dpush tests.
143
144
        self.build_tree_contents([("dc/foo", "bar")])
3920.2.33 by Jelmer Vernooij
Use branch_builder to create revisions in testsuite.
145
        dc_tree.commit('msg1')
3920.2.20 by Jelmer Vernooij
Fix dpush tests.
146
3920.2.33 by Jelmer Vernooij
Use branch_builder to create revisions in testsuite.
147
        builder.build_snapshot('revid2', None,
148
          [('modify', ('fooid', 'blie'))])
3920.2.20 by Jelmer Vernooij
Fix dpush tests.
149
3920.2.36 by Jelmer Vernooij
Fix tests after CommitBuilder changes.
150
        output, error = self.run_bzr("dpush -d dc d", retcode=3)
151
        self.assertEquals(output, "")
3920.2.20 by Jelmer Vernooij
Fix dpush tests.
152
        self.assertContainsRe(error, "have diverged")
4721.2.2 by Vincent Ladeuil
Start testing and implementing --strict for dpush.
153
154
155
class TestDpushStrictMixin(object):
156
4721.2.7 by Vincent Ladeuil
Final tweak.
157
    def setUp(self):
158
        test_foreign.register_dummy_foreign_for_test(self)
4721.2.2 by Vincent Ladeuil
Start testing and implementing --strict for dpush.
159
        # Create an empty branch where we will be able to push
160
        self.foreign = self.make_branch(
4721.2.7 by Vincent Ladeuil
Final tweak.
161
            'to', format=test_foreign.DummyForeignVcsDirFormat())
4721.2.2 by Vincent Ladeuil
Start testing and implementing --strict for dpush.
162
4721.2.6 by Vincent Ladeuil
More agressive test sharing between push and dpush.
163
    def set_config_push_strict(self, value):
4721.2.2 by Vincent Ladeuil
Start testing and implementing --strict for dpush.
164
        # set config var (any of bazaar.conf, locations.conf, branch.conf
165
        # should do)
166
        conf = self.tree.branch.get_config()
167
        conf.set_user_option('dpush_strict', value)
168
169
    _default_command = ['dpush', '../to']
170
171
4721.2.6 by Vincent Ladeuil
More agressive test sharing between push and dpush.
172
class TestDpushStrictWithoutChanges(TestDpushStrictMixin,
173
                                    test_push.TestPushStrictWithoutChanges):
4721.2.2 by Vincent Ladeuil
Start testing and implementing --strict for dpush.
174
175
    def setUp(self):
4721.2.7 by Vincent Ladeuil
Final tweak.
176
        test_push.TestPushStrictWithoutChanges.setUp(self)
177
        TestDpushStrictMixin.setUp(self)
4721.2.2 by Vincent Ladeuil
Start testing and implementing --strict for dpush.
178
4721.2.6 by Vincent Ladeuil
More agressive test sharing between push and dpush.
179
180
class TestDpushStrictWithChanges(TestDpushStrictMixin,
181
                                 test_push.TestPushStrictWithChanges):
4721.2.2 by Vincent Ladeuil
Start testing and implementing --strict for dpush.
182
183
    _changes_type = None # Set by load_tests
184
185
    def setUp(self):
4721.2.7 by Vincent Ladeuil
Final tweak.
186
        test_push.TestPushStrictWithChanges.setUp(self)
187
        TestDpushStrictMixin.setUp(self)
4721.2.2 by Vincent Ladeuil
Start testing and implementing --strict for dpush.
188
4721.2.6 by Vincent Ladeuil
More agressive test sharing between push and dpush.
189
    def test_push_with_revision(self):
190
        raise tests.TestNotApplicable('dpush does not handle --revision')
191