~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: John Arbash Meinel
  • Date: 2011-05-11 11:35:28 UTC
  • mto: This revision was merged to the branch mainline in revision 5851.
  • Revision ID: john@arbash-meinel.com-20110511113528-qepibuwxicjrbb2h
Break compatibility with python <2.6.

This includes auditing the code for places where we were doing
explicit 'sys.version' checks and removing them as appropriate.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005 Canonical Ltd
2
 
# -*- coding: utf-8 -*-
3
 
# vim: encoding=utf-8
 
1
# Copyright (C) 2005-2010 Canonical Ltd
4
2
#
5
3
# This program is free software; you can redistribute it and/or modify
6
4
# it under the terms of the GNU General Public License as published by
14
12
#
15
13
# You should have received a copy of the GNU General Public License
16
14
# along with this program; if not, write to the Free Software
17
 
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
16
 
19
17
"""Black-box tests for bzr missing."""
20
18
 
28
26
 
29
27
class TestMissing(TestCaseWithTransport):
30
28
 
 
29
    def assertMessages(self, out, must_have=(), must_not_have=()):
 
30
        """Check if commit messages are in or not in the output"""
 
31
        for m in must_have:
 
32
            self.assertContainsRe(out, r'\nmessage:\n  %s\n' % m)
 
33
        for m in must_not_have:
 
34
            self.assertNotContainsRe(out, r'\nmessage:\n  %s\n' % m)
 
35
 
 
36
    def test_missing_quiet(self):
 
37
        # <https://bugs.launchpad.net/bzr/+bug/284748>
 
38
        # create a source branch
 
39
        #
 
40
        # XXX: This still needs a test that missing is quiet when there are
 
41
        # missing revisions.
 
42
        a_tree = self.make_branch_and_tree('.')
 
43
        self.build_tree_contents([('a', 'initial\n')])
 
44
        a_tree.add('a')
 
45
        a_tree.commit(message='initial')
 
46
 
 
47
        out, err = self.run_bzr('missing -q .')
 
48
        self.assertEqual('', out)
 
49
        self.assertEqual('', err)
 
50
 
31
51
    def test_missing(self):
32
52
        missing = "You are missing 1 revision(s):"
33
53
 
43
63
        b_tree.commit(message='more')
44
64
 
45
65
        # run missing in a against b
46
 
        # this should not require missing to take out a write lock on a 
 
66
        # this should not require missing to take out a write lock on a
47
67
        # or b. So we take a write lock on both to test that at the same
48
68
        # time. This may let the test pass while the default branch is an
49
69
        # os-locking branch, but it will trigger failures with lockdir based
77
97
        lines2 = self.run_bzr('missing ../b --mine-only', retcode=1)[0]
78
98
        lines2 = lines2.splitlines()
79
99
        self.assertEqual(lines, lines2)
80
 
        lines3 = self.run_bzr('missing ../b --theirs-only', retcode=1)[0]
81
 
        lines3 = lines3.splitlines()
82
 
        self.assertEqual(0, len(lines3))
 
100
        lines3 = self.run_bzr('missing ../b --theirs-only', retcode=0)[0]
 
101
        self.assertEqualDiff('Other branch is up to date.\n', lines3)
83
102
 
84
 
        # relative to a, missing the 'merge' commit 
 
103
        # relative to a, missing the 'merge' commit
85
104
        os.chdir('../b')
86
105
        lines = self.run_bzr('missing ../a', retcode=1)[0].splitlines()
87
106
        self.assertEqual(missing, lines[0])
89
108
        lines2 = self.run_bzr('missing ../a --theirs-only', retcode=1)[0]
90
109
        lines2 = lines2.splitlines()
91
110
        self.assertEqual(lines, lines2)
92
 
        lines3 = self.run_bzr('missing ../a --mine-only', retcode=1)[0]
93
 
        lines3 = lines3.splitlines()
94
 
        self.assertEqual(0, len(lines3))
 
111
        lines3 = self.run_bzr('missing ../a --mine-only', retcode=0)[0]
 
112
        self.assertEqualDiff('This branch is up to date.\n', lines3)
95
113
        lines4 = self.run_bzr('missing ../a --short', retcode=1)[0]
96
114
        lines4 = lines4.splitlines()
97
115
        self.assertEqual(4, len(lines4))
109
127
        self.assertEqual("modified:", lines8[-2])
110
128
        self.assertEqual("  a", lines8[-1])
