~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2009-04-10 19:37:20 UTC
  • mfrom: (4222.3.15 username)
  • Revision ID: pqm@pqm.ubuntu.com-20090410193720-nyej7ft1k2yoyhui
(Jelmer) Prompt for user names for http if they are not in the
        configuration.

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
 
    test_foreign,
33
 
    )
34
 
from bzrlib.tests.blackbox import test_push
35
 
 
36
 
 
37
 
def load_tests(standard_tests, module, loader):
38
 
    """Multiply tests for the dpush command."""
39
 
    result = loader.suiteClass()
40
 
 
41
 
    # one for each king of change
42
 
    changes_tests, remaining_tests = tests.split_suite_by_condition(
43
 
        standard_tests, tests.condition_isinstance((
44
 
                TestDpushStrictWithChanges,
45
 
                )))
46
 
    changes_scenarios = [
47
 
        ('uncommitted',
48
 
         dict(_changes_type= '_uncommitted_changes')),
49
 
        ('pending-merges',
50
 
         dict(_changes_type= '_pending_merges')),
51
 
        ('out-of-sync-trees',
52
 
         dict(_changes_type= '_out_of_sync_trees')),
53
 
        ]
54
 
    tests.multiply_tests(changes_tests, changes_scenarios, result)
55
 
    # No parametrization for the remaining tests
56
 
    result.addTests(remaining_tests)
57
 
 
58
 
    return result
59
 
 
60
 
 
61
 
class TestDpush(blackbox.ExternalBase):
 
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):
62
45
 
63
46
    def setUp(self):
 
47
        BzrDirFormat.register_control_format(DummyForeignVcsDirFormat)
 
48
        self.addCleanup(self.unregister_format)
64
49
        super(TestDpush, self).setUp()
65
 
        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
66
56
 
67
57
    def make_dummy_builder(self, relpath):
68
 
        builder = self.make_branch_builder(
69
 
            relpath, format=test_foreign.DummyForeignVcsDirFormat())
70
 
        builder.build_snapshot('revid', None,
 
58
        builder = self.make_branch_builder(relpath, 
 
59
                format=DummyForeignVcsDirFormat())
 
60
        builder.build_snapshot('revid', None, 
71
61
            [('add', ('', 'TREE_ROOT', 'directory', None)),
72
62
             ('add', ('foo', 'fooid', 'file', 'bar'))])
73
63
        return builder
77
67
        source_tree = self.make_branch_and_tree("dc")
78
68
        output, error = self.run_bzr("dpush -d dc dp", retcode=3)
79
69
        self.assertEquals("", output)
80
 
        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')
81
71
 
82
72
    def test_dpush(self):
83
73
        branch = self.make_dummy_builder('d').get_branch()
86
76
        self.build_tree(("dc/foo", "blaaaa"))
87
77
        dc.open_workingtree().commit('msg')
88
78
 
89
 
        output, error = self.run_bzr("dpush -d dc d")
90
 
        self.assertEquals(error, "Pushed up to revision 2.\n")
 
79
        self.check_output("", "dpush -d dc d")
91
80
        self.check_output("", "status dc")
92
81
 
93
82
    def test_dpush_new(self):
94
 
        b = self.make_dummy_builder('d').get_branch()
 
83
        branch = self.make_dummy_builder('d').get_branch()
95
84
 
96
 
        dc = b.bzrdir.sprout('dc', force_new_repo=True)
 
85
        dc = branch.bzrdir.sprout('dc', force_new_repo=True)
97
86
        self.build_tree_contents([("dc/foofile", "blaaaa")])
98
87
        dc_tree = dc.open_workingtree()
99
88
        dc_tree.add("foofile")
104
93
        self.check_output("", "status dc")
105
94
 
106
95
    def test_dpush_wt_diff(self):
107
 
        b = self.make_dummy_builder('d').get_branch()
 
96
        branch = self.make_dummy_builder('d').get_branch()
108
97
 
109
 
        dc = b.bzrdir.sprout('dc', force_new_repo=True)
 
98
        dc = branch.bzrdir.sprout('dc', force_new_repo=True)
110
99
        self.build_tree_contents([("dc/foofile", "blaaaa")])
111
100
        dc_tree = dc.open_workingtree()
112
101
        dc_tree.add("foofile")
113
102
        newrevid = dc_tree.commit('msg')
114
103
 
115
104
        self.build_tree_contents([("dc/foofile", "blaaaal")])
116
 
        self.check_output("", "dpush -d dc d --no-strict")
 
105
        self.check_output("", "dpush -d dc d")
117
106
        self.assertFileEqual("blaaaal", "dc/foofile")
118
 
        # if the dummy vcs wasn't that dummy we could uncomment the line below
119
 
        # self.assertFileEqual("blaaaa", "d/foofile")
120
107
        self.check_output('modified:\n  foofile\n', "status dc")
121
108
 
122
109
    def test_diverged(self):
123
110
        builder = self.make_dummy_builder('d')
124
111
 
125
 
        b = builder.get_branch()
 
112
        branch = builder.get_branch()
126
113
 
127
 
        dc = b.bzrdir.sprout('dc', force_new_repo=True)
 
114
        dc = branch.bzrdir.sprout('dc', force_new_repo=True)
128
115
        dc_tree = dc.open_workingtree()
129
116
 
130
117
        self.build_tree_contents([("dc/foo", "bar")])
136
123
        output, error = self.run_bzr("dpush -d dc d", retcode=3)
137
124
        self.assertEquals(output, "")
138
125
        self.assertContainsRe(error, "have diverged")
139
 
 
140
 
 
141
 
class TestDpushStrictMixin(object):
142
 
 
143
 
    def setUp(self):
144
 
        test_foreign.register_dummy_foreign_for_test(self)
145
 
        # Create an empty branch where we will be able to push
146
 
        self.foreign = self.make_branch(
147
 
            'to', format=test_foreign.DummyForeignVcsDirFormat())
148
 
 
149
 
    def set_config_push_strict(self, value):
150
 
        # set config var (any of bazaar.conf, locations.conf, branch.conf
151
 
        # should do)
152
 
        conf = self.tree.branch.get_config()
153
 
        conf.set_user_option('dpush_strict', value)
154
 
 
155
 
    _default_command = ['dpush', '../to']
156
 
 
157
 
 
158
 
class TestDpushStrictWithoutChanges(TestDpushStrictMixin,
159
 
                                    test_push.TestPushStrictWithoutChanges):
160
 
 
161
 
    def setUp(self):
162
 
        test_push.TestPushStrictWithoutChanges.setUp(self)
163
 
        TestDpushStrictMixin.setUp(self)
164
 
 
165
 
 
166
 
class TestDpushStrictWithChanges(TestDpushStrictMixin,
167
 
                                 test_push.TestPushStrictWithChanges):
168
 
 
169
 
    _changes_type = None # Set by load_tests
170
 
 
171
 
    def setUp(self):
172
 
        test_push.TestPushStrictWithChanges.setUp(self)
173
 
        TestDpushStrictMixin.setUp(self)
174
 
 
175
 
    def test_push_with_revision(self):
176
 
        raise tests.TestNotApplicable('dpush does not handle --revision')
177