~bzr-pqm/bzr/bzr.dev

5557.1.7 by John Arbash Meinel
Merge in the bzr.dev 5582
1
# Copyright (C) 2009, 2010, 2011 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
4721.2.1 by Vincent Ladeuil
Some test cleamup.
21
from bzrlib import (
22
    tests,
3920.2.36 by Jelmer Vernooij
Fix tests after CommitBuilder changes.
23
    )
4721.2.1 by Vincent Ladeuil
Some test cleamup.
24
from bzrlib.tests import (
5283.4.1 by Martin Pool
Deprecate ExternalBase.check_output and update some callers to use scripts
25
    script,
4721.2.1 by Vincent Ladeuil
Some test cleamup.
26
    test_foreign,
27
    )
4721.2.6 by Vincent Ladeuil
More agressive test sharing between push and dpush.
28
from bzrlib.tests.blackbox import test_push
5559.2.2 by Martin Pool
Change to using standard load_tests_apply_scenarios.
29
from bzrlib.tests.scenarios import (
30
    load_tests_apply_scenarios,
31
    )
32
33
34
load_tests = load_tests_apply_scenarios
4721.2.2 by Vincent Ladeuil
Start testing and implementing --strict for dpush.
35
36
5283.4.1 by Martin Pool
Deprecate ExternalBase.check_output and update some callers to use scripts
37
class TestDpush(tests.TestCaseWithTransport):
3920.2.10 by Jelmer Vernooij
More work trying to implement a dummy version control system.
38
39
    def setUp(self):
40
        super(TestDpush, self).setUp()
4721.2.5 by Vincent Ladeuil
Some refactoring.
41
        test_foreign.register_dummy_foreign_for_test(self)
3920.2.10 by Jelmer Vernooij
More work trying to implement a dummy version control system.
42
3920.2.33 by Jelmer Vernooij
Use branch_builder to create revisions in testsuite.
43
    def make_dummy_builder(self, relpath):
4721.2.1 by Vincent Ladeuil
Some test cleamup.
44
        builder = self.make_branch_builder(
45
            relpath, format=test_foreign.DummyForeignVcsDirFormat())
46
        builder.build_snapshot('revid', None,
3920.2.33 by Jelmer Vernooij
Use branch_builder to create revisions in testsuite.
47
            [('add', ('', 'TREE_ROOT', 'directory', None)),
48
             ('add', ('foo', 'fooid', 'file', 'bar'))])
49
        return builder
50
3920.2.18 by Jelmer Vernooij
make sure dpush between native branches fails.
51
    def test_dpush_native(self):
3920.2.30 by Jelmer Vernooij
Review from John.
52
        target_tree = self.make_branch_and_tree("dp")
53
        source_tree = self.make_branch_and_tree("dc")
3920.2.36 by Jelmer Vernooij
Fix tests after CommitBuilder changes.
54
        output, error = self.run_bzr("dpush -d dc dp", retcode=3)
55
        self.assertEquals("", output)
5777.6.3 by Jelmer Vernooij
Fix line formatting.
56
        self.assertContainsRe(error,
57
            'in the same VCS, lossy push not necessary. Please use regular '
58
            'push.')
3920.2.18 by Jelmer Vernooij
make sure dpush between native branches fails.
59
3920.2.10 by Jelmer Vernooij
More work trying to implement a dummy version control system.
60
    def test_dpush(self):
3920.2.33 by Jelmer Vernooij
Use branch_builder to create revisions in testsuite.
61
        branch = self.make_dummy_builder('d').get_branch()
3920.2.10 by Jelmer Vernooij
More work trying to implement a dummy version control system.
62
3920.2.33 by Jelmer Vernooij
Use branch_builder to create revisions in testsuite.
63
        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.
64
        self.build_tree(("dc/foo", "blaaaa"))
3920.2.32 by Jelmer Vernooij
Avoid run_bzr for functions other than the one being tested.
65
        dc.open_workingtree().commit('msg')
66
5283.4.1 by Martin Pool
Deprecate ExternalBase.check_output and update some callers to use scripts
67
        script.run_script(self, """
68
            $ bzr dpush -d dc d
5777.6.11 by Jelmer Vernooij
Fix revision id generation.
69
            2>Doing on-the-fly conversion from DummyForeignVcsRepositoryFormat() to RepositoryFormat2a().
70
            2>This may take some time. Upgrade the repositories to the same format for better performance.
5283.4.1 by Martin Pool
Deprecate ExternalBase.check_output and update some callers to use scripts
71
            2>Pushed up to revision 2.
72
            $ bzr status dc
73
            """)