111
129
 
 
130
        os.chdir('../a')
 
131
        self.assertEqualDiff('Other branch is up to date.\n',
 
132
                             self.run_bzr('missing ../b --theirs-only')[0])
 
133
 
112
134
        # after a pull we're back on track
113
135
        b_tree.pull(a_branch)
114
 
        self.assertEqual("Branches are up to date.\n", self.run_bzr('missing ../a')[0])
 
136
        self.assertEqualDiff("Branches are up to date.\n",
 
137
                             self.run_bzr('missing ../b')[0])
 
138
        os.chdir('../b')
 
139
        self.assertEqualDiff('Branches are up to date.\n',
 
140
                             self.run_bzr('missing ../a')[0])
 
141
        # If you supply mine or theirs you only know one side is up to date
 
142
        self.assertEqualDiff('This branch is up to date.\n',
 
143
                             self.run_bzr('missing ../a --mine-only')[0])
 
144
        self.assertEqualDiff('Other branch is up to date.\n',
 
145
                             self.run_bzr('missing ../a --theirs-only')[0])
 
146
 
 
147
    def test_missing_filtered(self):
 
148
        # create a source branch
 
149
        a_tree = self.make_branch_and_tree('a')
 
150
        self.build_tree_contents([('a/a', 'initial\n')])
 
151
        a_tree.add('a')
 
152
        a_tree.commit(message='r1')
 
153
        # clone and add differing revisions
 
154
        b_tree = a_tree.bzrdir.sprout('b').open_workingtree()
 
155
 
 
156
        for i in range(2, 6):
 
157
            a_tree.commit(message='a%d' % i)
 
158
            b_tree.commit(message='b%d' % i)
 
159
 
 
160
        os.chdir('a')
 
161
        # local
 
162
        out,err = self.run_bzr('missing ../b --my-revision 3', retcode=1)
 
163
        self.assertMessages(out, ('a3', 'b2', 'b3', 'b4', 'b5'), ('a2', 'a4'))
 
164
 
 
165
        out,err = self.run_bzr('missing ../b --my-revision 3..4', retcode=1)
 
166
        self.assertMessages(out, ('a3', 'a4'), ('a2', 'a5'))
 
167
 
 
168
        #remote
 
169
        out,err = self.run_bzr('missing ../b -r 3', retcode=1)
 
170
        self.assertMessages(out, ('a2', 'a3', 'a4', 'a5', 'b3'), ('b2', 'b4'))
 
171
 
 
172
        out,err = self.run_bzr('missing ../b -r 3..4', retcode=1)
 
173
        self.assertMessages(out, ('b3', 'b4'), ('b2', 'b5'))
 
174
 
 
175
        #both
 
176
        out,err = self.run_bzr('missing ../b --my-revision 3..4 -r 3..4',
 
177
            retcode=1)
 
178
        self.assertMessages(out, ('a3', 'a4', 'b3', 'b4'),
 
179
            ('a2', 'a5', 'b2', 'b5'))
115
180
 
116
181
    def test_missing_check_last_location(self):
117
182
        # check that last location shown as filepath not file URL
131
196
 
132
197
        # check last location
133
198
        lines, err = self.run_bzr('missing', working_dir='../b')
134
 
        self.assertEquals('Using last location: %s\n'
 
199
        self.assertEquals('Using saved parent location: %s\n'
135
200
                          'Branches are up to date.\n' % location,
136
201
                          lines)
137
202
        self.assertEquals('', err)
 
203
 
 
204
    def test_missing_directory(self):
 
205
        """Test --directory option"""
 
206
 
 
207
        # create a source branch
 
208
        a_tree = self.make_branch_and_tree('a')
 
209
        self.build_tree_contents([('a/a', 'initial\n')])
 
210
        a_tree.add('a')
 
211
        a_tree.commit(message='initial')
 
212
 
 
213
        # clone and add a differing revision
 
214
        b_tree = a_tree.bzrdir.sprout('b').open_workingtree()
 
215
        self.build_tree_contents([('b/a', 'initial\nmore\n')])
 
216
        b_tree.commit(message='more')
 
217
        
 
218
        out2, err2 = self.run_bzr('missing --directory a b', retcode=1)
 
219
        os.chdir('a')
 
220
        out1, err1 = self.run_bzr('missing ../b', retcode=1)
 
221
        self.assertEqualDiff(out1, out2)
 
222
        self.assertEqualDiff(err1, err2)