~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: 2010-01-14 18:12:58 UTC
  • mfrom: (4960.1.2 various)
  • Revision ID: pqm@pqm.ubuntu.com-20100114181258-ey8bgiolululzosu
(vila) Fix brittle test

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2009, 2010, 2011 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
18
18
"""Black-box tests for bzr dpush."""
19
19
 
20
20
 
 
21
import os
 
22
 
21
23
from bzrlib import (
 
24
    branch,
 
25
    bzrdir,
 
26
    foreign,
22
27
    tests,
 
28
    workingtree,
23
29
    )
24
30
from bzrlib.tests import (
25
 
    script,
 
31
    blackbox,
26
32
    test_foreign,
27
33
    )
28
34
from bzrlib.tests.blackbox import test_push
29
 
from bzrlib.tests.scenarios import (
30
 
    load_tests_apply_scenarios,
31
 
    )
32
 
 
33
 
 
34
 
load_tests = load_tests_apply_scenarios
35
 
 
36
 
 
37
 
class TestDpush(tests.TestCaseWithTransport):
 
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):
38
62
 
39
63
    def setUp(self):
40
64
        super(TestDpush, self).setUp()
53
77
        source_tree = self.make_branch_and_tree("dc")
54
78
        output, error = self.run_bzr("dpush -d dc dp", retcode=3)
55
79
        self.assertEquals("", output)
56
 
        self.assertContainsRe(error,
57
 
            'in the same VCS, lossy push not necessary. Please use regular '
58
 
            'push.')
 
80
        self.assertContainsRe(error, 'in the same VCS, lossy push not necessary. Please use regular push.')
59
81
 
60
82
    def test_dpush(self):
61
83
        branch = self.make_dummy_builder('d').get_branch()
64
86
        self.build_tree(("dc/foo", "blaaaa"))
65
87
        dc.open_workingtree().commit('msg')
66
88
 
67
 
        script.run_script(self, """
68
 
            $ bzr dpush -d dc d
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.
71
 
            2>Pushed up to revision 2.
72
 
            $ bzr status dc
73
 
            """)
 
89
        output, error = self.run_bzr("dpush -d dc d")
 
90
        self.assertEquals(error, "Pushed up to revision 2.\n")
 
91
        self.check_output("", "status dc")
74
92
 
75
93
    def test_dpush_new(self):
76
94
        b = self.make_dummy_builder('d').get_branch()
81
99
        dc_tree.add("foofile")
82
100
        dc_tree.commit("msg")
83
101
 
84
 
        script.run_script(self, '''
85
 
            $ bzr dpush -d dc d
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.
88
 
            2>Pushed up to revision 2.
89
 
            $ bzr revno dc
90
 
            2
91
 
            $ bzr status dc
92
 
            ''')
 
102
        self.check_output("", "dpush -d dc d")
 
103
        self.check_output("2\n", "revno dc")
 
104
        self.check_output("", "status dc")
93
105
 
94
106
    def test_dpush_wt_diff(self):
95
107
        b = self.make_dummy_builder('d').get_branch()
101
113
        newrevid = dc_tree.commit('msg')
102
114
 
103
115
        self.build_tree_contents([("dc/foofile", "blaaaal")])
104
 
        script.run_script(self, '''
105
 
            $ bzr dpush -d dc d --no-strict
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.
108
 
            2>Pushed up to revision 2.
109
 
            ''')
 
116
        self.check_output("", "dpush -d dc d --no-strict")
110
117
        self.assertFileEqual("blaaaal", "dc/foofile")
111
118
        # if the dummy vcs wasn't that dummy we could uncomment the line below
112
119
        # self.assertFileEqual("blaaaa", "d/foofile")
113
 
        script.run_script(self, '''
114
 
            $ bzr status dc
115
 
            modified:
116
 
              foofile
117
 
            ''')
 
120
        self.check_output('modified:\n  foofile\n', "status dc")
118
121
 
119
122
    def test_diverged(self):
120
123
        builder = self.make_dummy_builder('d')
150
153
        conf.set_user_option('dpush_strict', value)
151
154
 
152
155
    _default_command = ['dpush', '../to']
 
156
    _default_pushed_revid = False # Doesn't aplly for dpush
 
157
 
 
158
    def assertPushSucceeds(self, args, pushed_revid=None):
 
159
        self.run_bzr(self._default_command + args,
 
160
                     working_dir=self._default_wd)
 
161
        if pushed_revid is None:
 
162
            # dpush change the revids, so we need to get back to it
 
163
            branch_from = branch.Branch.open(self._default_wd)
 
164
            pushed_revid = branch_from.last_revision()
 
165
        branch_to = branch.Branch.open('to')
 
166
        repo_to = branch_to.repository
 
167
        self.assertTrue(repo_to.has_revision(pushed_revid))
 
168
        self.assertEqual(branch_to.last_revision(), pushed_revid)
 
169
 
153
170
 
154
171
 
155
172
class TestDpushStrictWithoutChanges(TestDpushStrictMixin,
163
180
class TestDpushStrictWithChanges(TestDpushStrictMixin,
164
181
                                 test_push.TestPushStrictWithChanges):
165
182
 
166
 
    scenarios = test_push.strict_push_change_scenarios
167
 
 
168
183
    _changes_type = None # Set by load_tests
169
184
 
170
185
    def setUp(self):
173
188
 
174
189
    def test_push_with_revision(self):
175
190
        raise tests.TestNotApplicable('dpush does not handle --revision')
 
191