3920.2.10 by Jelmer Vernooij
More work trying to implement a dummy version control system.
74
75
    def test_dpush_new(self):
4721.2.1 by Vincent Ladeuil
Some test cleamup.
76
        b = self.make_dummy_builder('d').get_branch()
3920.2.33 by Jelmer Vernooij
Use branch_builder to create revisions in testsuite.
77
4721.2.1 by Vincent Ladeuil
Some test cleamup.
78
        dc = b.bzrdir.sprout('dc', force_new_repo=True)
3920.2.36 by Jelmer Vernooij
Fix tests after CommitBuilder changes.
79
        self.build_tree_contents([("dc/foofile", "blaaaa")])
3920.2.32 by Jelmer Vernooij
Avoid run_bzr for functions other than the one being tested.
80
        dc_tree = dc.open_workingtree()
3920.2.33 by Jelmer Vernooij
Use branch_builder to create revisions in testsuite.
81
        dc_tree.add("foofile")
82
        dc_tree.commit("msg")
3920.2.32 by Jelmer Vernooij
Avoid run_bzr for functions other than the one being tested.
83
5283.4.1 by Martin Pool
Deprecate ExternalBase.check_output and update some callers to use scripts
84
        script.run_script(self, '''
85
            $ bzr dpush -d dc d
5777.6.11 by Jelmer Vernooij
Fix revision id generation.
86
            2>Doing on-the-fly conversion from DummyForeignVcsRepositoryFormat() to RepositoryFormat2a().
87
            2>This may take some time. Upgrade the repositories to the same format for better performance.
5422.3.2 by Martin Pool
Update existing script tests to not ignore their output
88
            2>Pushed up to revision 2.
5283.4.1 by Martin Pool
Deprecate ExternalBase.check_output and update some callers to use scripts
89
            $ bzr revno dc
90
            2
91
            $ bzr status dc
92
            ''')
3920.2.10 by Jelmer Vernooij
More work trying to implement a dummy version control system.
93
94
    def test_dpush_wt_diff(self):
4721.2.1 by Vincent Ladeuil
Some test cleamup.
95
        b = self.make_dummy_builder('d').get_branch()
3920.2.10 by Jelmer Vernooij
More work trying to implement a dummy version control system.
96
4721.2.1 by Vincent Ladeuil
Some test cleamup.
97
        dc = b.bzrdir.sprout('dc', force_new_repo=True)
3920.2.20 by Jelmer Vernooij
Fix dpush tests.
98
        self.build_tree_contents([("dc/foofile", "blaaaa")])
3920.2.32 by Jelmer Vernooij
Avoid run_bzr for functions other than the one being tested.
99
        dc_tree = dc.open_workingtree()
3920.2.33 by Jelmer Vernooij
Use branch_builder to create revisions in testsuite.
100
        dc_tree.add("foofile")
101
        newrevid = dc_tree.commit('msg')
3920.2.32 by Jelmer Vernooij
Avoid run_bzr for functions other than the one being tested.
102
3920.2.20 by Jelmer Vernooij
Fix dpush tests.
103
        self.build_tree_contents([("dc/foofile", "blaaaal")])
5283.4.1 by Martin Pool
Deprecate ExternalBase.check_output and update some callers to use scripts
104
        script.run_script(self, '''
105
            $ bzr dpush -d dc d --no-strict
5777.6.11 by Jelmer Vernooij
Fix revision id generation.
106
            2>Doing on-the-fly conversion from DummyForeignVcsRepositoryFormat() to RepositoryFormat2a().
107
            2>This may take some time. Upgrade the repositories to the same format for better performance.
5422.3.2 by Martin Pool
Update existing script tests to not ignore their output
108
            2>Pushed up to revision 2.
5283.4.1 by Martin Pool
Deprecate ExternalBase.check_output and update some callers to use scripts
109
            ''')
3920.2.20 by Jelmer Vernooij
Fix dpush tests.
110
        self.assertFileEqual("blaaaal", "dc/foofile")
4721.2.3 by Vincent Ladeuil
Make all test pass by implement --strict for dpush.
111
        # if the dummy vcs wasn't that dummy we could uncomment the line below
112
        # self.assertFileEqual("blaaaa", "d/foofile")
5283.4.1 by Martin Pool
Deprecate ExternalBase.check_output and update some callers to use scripts
113
        script.run_script(self, '''
114
            $ bzr status dc
115
            modified:
116
              foofile
117
            ''')
