~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

(vila) Fix test failures blocking package builds. (Vincent Ladeuil)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2007, 2008, 2009 Canonical Ltd
 
1
# Copyright (C) 2009-2012 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
18
18
"""Black-box tests for bzr dpush."""
19
19
 
20
20
 
21
 
import os
22
 
 
23
 
from bzrlib.branch import (
24
 
    Branch,
25
 
    InterBranch,
26
 
    )
27
 
from bzrlib.bzrdir import (
28
 
    BzrDirFormat,
29
 
    )
30
 
from bzrlib.foreign import (
31
 
    ForeignBranch,
32
 
    ForeignRepository,
33
 
    )
34
 
from bzrlib.repository import (
35
 
    Repository,
36
 
    )
37
 
from bzrlib.tests.blackbox import (
38
 
    ExternalBase,
39
 
    )
40
 
from bzrlib.tests.test_foreign import (
41
 
    DummyForeignVcsDirFormat,
42
 
    InterToDummyVcsBranch,
43
 
    )
44
 
 
45
 
 
46
 
class TestDpush(ExternalBase):
 
21
from bzrlib import (
 
22
    branch,
 
23
    tests,
 
24
    )
 
25
from bzrlib.tests import (
 
26
    script,
 
27
    test_foreign,
 
28
    )
 
29
from bzrlib.tests.blackbox import test_push
 
30
from bzrlib.tests.scenarios import (
 
31
    load_tests_apply_scenarios,
 
32
    )
 
33
 
 
34
 
 
35
load_tests = load_tests_apply_scenarios
 
36
 
 
37
 
 
38
class TestDpush(tests.TestCaseWithTransport):
47
39
 
48
40
    def setUp(self):
49
 
        BzrDirFormat.register_control_format(DummyForeignVcsDirFormat)
50
 
        InterBranch.register_optimiser(InterToDummyVcsBranch)
51
 
        self.addCleanup(self.unregister_format)
52
41
        super(TestDpush, self).setUp()
53
 
 
54
 
    def unregister_format(self):
55
 
        try:
56
 
            BzrDirFormat.unregister_control_format(DummyForeignVcsDirFormat)
57
 
        except ValueError:
58
 
            pass
59
 
        InterBranch.unregister_optimiser(InterToDummyVcsBranch)
 
42
        test_foreign.register_dummy_foreign_for_test(self)
60
43
 
61
44
    def make_dummy_builder(self, relpath):
62
 
        builder = self.make_branch_builder(relpath, 
63
 
                format=DummyForeignVcsDirFormat())
