/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
1
# Copyright (C) 2009-2012, 2016 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
6622.1.29 by Jelmer Vernooij
Fix some more tests.
18
"""Black-box tests for brz dpush."""
3920.2.7 by Jelmer Vernooij
Add comments about dummy vcs.
19
3920.2.36 by Jelmer Vernooij
Fix tests after CommitBuilder changes.
20
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
21
from breezy import (
6404.6.1 by Vincent Ladeuil
Tests passing for a first rough version of a cached branch config store. The changes here are too invasive and several parallel proposals have been made.
22
    branch,
4721.2.1 by Vincent Ladeuil
Some test cleamup.
23
    tests,
3920.2.36 by Jelmer Vernooij
Fix tests after CommitBuilder changes.
24
    )
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
25
from breezy.tests import (
5283.4.1 by Martin Pool
Deprecate ExternalBase.check_output and update some callers to use scripts
26
    script,
4721.2.1 by Vincent Ladeuil
Some test cleamup.
27
    test_foreign,
28
    )
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
29
from breezy.tests.blackbox import test_push
30
from breezy.tests.scenarios import (
5559.2.2 by Martin Pool
Change to using standard load_tests_apply_scenarios.
31
    load_tests_apply_scenarios,
32
    )
33
34
35
load_tests = load_tests_apply_scenarios
4721.2.2 by Vincent Ladeuil
Start testing and implementing --strict for dpush.
36
37
5283.4.1 by Martin Pool
Deprecate ExternalBase.check_output and update some callers to use scripts
38
class TestDpush(tests.TestCaseWithTransport):
3920.2.10 by Jelmer Vernooij
More work trying to implement a dummy version control system.
39
40
    def setUp(self):
41
        super(TestDpush, self).setUp()
4721.2.5 by Vincent Ladeuil
Some refactoring.
42
        test_foreign.register_dummy_foreign_for_test(self)
3920.2.10 by Jelmer Vernooij
More work trying to implement a dummy version control system.
43
3920.2.33 by Jelmer Vernooij
Use branch_builder to create revisions in testsuite.
44
    def make_dummy_builder(self, relpath):
4721.2.1 by Vincent Ladeuil
Some test cleamup.
45
        builder = self.make_branch_builder(
46
            relpath, format=test_foreign.DummyForeignVcsDirFormat())
6816.2.1 by Jelmer Vernooij
Migrate some build_snapshot code over to having revision_id as keyword argument.
47
        builder.build_snapshot(None,
3920.2.33 by Jelmer Vernooij
Use branch_builder to create revisions in testsuite.
48
            [('add', ('', 'TREE_ROOT', 'directory', None)),
6816.2.1 by Jelmer Vernooij
Migrate some build_snapshot code over to having revision_id as keyword argument.
49
             ('add', ('foo', 'fooid', 'file', 'bar'))],
50
            revision_id='revid')
3920.2.33 by Jelmer Vernooij
Use branch_builder to create revisions in testsuite.
51
        return builder
52
3920.2.18 by Jelmer Vernooij
make sure dpush between native branches fails.
53
    def test_dpush_native(self):
3920.2.30 by Jelmer Vernooij
Review from John.
54
        target_tree = self.make_branch_and_tree("dp")
55
        source_tree = self.make_branch_and_tree("dc")
3920.2.36 by Jelmer Vernooij
Fix tests after CommitBuilder changes.
56
        output, error = self.run_bzr("dpush -d dc dp", retcode=3)
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
57
        self.assertEqual("", output)
5777.6.3 by Jelmer Vernooij
Fix line formatting.
58
        self.assertContainsRe(error,
59
            'in the same VCS, lossy push not necessary. Please use regular '
60
            'push.')
3920.2.18 by Jelmer Vernooij
make sure dpush between native branches fails.
61
3920.2.10 by Jelmer Vernooij
More work trying to implement a dummy version control system.
62
    def test_dpush(self):
3920.2.33 by Jelmer Vernooij
Use branch_builder to create revisions in testsuite.
63
        branch = self.make_dummy_builder('d').get_branch()
3920.2.10 by Jelmer Vernooij
More work trying to implement a dummy version control system.
64
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
65
        dc = branch.controldir.sprout('dc', force_new_repo=True)
