26
26
it's normally invoked.
29
# this code was previously in testbzr
31
from bzrlib.selftest import InTempDir, BzrTestBase
31
from unittest import TestCase
32
from bzrlib.selftest import TestBase, InTempDir
35
36
class ExternalBase(InTempDir):
36
def runbzr(self, args, retcode=0,backtick=False):
37
def runbzr(self, args, retcode=0):
39
40
from subprocess import call
44
45
if isinstance(args, basestring):
45
46
args = args.split()
48
return self.backtick(['python', self.BZRPATH,] + args,
51
return self.runcmd(['python', self.BZRPATH,] + args,
56
class MvCommand(BzrTestBase):
58
"""Test two modes of operation for mv"""
59
b = Branch('.', init=True)
60
self.build_tree(['a', 'c', 'subdir/'])
61
self.run_bzr('mv', 'a', 'b')
62
self.run_bzr('mv', 'b', 'subdir')
63
self.run_bzr('mv', 'subdir/b', 'a')
64
self.run_bzr('mv', 'a', 'b', 'subdir')
65
self.run_bzr('mv', 'subdir/a', 'subdir/newa')
69
class TestVersion(BzrTestBase):
70
"""Check output from version command and master option is reasonable"""
48
return self.runcmd(['python', self.BZRPATH,] + args,
53
class TestVersion(ExternalBase):
72
55
# output is intentionally passed through to stdout so that we
73
56
# can see the version being tested
74
from cStringIO import StringIO
77
sys.stdout = tmp_out = StringIO()
79
self.run_bzr('version')
83
output = tmp_out.getvalue()
84
self.log('bzr version output:')
87
self.assert_(output.startswith('bzr (bazaar-ng) '))
88
self.assertNotEqual(output.index('Canonical'), -1)
90
# make sure --version is consistent
92
sys.stdout = tmp_out = StringIO()
94
self.run_bzr('--version')
98
self.log('bzr --version output:')
99
self.log(tmp_out.getvalue())
101
self.assertEquals(output, tmp_out.getvalue())
57
self.runbzr(['version'])
107
61
class HelpCommands(ExternalBase):
119
73
self.runbzr(['init'])
122
77
class UserIdentity(ExternalBase):
123
78
def runTest(self):
124
79
# this should always identify something, if only "john@localhost"
125
80
self.runbzr("whoami")
126
81
self.runbzr("whoami --email")
128
self.assertEquals(self.runbzr("whoami --email",
129
backtick=True).count('@'), 1)
131
class UserIdentityBranch(ExternalBase):
133
# tests branch specific user identity
135
f = file('.bzr/email', 'wt')
136
f.write('Branch Identity <branch@identi.ty>')
138
whoami = self.runbzr("whoami",backtick=True)
139
whoami_email = self.runbzr("whoami --email",backtick=True)
140
self.assertTrue(whoami.startswith('Branch Identity <branch@identi.ty>'))
141
self.assertTrue(whoami_email.startswith('branch@identi.ty'))
82
self.assertEquals(self.backtick("bzr whoami --email").count('@'),
144
86
class InvalidCommands(ExternalBase):
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')
373
397
class RevertCommand(ExternalBase):
374
398
def runTest(self):
375
399
self.runbzr('init')