64
 
        builder.build_snapshot('revid', None, 
 
45
        builder = self.make_branch_builder(
 
46
            relpath, format=test_foreign.DummyForeignVcsDirFormat())
 
47
        builder.build_snapshot('revid', None,
65
48
            [('add', ('', 'TREE_ROOT', 'directory', None)),
66
49
             ('add', ('foo', 'fooid', 'file', 'bar'))])
67
50
        return builder
71
54
        source_tree = self.make_branch_and_tree("dc")
72
55
        output, error = self.run_bzr("dpush -d dc dp", retcode=3)
73
56
        self.assertEquals("", output)
74
 
        self.assertContainsRe(error, 'in the same VCS, lossy push not necessary. Please use regular push.')
 
57
        self.assertContainsRe(error,
 
58
            'in the same VCS, lossy push not necessary. Please use regular '
 
59
            'push.')
75
60
 
76
61
    def test_dpush(self):
77
62
        branch = self.make_dummy_builder('d').get_branch()
80
65
        self.build_tree(("dc/foo", "blaaaa"))
81
66
        dc.open_workingtree().commit('msg')
82
67
 
83
 
        output, error = self.run_bzr("dpush -d dc d")
84
 
        self.assertEquals(error, "Pushed up to revision 2.\n")
85
 
        self.check_output("", "status dc")
 
68
        script.run_script(self, """
 
69
            $ bzr dpush -d dc d
 
70
            2>Doing on-the-fly conversion from DummyForeignVcsRepositoryFormat() to RepositoryFormat2a().
 
71
            2>This may take some time. Upgrade the repositories to the same format for better performance.
 
72
            2>Pushed up to revision 2.
 
73
            $ bzr status dc
 
74
            """)
86
75
 
87
76
    def test_dpush_new(self):
88
 
        branch = self.make_dummy_builder('d').get_branch()
 
77
        b = self.make_dummy_builder('d').get_branch()
89
78
 
90
 
        dc = branch.bzrdir.sprout('dc', force_new_repo=True)
 
79
        dc = b.bzrdir.sprout('dc', force_new_repo=True)
91
80
        self.build_tree_contents([("dc/foofile", "blaaaa")])
92
81
        dc_tree = dc.open_workingtree()
93
82
        dc_tree.add("foofile")
94
83
        dc_tree.commit("msg")
95
84
 
96
 
        self.check_output("", "dpush -d dc d")
97
 
        self.check_output("2\n", "revno dc")
98
 
        self.check_output("", "status dc")
 
85
        script.run_script(self, '''
 
86
            $ bzr dpush -d dc d
 
87
            2>Doing on-the-fly conversion from DummyForeignVcsRepositoryFormat() to RepositoryFormat2a().
 
88
            2>This may take some time. Upgrade the repositories to the same format for better performance.
 
89
            2>Pushed up to revision 2.
 
90
            $ bzr revno dc
 
91
            2
 
92
            $ bzr status dc
 
93
            ''')
99
94
 
100
95
    def test_dpush_wt_diff(self):
101
 
        branch = self.make_dummy_builder('d').get_branch()
 
96
        b = self.make_dummy_builder('d').get_branch()
102
97
 
103
 
        dc = branch.bzrdir.sprout('dc', force_new_repo=True)
 
98
        dc = b.bzrdir.sprout('dc', force_new_repo=True)
104
99
        self.build_tree_contents([("dc/foofile", "blaaaa")])
105
100
        dc_tree = dc.open_workingtree()
106
101
        dc_tree.add("foofile")
107
102
        newrevid = dc_tree.commit('msg')
108
103
 
109
104
        self.build_tree_contents([("dc/foofile", "blaaaal")])
110
 
        self.check_output("", "dpush -d dc d")
 
105
        script.run_script(self, '''
 
106
            $ bzr dpush -d dc d --no-strict
 
107
            2>Doing on-the-fly conversion from DummyForeignVcsRepositoryFormat() to RepositoryFormat2a().
 
108
            2>This may take some time. Upgrade the repositories to the same format for better performance.
 
109
            2>Pushed up to revision 2.
 
110
            ''')
111
111
        self.assertFileEqual("blaaaal", "dc/foofile")
112
 
        self.check_output('modified:\n  foofile\n', "status dc")
 
112
        # if the dummy vcs wasn't that dummy we could uncomment the line below
 
113
        # self.assertFileEqual("blaaaa", "d/foofile")
 
114
        script.run_script(self, '''
 
115
            $ bzr status dc
 
116
            modified:
 
117
              foofile
 
118
            ''')
113
119
 
114
120
    def test_diverged(self):
115
121
        builder = self.make_dummy_builder('d')
116
122
 
117
 
        branch = builder.get_branch()
 
123
        b = builder.get_branch()
118
124
 
119
 
        dc = branch.bzrdir.sprout('dc', force_new_repo=True)
 
125
        dc = b.bzrdir.sprout('dc', force_new_repo=True)
120
126
        dc_tree = dc.open_workingtree()
121
127
 
122
128
        self.build_tree_contents([("dc/foo", "bar")])
128
134
        output, error = self.run_bzr("dpush -d dc d", retcode=3)
129
135
        self.assertEquals(output, "")
130
136
        self.assertContainsRe(error, "have diverged")
 
137
 
 
138
 
 
139
class TestDpushStrictMixin(object):
 
140
 
 
141
    def setUp(self):
 
142
        test_foreign.register_dummy_foreign_for_test(self)
 
143
        # Create an empty branch where we will be able to push
 
144
        self.foreign = self.make_branch(
 
145
            'to', format=test_foreign.DummyForeignVcsDirFormat())
 
146
 
 
147
    def set_config_push_strict(self, value):
 
148
        br = branch.Branch.open('local')
 
149
        br.get_config_stack().set('dpush_strict', value)
 
150
 
 
151
    _default_command = ['dpush', '../to']
 
152
 
 
153
 
 
154
class TestDpushStrictWithoutChanges(TestDpushStrictMixin,
 
155
                                    test_push.TestPushStrictWithoutChanges):
 
156
 
 
157
    def setUp(self):
 
158
        test_push.TestPushStrictWithoutChanges.setUp(self)
 
159
        TestDpushStrictMixin.setUp(self)
 
160
 
 
161
 
 
162
class TestDpushStrictWithChanges(TestDpushStrictMixin,
 
163
                                 test_push.TestPushStrictWithChanges):
 
164
 
 
165
    scenarios = test_push.strict_push_change_scenarios
 
166
 
 
167
    _changes_type = None # Set by load_tests
 
168
 
 
169
    def setUp(self):
 
170
        test_push.TestPushStrictWithChanges.setUp(self)
 
171
        TestDpushStrictMixin.setUp(self)
 
172
 
 
173
    def test_push_with_revision(self):
 
174
        raise tests.TestNotApplicable('dpush does not handle --revision')