3920.2.10 by Jelmer Vernooij
More work trying to implement a dummy version control system.
66
        self.build_tree(("dc/foo", "blaaaa"))
3920.2.32 by Jelmer Vernooij
Avoid run_bzr for functions other than the one being tested.
67
        dc.open_workingtree().commit('msg')
68
5283.4.1 by Martin Pool
Deprecate ExternalBase.check_output and update some callers to use scripts
69
        script.run_script(self, """
6622.1.29 by Jelmer Vernooij
Fix some more tests.
70
            $ brz dpush -d dc d
5777.6.11 by Jelmer Vernooij
Fix revision id generation.
71
            2>Doing on-the-fly conversion from DummyForeignVcsRepositoryFormat() to RepositoryFormat2a().
72
            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
73
            2>Pushed up to revision 2.
6622.1.29 by Jelmer Vernooij
Fix some more tests.
74
            $ brz status dc
5283.4.1 by Martin Pool
Deprecate ExternalBase.check_output and update some callers to use scripts
75
            """)
3920.2.10 by Jelmer Vernooij
More work trying to implement a dummy version control system.
76
77
    def test_dpush_new(self):
4721.2.1 by Vincent Ladeuil
Some test cleamup.
78
        b = self.make_dummy_builder('d').get_branch()
3920.2.33 by Jelmer Vernooij
Use branch_builder to create revisions in testsuite.
79
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
80
        dc = b.controldir.sprout('dc', force_new_repo=True)
3920.2.36 by Jelmer Vernooij
Fix tests after CommitBuilder changes.
81
        self.build_tree_contents([("dc/foofile", "blaaaa")])
3920.2.32 by Jelmer Vernooij
Avoid run_bzr for functions other than the one being tested.
82
        dc_tree = dc.open_workingtree()
3920.2.33 by Jelmer Vernooij
Use branch_builder to create revisions in testsuite.
83
        dc_tree.add("foofile")
84
        dc_tree.commit("msg")
3920.2.32 by Jelmer Vernooij
Avoid run_bzr for functions other than the one being tested.
85
5283.4.1 by Martin Pool
Deprecate ExternalBase.check_output and update some callers to use scripts
86
        script.run_script(self, '''
6622.1.29 by Jelmer Vernooij
Fix some more tests.
87
            $ brz dpush -d dc d
5777.6.11 by Jelmer Vernooij
Fix revision id generation.
88
            2>Doing on-the-fly conversion from DummyForeignVcsRepositoryFormat() to RepositoryFormat2a().
89
            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
90
            2>Pushed up to revision 2.
6622.1.29 by Jelmer Vernooij
Fix some more tests.
91
            $ brz revno dc
5283.4.1 by Martin Pool
Deprecate ExternalBase.check_output and update some callers to use scripts
92
            2
6622.1.29 by Jelmer Vernooij
Fix some more tests.
93
            $ brz status dc
5283.4.1 by Martin Pool
Deprecate ExternalBase.check_output and update some callers to use scripts
94
            ''')
3920.2.10 by Jelmer Vernooij
More work trying to implement a dummy version control system.
95
96
    def test_dpush_wt_diff(self):
4721.2.1 by Vincent Ladeuil
Some test cleamup.
97
        b = self.make_dummy_builder('d').get_branch()
3920.2.10 by Jelmer Vernooij
More work trying to implement a dummy version control system.
98
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
99
        dc = b.controldir.sprout('dc', force_new_repo=True)
3920.2.20 by Jelmer Vernooij
Fix dpush tests.
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
        newrevid = dc_tree.commit('msg')
3920.2.32 by Jelmer Vernooij
Avoid run_bzr for functions other than the one being tested.
104
3920.2.20 by Jelmer Vernooij
Fix dpush tests.
105
        self.build_tree_contents([("dc/foofile", "blaaaal")])