3920.2.20 by Jelmer Vernooij
Fix dpush tests.
118
119
    def test_diverged(self):
3920.2.33 by Jelmer Vernooij
Use branch_builder to create revisions in testsuite.
120
        builder = self.make_dummy_builder('d')
121
4721.2.1 by Vincent Ladeuil
Some test cleamup.
122
        b = builder.get_branch()
3920.2.33 by Jelmer Vernooij
Use branch_builder to create revisions in testsuite.
123
4721.2.1 by Vincent Ladeuil
Some test cleamup.
124
        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.
125
        dc_tree = dc.open_workingtree()
3920.2.20 by Jelmer Vernooij
Fix dpush tests.
126
127
        self.build_tree_contents([("dc/foo", "bar")])
3920.2.33 by Jelmer Vernooij
Use branch_builder to create revisions in testsuite.
128
        dc_tree.commit('msg1')
3920.2.20 by Jelmer Vernooij
Fix dpush tests.
129
3920.2.33 by Jelmer Vernooij
Use branch_builder to create revisions in testsuite.
130
        builder.build_snapshot('revid2', None,
131
          [('modify', ('fooid', 'blie'))])
3920.2.20 by Jelmer Vernooij
Fix dpush tests.
132
3920.2.36 by Jelmer Vernooij
Fix tests after CommitBuilder changes.
133
        output, error = self.run_bzr("dpush -d dc d", retcode=3)
134
        self.assertEquals(output, "")
3920.2.20 by Jelmer Vernooij
Fix dpush tests.
135
        self.assertContainsRe(error, "have diverged")
4721.2.2 by Vincent Ladeuil
Start testing and implementing --strict for dpush.
136
137
138
class TestDpushStrictMixin(object):
139
4721.2.7 by Vincent Ladeuil
Final tweak.
140
    def setUp(self):
141
        test_foreign.register_dummy_foreign_for_test(self)
4721.2.2 by Vincent Ladeuil
Start testing and implementing --strict for dpush.
142
        # Create an empty branch where we will be able to push
143
        self.foreign = self.make_branch(
4721.2.7 by Vincent Ladeuil
Final tweak.
144
            'to', format=test_foreign.DummyForeignVcsDirFormat())
4721.2.2 by Vincent Ladeuil
Start testing and implementing --strict for dpush.
145
4721.2.6 by Vincent Ladeuil
More agressive test sharing between push and dpush.
146
    def set_config_push_strict(self, value):
4721.2.2 by Vincent Ladeuil
Start testing and implementing --strict for dpush.
147
        # set config var (any of bazaar.conf, locations.conf, branch.conf
148
        # should do)
149
        conf = self.tree.branch.get_config()
150
        conf.set_user_option('dpush_strict', value)
151
152
    _default_command = ['dpush', '../to']
153
154
4721.2.6 by Vincent Ladeuil
More agressive test sharing between push and dpush.
155
class TestDpushStrictWithoutChanges(TestDpushStrictMixin,
156
                                    test_push.TestPushStrictWithoutChanges):
4721.2.2 by Vincent Ladeuil
Start testing and implementing --strict for dpush.
157
158
    def setUp(self):
4721.2.7 by Vincent Ladeuil
Final tweak.
159
        test_push.TestPushStrictWithoutChanges.setUp(self)
160
        TestDpushStrictMixin.setUp(self)
4721.2.2 by Vincent Ladeuil
Start testing and implementing --strict for dpush.
161
4721.2.6 by Vincent Ladeuil
More agressive test sharing between push and dpush.
162
163
class TestDpushStrictWithChanges(TestDpushStrictMixin,
164
                                 test_push.TestPushStrictWithChanges):
4721.2.2 by Vincent Ladeuil
Start testing and implementing --strict for dpush.
165
5559.2.2 by Martin Pool
Change to using standard load_tests_apply_scenarios.
166
    scenarios = test_push.strict_push_change_scenarios
167
4721.2.2 by Vincent Ladeuil
Start testing and implementing --strict for dpush.
168
    _changes_type = None # Set by load_tests
169
170
    def setUp(self):
4721.2.7 by Vincent Ladeuil
Final tweak.
171
        test_push.TestPushStrictWithChanges.setUp(self)
172
        TestDpushStrictMixin.setUp(self)
4721.2.2 by Vincent Ladeuil
Start testing and implementing --strict for dpush.
173
4721.2.6 by Vincent Ladeuil
More agressive test sharing between push and dpush.
174
    def test_push_with_revision(self):
175
        raise tests.TestNotApplicable('dpush does not handle --revision')