26
26
it's normally invoked.
31
from bzrlib.selftest import TestCaseInTempDir, BzrTestBase
32
from bzrlib.branch import Branch
33
from bzrlib.commands import run_bzr
36
class ExternalBase(TestCaseInTempDir):
37
def runbzr(self, args, retcode=0,backtick=False):
29
# this code was previously in testbzr
31
from unittest import TestCase
32
from bzrlib.selftest import TestBase, InTempDir
36
class ExternalBase(InTempDir):
37
def runbzr(self, args, retcode=0):
40
from subprocess import call
41
except ImportError, e:
38
45
if isinstance(args, basestring):
39
46
args = args.split()
42
return self.backtick(['python', self.BZRPATH,] + args,
45
return self.runcmd(['python', self.BZRPATH,] + args,
49
class TestCommands(ExternalBase):
51
def test_help_commands(self):
48
return self.runcmd(['python', self.BZRPATH,] + args,
53
class TestVersion(ExternalBase):
55
# output is intentionally passed through to stdout so that we
56
# can see the version being tested
57
self.runbzr(['version'])
61
class HelpCommands(ExternalBase):
52
63
self.runbzr('--help')
53
64
self.runbzr('help')
54
65
self.runbzr('help commands')
55
66
self.runbzr('help help')
56
67
self.runbzr('commit -h')
58
def test_init_branch(self):
70
class InitBranch(ExternalBase):
59
73
self.runbzr(['init'])
61
def test_whoami(self):
77
class UserIdentity(ExternalBase):
62
79
# this should always identify something, if only "john@localhost"
63
80
self.runbzr("whoami")
64
81
self.runbzr("whoami --email")
66
self.assertEquals(self.runbzr("whoami --email",
67
backtick=True).count('@'), 1)
69
def test_whoami_branch(self):
70
"""branch specific user identity works."""
72
f = file('.bzr/email', 'wt')
73
f.write('Branch Identity <branch@identi.ty>')
75
whoami = self.runbzr("whoami",backtick=True)
76
whoami_email = self.runbzr("whoami --email",backtick=True)
77
self.assertTrue(whoami.startswith('Branch Identity <branch@identi.ty>'))
78
self.assertTrue(whoami_email.startswith('branch@identi.ty'))
80
def test_invalid_commands(self):
82
self.assertEquals(self.backtick("bzr whoami --email").count('@'),
86
class InvalidCommands(ExternalBase):
81
88
self.runbzr("pants", retcode=1)
82
89
self.runbzr("--pants off", retcode=1)
83
90
self.runbzr("diff --message foo", retcode=1)
85
def test_empty_commit(self):
94
class EmptyCommit(ExternalBase):
86
96
self.runbzr("init")
87
97
self.build_tree(['hello.txt'])
88
98
self.runbzr("commit -m empty", retcode=1)
89
99
self.runbzr("add hello.txt")
90
100
self.runbzr("commit -m added")
92
def test_ignore_patterns(self):
104
class IgnorePatterns(ExternalBase):
93
106
from bzrlib.branch import Branch
95
108
b = Branch('.', init=True)
120
133
self.runbzr('ignore garh')
121
134
self.assertEquals(list(b.unknowns()), [])
122
135
assert file('.bzrignore', 'rb').read() == '*.blah\ngarh\n'
124
def test_revert(self):
128
file('hello', 'wt').write('foo')
129
self.runbzr('add hello')
130
self.runbzr('commit -m setup hello')
132
file('goodbye', 'wt').write('baz')
133
self.runbzr('add goodbye')
134
self.runbzr('commit -m setup goodbye')
136
file('hello', 'wt').write('bar')
137
file('goodbye', 'wt').write('qux')
138
self.runbzr('revert hello')
139
self.check_file_contents('hello', 'foo')
140
self.check_file_contents('goodbye', 'qux')
141
self.runbzr('revert')
142
self.check_file_contents('goodbye', 'baz')
144
os.mkdir('revertdir')
145
self.runbzr('add revertdir')
146
self.runbzr('commit -m f')
147
os.rmdir('revertdir')
148
self.runbzr('revert')
150
def skipped_test_mv_modes(self):
151
"""Test two modes of operation for mv"""
152
from bzrlib.branch import Branch
153
b = Branch('.', init=True)
154
self.build_tree(['a', 'c', 'subdir/'])
155
self.run_bzr('mv', 'a', 'b')
156
self.run_bzr('mv', 'b', 'subdir')
157
self.run_bzr('mv', 'subdir/b', 'a')
158
self.run_bzr('mv', 'a', 'b', 'subdir')
159
self.run_bzr('mv', 'subdir/a', 'subdir/newa')
161
def test_main_version(self):
162
"""Check output from version command and master option is reasonable"""
163
# output is intentionally passed through to stdout so that we
164
# can see the version being tested
165
output = self.runbzr('version', backtick=1)
166
self.log('bzr version output:')
168
self.assert_(output.startswith('bzr (bazaar-ng) '))
169
self.assertNotEqual(output.index('Canonical'), -1)
170
# make sure --version is consistent
171
tmp_output = self.runbzr('--version', backtick=1)
172
self.log('bzr --version output:')
174
self.assertEquals(output, tmp_output)
176
def example_branch(test):
178
file('hello', 'wt').write('foo')
179
test.runbzr('add hello')
180
test.runbzr('commit -m setup hello')
181
file('goodbye', 'wt').write('baz')
182
test.runbzr('add goodbye')
183
test.runbzr('commit -m setup goodbye')
185
def test_revert(self):
186
self.example_branch()
187
file('hello', 'wt').write('bar')
188
file('goodbye', 'wt').write('qux')
189
self.runbzr('revert hello')
190
self.check_file_contents('hello', 'foo')
191
self.check_file_contents('goodbye', 'qux')
192
self.runbzr('revert')
193
self.check_file_contents('goodbye', 'baz')
195
def test_merge(self):
196
from bzrlib.branch import Branch
202
self.example_branch()
204
self.runbzr('branch a b')
206
file('goodbye', 'wt').write('quux')
207
self.runbzr(['commit', '-m', "more u's are always good"])
210
file('hello', 'wt').write('quuux')
211
# We can't merge when there are in-tree changes
212
self.runbzr('merge ../b', retcode=1)
213
self.runbzr(['commit', '-m', "Like an epidemic of u's"])
214
self.runbzr('merge ../b')
215
self.check_file_contents('goodbye', 'quux')
216
# Merging a branch pulls its revision into the tree
219
a.get_revision_xml(b.last_patch())
221
self.log('pending merges: %s', a.pending_merges())
222
# assert a.pending_merges() == [b.last_patch()], "Assertion %s %s" \
223
# % (a.pending_merges(), b.last_patch())
226
def test_add_reports(self):
227
"""add command prints the names of added files."""
228
b = Branch('.', init=True)
229
self.build_tree(['top.txt', 'dir/', 'dir/sub.txt'])
231
from cStringIO import StringIO
234
ret = self.apply_redirected(None, out, None,
237
self.assertEquals(ret, 0)
239
# the ordering is not defined at the moment
240
results = sorted(out.getvalue().rstrip('\n').split('\n'))
241
self.assertEquals(['added dir',
247
140
class OldTests(ExternalBase):
248
"""old tests moved from ./testbzr."""
141
# old tests moved from ./testbzr
251
143
from os import chdir, mkdir
252
144
from os.path import exists
318
assert os.path.exists('branch1')
319
assert not os.path.exists('branch2')
320
# Can't create a branch if it already exists
321
runbzr('branch branch1', retcode=1)
322
# Can't create a branch if its parent doesn't exist
323
runbzr('branch /unlikely/to/exist', retcode=1)
324
runbzr('branch branch1 branch2')
325
assert exists('branch2')
326
assert exists('branch2/sub1')
327
assert exists('branch2/sub1/hello.txt')
329
runbzr('branch --revision 0 branch1 branch3')
330
assert not exists('branch3/sub1/hello.txt')
331
runbzr('branch --revision 0..3 branch1 branch4', retcode=1)
335
runbzr('pull', retcode=1)
336
runbzr('pull ../branch2')
339
runbzr('commit --unchanged -m empty')
341
chdir('../../branch2')
343
runbzr('commit --unchanged -m empty')
345
runbzr('commit --unchanged -m empty')
346
runbzr('pull', retcode=1)
349
progress('status after remove')
350
mkdir('status-after-remove')
351
# see mail from William Dodé, 2005-05-25
352
# $ bzr init; touch a; bzr add a; bzr commit -m "add a"
353
# * looking for changes...
358
# bzr: local variable 'kind' referenced before assignment
359
# at /vrac/python/bazaar-ng/bzrlib/diff.py:286 in compare_trees()
360
# see ~/.bzr.log for debug information
361
chdir('status-after-remove')
363
file('a', 'w').write('foo')
365
runbzr(['commit', '-m', 'add a'])
373
progress("recursive and non-recursive add")
378
fp = os.path.join('foo', 'test.txt')
382
runbzr('add --no-recurse foo')
383
runbzr('file-id foo')
384
runbzr('file-id ' + fp, 1) # not versioned yet
385
runbzr('commit -m add-dir-only')
387
self.runbzr('file-id ' + fp, 1) # still not versioned
389
self.runbzr('add foo')
390
self.runbzr('file-id ' + fp)
391
self.runbzr('commit -m add-sub-file')
397
class RevertCommand(ExternalBase):
401
file('hello', 'wt').write('foo')
402
self.runbzr('add hello')
403
self.runbzr('commit -m setup hello')
405
file('goodbye', 'wt').write('baz')
406
self.runbzr('add goodbye')
407
self.runbzr('commit -m setup goodbye')
409
file('hello', 'wt').write('bar')
410
file('goodbye', 'wt').write('qux')
411
self.runbzr('revert hello')
412
self.check_file_contents('hello', 'foo')
413
self.check_file_contents('goodbye', 'qux')
414
self.runbzr('revert')
415
self.check_file_contents('goodbye', 'baz')