5283.4.1 by Martin Pool
Deprecate ExternalBase.check_output and update some callers to use scripts
106
        script.run_script(self, '''
6622.1.29 by Jelmer Vernooij
Fix some more tests.
107
            $ brz dpush -d dc d --no-strict
5777.6.11 by Jelmer Vernooij
Fix revision id generation.
108
            2>Doing on-the-fly conversion from DummyForeignVcsRepositoryFormat() to RepositoryFormat2a().
109
            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
110
            2>Pushed up to revision 2.
5283.4.1 by Martin Pool
Deprecate ExternalBase.check_output and update some callers to use scripts
111
            ''')
3920.2.20 by Jelmer Vernooij
Fix dpush tests.
112
        self.assertFileEqual("blaaaal", "dc/foofile")
4721.2.3 by Vincent Ladeuil
Make all test pass by implement --strict for dpush.
113
        # if the dummy vcs wasn't that dummy we could uncomment the line below
114
        # self.assertFileEqual("blaaaa", "d/foofile")
5283.4.1 by Martin Pool
Deprecate ExternalBase.check_output and update some callers to use scripts
115
        script.run_script(self, '''
6622.1.29 by Jelmer Vernooij
Fix some more tests.
116
            $ brz status dc
5283.4.1 by Martin Pool
Deprecate ExternalBase.check_output and update some callers to use scripts
117
            modified:
118
              foofile
119
            ''')
3920.2.20 by Jelmer Vernooij
Fix dpush tests.
120
121
    def test_diverged(self):
3920.2.33 by Jelmer Vernooij
Use branch_builder to create revisions in testsuite.
122
        builder = self.make_dummy_builder('d')
123
4721.2.1 by Vincent Ladeuil
Some test cleamup.
124
        b = builder.get_branch()
3920.2.33 by Jelmer Vernooij
Use branch_builder to create revisions in testsuite.
125
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
126
        dc = b.controldir.sprout('dc', force_new_repo=True)
3920.2.32 by Jelmer Vernooij
Avoid run_bzr for functions other than the one being tested.
127
        dc_tree = dc.open_workingtree()
3920.2.20 by Jelmer Vernooij
Fix dpush tests.
128
129
        self.build_tree_contents([("dc/foo", "bar")])
3920.2.33 by Jelmer Vernooij
Use branch_builder to create revisions in testsuite.
130
        dc_tree.commit('msg1')
3920.2.20 by Jelmer Vernooij
Fix dpush tests.
131
6816.2.1 by Jelmer Vernooij
Migrate some build_snapshot code over to having revision_id as keyword argument.
132
        builder.build_snapshot(None,
133
          [('modify', ('fooid', 'blie'))], revision_id='revid2')
3920.2.20 by Jelmer Vernooij
Fix dpush tests.
134
3920.2.36 by Jelmer Vernooij
Fix tests after CommitBuilder changes.
135
        output, error = self.run_bzr("dpush -d dc d", retcode=3)
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
136
        self.assertEqual(output, "")
3920.2.20 by Jelmer Vernooij
Fix dpush tests.
137
        self.assertContainsRe(error, "have diverged")
4721.2.2 by Vincent Ladeuil
Start testing and implementing --strict for dpush.
138
139
140
class TestDpushStrictMixin(object):
141
4721.2.7 by Vincent Ladeuil
Final tweak.
142
    def setUp(self):
143
        test_foreign.register_dummy_foreign_for_test(self)
4721.2.2 by Vincent Ladeuil
Start testing and implementing --strict for dpush.
144
        # Create an empty branch where we will be able to push
145
        self.foreign = self.make_branch(
4721.2.7 by Vincent Ladeuil
Final tweak.
146
            'to', format=test_foreign.DummyForeignVcsDirFormat())
4721.2.2 by Vincent Ladeuil
Start testing and implementing --strict for dpush.
147
4721.2.6 by Vincent Ladeuil
More agressive test sharing between push and dpush.
148
    def set_config_push_strict(self, value):
6404.6.1 by Vincent Ladeuil
Tests passing for a first rough version of a cached branch config store. The changes here are too invasive and several parallel proposals have been made.
149
        br = branch.Branch.open('local')
6404.6.7 by Vincent Ladeuil
Change set/remove to require a lock for the branch config files.
150
        br.get_config_stack().set('dpush_strict', value)
4721.2.2 by Vincent Ladeuil
Start testing and implementing --strict for dpush.
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')