~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/selftest/blackbox.py

  • Committer: Robert Collins
  • Date: 2005-10-17 11:56:54 UTC
  • mfrom: (1185.16.59)
  • Revision ID: robertc@robertcollins.net-20051017115654-662239e1587524a8
mergeĀ fromĀ martin.

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
# along with this program; if not, write to the Free Software
16
16
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17
17
 
18
 
# Mr. Smoketoomuch: I'm sorry?
19
 
# Mr. Bounder: You'd better cut down a little then.
20
 
# Mr. Smoketoomuch: Oh, I see! Smoke too much so I'd better cut down a little
21
 
#                   then!
22
18
 
23
19
"""Black-box tests for bzr.
24
20
 
28
24
"""
29
25
 
30
26
 
31
 
# XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
32
 
# Note: Please don't add new tests here, it's too big and bulky.  Instead add
33
 
# them into small suites in bzrlib.tests.blackbox.test_FOO for the particular
34
 
# UI command/aspect that is being tested.
35
 
 
36
 
 
37
27
from cStringIO import StringIO
38
28
import os
39
29
import re
44
34
from bzrlib.clone import copy_branch
45
35
from bzrlib.errors import BzrCommandError
46
36
from bzrlib.osutils import has_symlinks
47
 
from bzrlib.tests.HTTPTestUtil import TestCaseWithWebserver
48
 
from bzrlib.tests.blackbox import ExternalBase
 
37
from bzrlib.selftest import TestCaseInTempDir, BzrTestBase
 
38
from bzrlib.selftest.HTTPTestUtil import TestCaseWithWebserver
 
39
 
 
40
 
 
41
class ExternalBase(TestCaseInTempDir):
 
42
 
 
43
    def runbzr(self, args, retcode=0, backtick=False):
 
44
        if isinstance(args, basestring):
 
45
            args = args.split()
 
46
 
 
47
        if backtick:
 
48
            return self.run_bzr_captured(args, retcode=retcode)[0]
 
49
        else:
 
50
            return self.run_bzr_captured(args, retcode=retcode)
 
51
 
49
52
 
50
53
class TestCommands(ExternalBase):
51
54
 
59
62
    def test_init_branch(self):
60
63
        self.runbzr(['init'])
61
64
 
62
 
        # Can it handle subdirectories as well?
63
 
        self.runbzr('init subdir1')
64
 
        self.assert_(os.path.exists('subdir1'))
65
 
        self.assert_(os.path.exists('subdir1/.bzr'))
66
 
 
67
 
        self.runbzr('init subdir2/nothere', retcode=3)
68
 
        
69
 
        os.mkdir('subdir2')
70
 
        self.runbzr('init subdir2')
71
 
        self.runbzr('init subdir2', retcode=3)
72
 
 
73
 
        self.runbzr('init subdir2/subsubdir1')
74
 
        self.assert_(os.path.exists('subdir2/subsubdir1/.bzr'))
75
 
 
76
65
    def test_whoami(self):
77
66
        # this should always identify something, if only "john@localhost"
78
67
        self.runbzr("whoami")
104
93
        if bzr_email is not None:
105
94
            os.environ['BZREMAIL'] = bzr_email
106
95
 
107
 
    def test_nick_command(self):
108
 
        """bzr nick for viewing, setting nicknames"""
109
 
        os.mkdir('me.dev')
110
 
        os.chdir('me.dev')
111
 
        self.runbzr('init')
112
 
        nick = self.runbzr("nick",backtick=True)
113
 
        self.assertEqual(nick, 'me.dev\n')
114
 
        nick = self.runbzr("nick moo")
115
 
        nick = self.runbzr("nick",backtick=True)
116
 
        self.assertEqual(nick, 'moo\n')
117
 
 
118
 
 
119
96
    def test_invalid_commands(self):
120
 
        self.runbzr("pants", retcode=3)
121
 
        self.runbzr("--pants off", retcode=3)
122
 
        self.runbzr("diff --message foo", retcode=3)
 
97
        self.runbzr("pants", retcode=1)
 
98
        self.runbzr("--pants off", retcode=1)
 
99
        self.runbzr("diff --message foo", retcode=1)
123
100
 
124
101
    def test_empty_commit(self):
125
102
        self.runbzr("init")
126
103
        self.build_tree(['hello.txt'])
127
 
        self.runbzr("commit -m empty", retcode=3)
 
104
        self.runbzr("commit -m empty", retcode=1)
128
105
        self.runbzr("add hello.txt")
129
 
        self.runbzr("commit -m added")       
 
106
        self.runbzr("commit -m added")
130
107
 
131
108
    def test_empty_commit_message(self):
132
109
        self.runbzr("init")
133
110
        file('foo.c', 'wt').write('int main() {}')
134
111
        self.runbzr(['add', 'foo.c'])
135
 
        self.runbzr(["commit", "-m", ""] , retcode=3) 
136
 
 
137
 
    def test_remove_deleted(self):
138
 
        self.runbzr("init")
139
 
        self.build_tree(['a'])
140
 
        self.runbzr(['add', 'a'])
141
 
        self.runbzr(['commit', '-m', 'added a'])
142
 
        os.unlink('a')
143
 
        self.runbzr(['remove', 'a'])
144
 
 
145
 
    def test_other_branch_commit(self):
146
 
        # this branch is to ensure consistent behaviour, whether we're run
147
 
        # inside a branch, or not.
148
 
        os.mkdir('empty_branch')
149
 
        os.chdir('empty_branch')
150
 
        self.runbzr('init')
151
 
        os.mkdir('branch')
152
 
        os.chdir('branch')
153
 
        self.runbzr('init')
154
 
        file('foo.c', 'wt').write('int main() {}')
155
 
        file('bar.c', 'wt').write('int main() {}')
156
 
        os.chdir('..')
157
 
        self.runbzr(['add', 'branch/foo.c'])
158
 
        self.runbzr(['add', 'branch'])
159
 
        # can't commit files in different trees; sane error
160
 
        self.runbzr('commit -m newstuff branch/foo.c .', retcode=3)
161
 
        self.runbzr('commit -m newstuff branch/foo.c')
162
 
        self.runbzr('commit -m newstuff branch')
163
 
        self.runbzr('commit -m newstuff branch', retcode=3)
 
112
        self.runbzr(["commit", "-m", ""] , retcode=1) 
164
113
 
165
114
    def test_ignore_patterns(self):
166
115
        from bzrlib.branch import Branch
167
 
        Branch.initialize('.')
168
 
        self.assertEquals(self.capture('unknowns'), '')
 
116
        
 
117
        b = Branch.initialize('.')
 
118
        self.assertEquals(list(b.unknowns()), [])
169
119
 
170
120
        file('foo.tmp', 'wt').write('tmp files are ignored')
171
 
        self.assertEquals(self.capture('unknowns'), '')
 
121
        self.assertEquals(list(b.unknowns()), [])
 
122
        assert self.capture('unknowns') == ''
172
123
 
173
124
        file('foo.c', 'wt').write('int main() {}')
174
 
        self.assertEquals(self.capture('unknowns'), 'foo.c\n')
 
125
        self.assertEquals(list(b.unknowns()), ['foo.c'])
 
126
        assert self.capture('unknowns') == 'foo.c\n'
175
127
 
176
128
        self.runbzr(['add', 'foo.c'])
177
 
        self.assertEquals(self.capture('unknowns'), '')
 
129
        assert self.capture('unknowns') == ''
178
130
 
179
131
        # 'ignore' works when creating the .bzignore file
180
132
        file('foo.blah', 'wt').write('blah')
181
 
        self.assertEquals(self.capture('unknowns'), 'foo.blah\n')
 
133
        self.assertEquals(list(b.unknowns()), ['foo.blah'])
182
134
        self.runbzr('ignore *.blah')
183
 
        self.assertEquals(self.capture('unknowns'), '')
184
 
        self.assertEquals(file('.bzrignore', 'rU').read(), '*.blah\n')
 
135
        self.assertEquals(list(b.unknowns()), [])
 
136
        assert file('.bzrignore', 'rU').read() == '*.blah\n'
185
137
 
186
138
        # 'ignore' works when then .bzrignore file already exists
187
139
        file('garh', 'wt').write('garh')
188
 
        self.assertEquals(self.capture('unknowns'), 'garh\n')
 
140
        self.assertEquals(list(b.unknowns()), ['garh'])
 
141
        assert self.capture('unknowns') == 'garh\n'
189
142
        self.runbzr('ignore garh')
190
 
        self.assertEquals(self.capture('unknowns'), '')
191
 
        self.assertEquals(file('.bzrignore', 'rU').read(), '*.blah\ngarh\n')
 
143
        self.assertEquals(list(b.unknowns()), [])
 
144
        assert file('.bzrignore', 'rU').read() == '*.blah\ngarh\n'
192
145
 
193
146
    def test_revert(self):
194
147
        self.runbzr('init')
237
190
        self.runbzr('revert')
238
191
        os.chdir('..')
239
192
 
240
 
    def test_status(self):
241
 
        self.runbzr("init")
242
 
        self.build_tree(['hello.txt'])
243
 
        result = self.runbzr("status")
244
 
        self.assert_("unknown:\n  hello.txt\n" in result, result)
245
 
        self.runbzr("add hello.txt")
246
 
        result = self.runbzr("status")
247
 
        self.assert_("added:\n  hello.txt\n" in result, result)
248
 
        self.runbzr("commit -m added")
249
 
        result = self.runbzr("status -r 0..1")
250
 
        self.assert_("added:\n  hello.txt\n" in result, result)
251
 
        self.build_tree(['world.txt'])
252
 
        result = self.runbzr("status -r 0")
253
 
        self.assert_("added:\n  hello.txt\n" \
254
 
                     "unknown:\n  world.txt\n" in result, result)
255
193
 
256
194
    def test_mv_modes(self):
257
195
        """Test two modes of operation for mv"""
296
234
        self.runbzr('export ../latest')
297
235
        self.assertEqual(file('../latest/goodbye', 'rt').read(), 'baz')
298
236
        self.runbzr('export ../first -r 1')
299
 
        self.assert_(not os.path.exists('../first/goodbye'))
 
237
        assert not os.path.exists('../first/goodbye')
300
238
        self.assertEqual(file('../first/hello', 'rt').read(), 'foo')
301
239
        self.runbzr('export ../first.gz -r 1')
302
240
        self.assertEqual(file('../first.gz/hello', 'rt').read(), 'foo')
303
241
        self.runbzr('export ../first.bz2 -r 1')
304
242
        self.assertEqual(file('../first.bz2/hello', 'rt').read(), 'foo')
305
 
 
 
243
        self.runbzr('export ../first.tar -r 1')
 
244
        assert os.path.isfile('../first.tar')
306
245
        from tarfile import TarFile
307
 
        self.runbzr('export ../first.tar -r 1')
308
 
        self.assert_(os.path.isfile('../first.tar'))
309
246
        tf = TarFile('../first.tar')
310
 
        self.assert_('first/hello' in tf.getnames(), tf.getnames())
 
247
        assert 'first/hello' in tf.getnames(), tf.getnames()
311
248
        self.assertEqual(tf.extractfile('first/hello').read(), 'foo')
312
249
        self.runbzr('export ../first.tar.gz -r 1')
313
 
        self.assert_(os.path.isfile('../first.tar.gz'))
 
250
        assert os.path.isfile('../first.tar.gz')
314
251
        self.runbzr('export ../first.tbz2 -r 1')
315
 
        self.assert_(os.path.isfile('../first.tbz2'))
 
252
        assert os.path.isfile('../first.tbz2')
316
253
        self.runbzr('export ../first.tar.bz2 -r 1')
317
 
        self.assert_(os.path.isfile('../first.tar.bz2'))
 
254
        assert os.path.isfile('../first.tar.bz2')
318
255
        self.runbzr('export ../first.tar.tbz2 -r 1')
319
 
        self.assert_(os.path.isfile('../first.tar.tbz2'))
320
 
 
 
256
        assert os.path.isfile('../first.tar.tbz2')
321
257
        from bz2 import BZ2File
322
258
        tf = TarFile('../first.tar.tbz2', 
323
259
                     fileobj=BZ2File('../first.tar.tbz2', 'r'))
324
 
        self.assert_('first.tar/hello' in tf.getnames(), tf.getnames())
 
260
        assert 'first.tar/hello' in tf.getnames(), tf.getnames()
325
261
        self.assertEqual(tf.extractfile('first.tar/hello').read(), 'foo')
326
262
        self.runbzr('export ../first2.tar -r 1 --root pizza')
327
263
        tf = TarFile('../first2.tar')
328
 
        self.assert_('pizza/hello' in tf.getnames(), tf.getnames())
329
 
 
330
 
        from zipfile import ZipFile
331
 
        self.runbzr('export ../first.zip -r 1')
332
 
        self.failUnlessExists('../first.zip')
333
 
        zf = ZipFile('../first.zip')
334
 
        self.assert_('first/hello' in zf.namelist(), zf.namelist())
335
 
        self.assertEqual(zf.read('first/hello'), 'foo')
336
 
 
337
 
        self.runbzr('export ../first2.zip -r 1 --root pizza')
338
 
        zf = ZipFile('../first2.zip')
339
 
        self.assert_('pizza/hello' in zf.namelist(), zf.namelist())
340
 
        
341
 
        self.runbzr('export ../first-zip --format=zip -r 1')
342
 
        zf = ZipFile('../first-zip')
343
 
        self.assert_('first-zip/hello' in zf.namelist(), zf.namelist())
 
264
        assert 'pizza/hello' in tf.getnames(), tf.getnames()
344
265
 
345
266
    def test_diff(self):
346
267
        self.example_branch()
347
268
        file('hello', 'wt').write('hello world!')
348
269
        self.runbzr('commit -m fixing hello')
349
 
        output = self.runbzr('diff -r 2..3', backtick=1, retcode=1)
 
270
        output = self.runbzr('diff -r 2..3', backtick=1)
350
271
        self.assert_('\n+hello world!' in output)
351
 
        output = self.runbzr('diff -r last:3..last:1', backtick=1, retcode=1)
 
272
        output = self.runbzr('diff -r last:3..last:1', backtick=1)
352
273
        self.assert_('\n+baz' in output)
353
 
        file('moo', 'wb').write('moo')
354
 
        self.runbzr('add moo')
355
 
        os.unlink('moo')
356
 
        self.runbzr('diff')
357
274
 
358
275
    def test_diff_branches(self):
359
 
        self.build_tree(['branch1/', 'branch1/file', 'branch2/'], line_endings='binary')
 
276
        self.build_tree(['branch1/', 'branch1/file', 'branch2/'])
360
277
        branch = Branch.initialize('branch1')
361
 
        branch.working_tree().add(['file'])
362
 
        branch.working_tree().commit('add file')
 
278
        branch.add(['file'])
 
279
        branch.commit('add file')
363
280
        copy_branch(branch, 'branch2')
364
 
        print >> open('branch2/file', 'wb'), 'new content'
 
281
        print >> open('branch2/file', 'w'), 'new content'
365
282
        branch2 = Branch.open('branch2')
366
 
        branch2.working_tree().commit('update file')
 
283
        branch2.commit('update file')
367
284
        # should open branch1 and diff against branch2, 
368
 
        output = self.run_bzr_captured(['diff', '-r', 'branch:branch2', 
369
 
                                        'branch1'],
370
 
                                       retcode=1)
 
285
        output = self.run_bzr_captured(['diff', '-r', 'branch:branch2', 'branch1'])
371
286
        self.assertEquals(("=== modified file 'file'\n"
372
 
                           "--- file\t\n"
373
 
                           "+++ file\t\n"
 
287
                           "--- file\n"
 
288
                           "+++ file\n"
374
289
                           "@@ -1,1 +1,1 @@\n"
375
290
                           "-new content\n"
376
291
                           "+contents of branch1/file\n"
377
292
                           "\n", ''), output)
378
 
        output = self.run_bzr_captured(['diff', 'branch2', 'branch1'],
379
 
                                       retcode=1)
380
 
        self.assertEqualDiff(("=== modified file 'file'\n"
381
 
                              "--- file\t\n"
382
 
                              "+++ file\t\n"
383
 
                              "@@ -1,1 +1,1 @@\n"
384
 
                              "-new content\n"
385
 
                              "+contents of branch1/file\n"
386
 
                              "\n", ''), output)
387
 
 
388
293
 
389
294
    def test_branch(self):
390
295
        """Branch from one branch to another."""
393
298
        self.example_branch()
394
299
        os.chdir('..')
395
300
        self.runbzr('branch a b')
396
 
        self.assertFileEqual('b\n', 'b/.bzr/branch-name')
397
301
        self.runbzr('branch a c -r 1')
398
302
        os.chdir('b')
399
303
        self.runbzr('commit -m foo --unchanged')
420
324
        os.chdir('../a')
421
325
        file('hello', 'wt').write('quuux')
422
326
        # We can't merge when there are in-tree changes
423
 
        self.runbzr('merge ../b', retcode=3)
 
327
        self.runbzr('merge ../b', retcode=1)
424
328
        self.runbzr(['commit', '-m', "Like an epidemic of u's"])
425
 
        self.runbzr('merge ../b -r last:1..last:1 --merge-type blooof',
426
 
                    retcode=3)
427
 
        self.runbzr('merge ../b -r last:1..last:1 --merge-type merge3')
428
 
        self.runbzr('revert --no-backup')
429
 
        self.runbzr('merge ../b -r last:1..last:1 --merge-type weave')
430
 
        self.runbzr('revert --no-backup')
431
 
        self.runbzr('merge ../b -r last:1..last:1 --reprocess')
432
 
        self.runbzr('revert --no-backup')
433
 
        self.runbzr('merge ../b -r last:1')
 
329
        self.runbzr('merge ../b')
434
330
        self.check_file_contents('goodbye', 'quux')
435
331
        # Merging a branch pulls its revision into the tree
436
332
        a = Branch.open('.')
437
333
        b = Branch.open('../b')
438
334
        a.get_revision_xml(b.last_revision())
439
 
        self.log('pending merges: %s', a.working_tree().pending_merges())
440
 
        self.assertEquals(a.working_tree().pending_merges(),
441
 
                          [b.last_revision()])
442
 
        self.runbzr('commit -m merged')
443
 
        self.runbzr('merge ../b -r last:1')
444
 
        self.assertEqual(Branch.open('.').working_tree().pending_merges(), [])
 
335
        self.log('pending merges: %s', a.pending_merges())
 
336
        #        assert a.pending_merges() == [b.last_revision()], "Assertion %s %s" \
 
337
        #        % (a.pending_merges(), b.last_patch())
445
338
 
446
339
    def test_merge_with_missing_file(self):
447
340
        """Merge handles missing file conflicts"""
469
362
        print >> file('b.txt', 'ab'), "something"
470
363
        print >> file('sub/c.txt', 'ab'), "something"
471
364
        self.runbzr(('commit', '-m', 'Modified a.txt'))
472
 
        self.runbzr('merge ../a/', retcode=1)
473
 
        self.assert_(os.path.exists('sub/a.txt.THIS'))
474
 
        self.assert_(os.path.exists('sub/a.txt.BASE'))
 
365
        self.runbzr('merge ../a/')
 
366
        assert os.path.exists('sub/a.txt.THIS')
 
367
        assert os.path.exists('sub/a.txt.BASE')
475
368
        os.chdir('../a')
476
 
        self.runbzr('merge ../b/', retcode=1)
477
 
        self.assert_(os.path.exists('sub/a.txt.OTHER'))
478
 
        self.assert_(os.path.exists('sub/a.txt.BASE'))
479
 
 
480
 
    def test_inventory(self):
481
 
        bzr = self.runbzr
482
 
        def output_equals(value, *args):
483
 
            out = self.runbzr(['inventory'] + list(args), backtick=True)
484
 
            self.assertEquals(out, value)
485
 
 
486
 
        bzr('init')
487
 
        open('a', 'wb').write('hello\n')
488
 
        os.mkdir('b')
489
 
 
490
 
        bzr('add a b')
491
 
        bzr('commit -m add')
492
 
 
493
 
        output_equals('a\n', '--kind', 'file')
494
 
        output_equals('b\n', '--kind', 'directory')        
495
 
 
496
 
    def test_ls(self):
497
 
        """Test the abilities of 'bzr ls'"""
498
 
        bzr = self.runbzr
499
 
        def bzrout(*args, **kwargs):
500
 
            kwargs['backtick'] = True
501
 
            return self.runbzr(*args, **kwargs)
502
 
 
503
 
        def ls_equals(value, *args):
504
 
            out = self.runbzr(['ls'] + list(args), backtick=True)
505
 
            self.assertEquals(out, value)
506
 
 
507
 
        bzr('init')
508
 
        open('a', 'wb').write('hello\n')
509
 
 
510
 
        # Can't supply both
511
 
        bzr('ls --verbose --null', retcode=3)
512
 
 
513
 
        ls_equals('a\n')
514
 
        ls_equals('?        a\n', '--verbose')
515
 
        ls_equals('a\n', '--unknown')
516
 
        ls_equals('', '--ignored')
517
 
        ls_equals('', '--versioned')
518
 
        ls_equals('a\n', '--unknown', '--ignored', '--versioned')
519
 
        ls_equals('', '--ignored', '--versioned')
520
 
        ls_equals('a\0', '--null')
521
 
 
522
 
        bzr('add a')
523
 
        ls_equals('V        a\n', '--verbose')
524
 
        bzr('commit -m add')
525
 
        
 
369
        self.runbzr('merge ../b/')
 
370
        assert os.path.exists('sub/a.txt.OTHER')
 
371
        assert os.path.exists('sub/a.txt.BASE')
 
372
 
 
373
    def test_pull(self):
 
374
        """Pull changes from one branch to another."""
 
375
        os.mkdir('a')
 
376
        os.chdir('a')
 
377
 
 
378
        self.example_branch()
 
379
        self.runbzr('pull', retcode=1)
 
380
        self.runbzr('missing', retcode=1)
 
381
        self.runbzr('missing .')
 
382
        self.runbzr('missing')
 
383
        self.runbzr('pull')
 
384
        self.runbzr('pull /', retcode=1)
 
385
        self.runbzr('pull')
 
386
 
 
387
        os.chdir('..')
 
388
        self.runbzr('branch a b')
 
389
        os.chdir('b')
 
390
        self.runbzr('pull')
526
391
        os.mkdir('subdir')
527
 
        ls_equals('V        a\n'
528
 
                  '?        subdir/\n'
529
 
                  , '--verbose')
530
 
        open('subdir/b', 'wb').write('b\n')
531
 
        bzr('add')
532
 
        ls_equals('V        a\n'
533
 
                  'V        subdir/\n'
534
 
                  'V        subdir/b\n'
535
 
                  , '--verbose')
536
 
        bzr('commit -m subdir')
537
 
 
538
 
        ls_equals('a\n'
539
 
                  'subdir\n'
540
 
                  , '--non-recursive')
541
 
 
542
 
        ls_equals('V        a\n'
543
 
                  'V        subdir/\n'
544
 
                  , '--verbose', '--non-recursive')
545
 
 
546
 
        # Check what happens in a sub-directory
547
 
        os.chdir('subdir')
548
 
        ls_equals('b\n')
549
 
        ls_equals('b\0'
550
 
                  , '--null')
551
 
        ls_equals('a\n'
552
 
                  'subdir\n'
553
 
                  'subdir/b\n'
554
 
                  , '--from-root')
555
 
        ls_equals('a\0'
556
 
                  'subdir\0'
557
 
                  'subdir/b\0'
558
 
                  , '--from-root', '--null')
559
 
        ls_equals('a\n'
560
 
                  'subdir\n'
561
 
                  , '--from-root', '--non-recursive')
562
 
 
563
 
        os.chdir('..')
564
 
 
565
 
        # Check what happens when we supply a specific revision
566
 
        ls_equals('a\n', '--revision', '1')
567
 
        ls_equals('V        a\n'
568
 
                  , '--verbose', '--revision', '1')
569
 
 
570
 
        os.chdir('subdir')
571
 
        ls_equals('', '--revision', '1')
572
 
 
573
 
        # Now try to do ignored files.
574
 
        os.chdir('..')
575
 
        open('blah.py', 'wb').write('unknown\n')
576
 
        open('blah.pyo', 'wb').write('ignored\n')
577
 
        ls_equals('a\n'
578
 
                  'blah.py\n'
579
 
                  'blah.pyo\n'
580
 
                  'subdir\n'
581
 
                  'subdir/b\n')
582
 
        ls_equals('V        a\n'
583
 
                  '?        blah.py\n'
584
 
                  'I        blah.pyo\n'
585
 
                  'V        subdir/\n'
586
 
                  'V        subdir/b\n'
587
 
                  , '--verbose')
588
 
        ls_equals('blah.pyo\n'
589
 
                  , '--ignored')
590
 
        ls_equals('blah.py\n'
591
 
                  , '--unknown')
592
 
        ls_equals('a\n'
593
 
                  'subdir\n'
594
 
                  'subdir/b\n'
595
 
                  , '--versioned')
596
 
 
597
 
    def test_pull_verbose(self):
598
 
        """Pull changes from one branch to another and watch the output."""
599
 
 
600
 
        os.mkdir('a')
601
 
        os.chdir('a')
602
 
 
603
 
        bzr = self.runbzr
604
 
        self.example_branch()
605
 
 
606
 
        os.chdir('..')
607
 
        bzr('branch a b')
608
 
        os.chdir('b')
609
 
        open('b', 'wb').write('else\n')
610
 
        bzr('add b')
611
 
        bzr(['commit', '-m', 'added b'])
612
 
 
 
392
        self.runbzr('add subdir')
 
393
        self.runbzr('commit -m blah --unchanged')
613
394
        os.chdir('../a')
614
 
        out = bzr('pull --verbose ../b', backtick=True)
615
 
        self.failIfEqual(out.find('Added Revisions:'), -1)
616
 
        self.failIfEqual(out.find('message:\n  added b'), -1)
617
 
        self.failIfEqual(out.find('added b'), -1)
618
 
 
619
 
        # Check that --overwrite --verbose prints out the removed entries
620
 
        bzr('commit -m foo --unchanged')
 
395
        a = Branch.open('.')
 
396
        b = Branch.open('../b')
 
397
        assert a.revision_history() == b.revision_history()[:-1]
 
398
        self.runbzr('pull ../b')
 
399
        assert a.revision_history() == b.revision_history()
 
400
        self.runbzr('commit -m blah2 --unchanged')
621
401
        os.chdir('../b')
622
 
        bzr('commit -m baz --unchanged')
623
 
        bzr('pull ../a', retcode=3)
624
 
        out = bzr('pull --overwrite --verbose ../a', backtick=1)
625
 
 
626
 
        remove_loc = out.find('Removed Revisions:')
627
 
        self.failIfEqual(remove_loc, -1)
628
 
        added_loc = out.find('Added Revisions:')
629
 
        self.failIfEqual(added_loc, -1)
630
 
 
631
 
        removed_message = out.find('message:\n  baz')
632
 
        self.failIfEqual(removed_message, -1)
633
 
        self.failUnless(remove_loc < removed_message < added_loc)
634
 
 
635
 
        added_message = out.find('message:\n  foo')
636
 
        self.failIfEqual(added_message, -1)
637
 
        self.failUnless(added_loc < added_message)
638
 
        
 
402
        self.runbzr('commit -m blah3 --unchanged')
 
403
        self.runbzr('pull ../a', retcode=1)
 
404
        os.chdir('../a')
 
405
        self.runbzr('merge ../b')
 
406
        self.runbzr('commit -m blah4 --unchanged')
 
407
        os.chdir('../b/subdir')
 
408
        self.runbzr('pull ../../a')
 
409
        assert a.revision_history()[-1] == b.revision_history()[-1]
 
410
        self.runbzr('commit -m blah5 --unchanged')
 
411
        self.runbzr('commit -m blah6 --unchanged')
 
412
        os.chdir('..')
 
413
        self.runbzr('pull ../a')
 
414
        os.chdir('../a')
 
415
        self.runbzr('commit -m blah7 --unchanged')
 
416
        self.runbzr('merge ../b')
 
417
        self.runbzr('commit -m blah8 --unchanged')
 
418
        self.runbzr('pull ../b')
 
419
        self.runbzr('pull ../b')
 
420
 
639
421
    def test_locations(self):
640
422
        """Using and remembering different locations"""
641
423
        os.mkdir('a')
642
424
        os.chdir('a')
643
425
        self.runbzr('init')
644
426
        self.runbzr('commit -m unchanged --unchanged')
645
 
        self.runbzr('pull', retcode=3)
646
 
        self.runbzr('merge', retcode=3)
 
427
        self.runbzr('pull', retcode=1)
 
428
        self.runbzr('merge', retcode=1)
647
429
        self.runbzr('branch . ../b')
648
430
        os.chdir('../b')
649
431
        self.runbzr('pull')
660
442
        os.chdir('../b')
661
443
        self.runbzr('pull')
662
444
        os.chdir('../d')
663
 
        self.runbzr('pull', retcode=3)
 
445
        self.runbzr('pull', retcode=1)
664
446
        self.runbzr('pull ../a --remember')
665
447
        self.runbzr('pull')
666
448
        
667
449
    def test_add_reports(self):
668
450
        """add command prints the names of added files."""
669
451
        b = Branch.initialize('.')
670
 
        self.build_tree(['top.txt', 'dir/', 'dir/sub.txt', 'CVS'])
671
 
        out = self.run_bzr_captured(['add'], retcode=0)[0]
 
452
        self.build_tree(['top.txt', 'dir/', 'dir/sub.txt'])
 
453
        out = self.run_bzr_captured(['add'], retcode = 0)[0]
672
454
        # the ordering is not defined at the moment
673
455
        results = sorted(out.rstrip('\n').split('\n'))
674
 
        self.assertEquals(['If you wish to add some of these files, please'\
675
 
                           ' add them by name.',
676
 
                           'added dir',
 
456
        self.assertEquals(['added dir',
677
457
                           'added dir'+os.sep+'sub.txt',
678
 
                           'added top.txt',
679
 
                           'ignored 1 file(s) matching "CVS"'],
680
 
                          results)
681
 
        out = self.run_bzr_captured(['add', '-v'], retcode=0)[0]
682
 
        results = sorted(out.rstrip('\n').split('\n'))
683
 
        self.assertEquals(['If you wish to add some of these files, please'\
684
 
                           ' add them by name.',
685
 
                           'ignored CVS matching "CVS"'],
 
458
                           'added top.txt',],
686
459
                          results)
687
460
 
688
461
    def test_add_quiet_is(self):
689
462
        """add -q does not print the names of added files."""
690
463
        b = Branch.initialize('.')
691
464
        self.build_tree(['top.txt', 'dir/', 'dir/sub.txt'])
692
 
        out = self.run_bzr_captured(['add', '-q'], retcode=0)[0]
 
465
        out = self.run_bzr_captured(['add', '-q'], retcode = 0)[0]
693
466
        # the ordering is not defined at the moment
694
467
        results = sorted(out.rstrip('\n').split('\n'))
695
468
        self.assertEquals([''], results)
696
469
 
697
 
    def test_add_in_unversioned(self):
698
 
        """Try to add a file in an unversioned directory.
699
 
 
700
 
        "bzr add" should add the parent(s) as necessary.
701
 
        """
702
 
        from bzrlib.branch import Branch
703
 
        Branch.initialize('.')
704
 
        self.build_tree(['inertiatic/', 'inertiatic/esp'])
705
 
        self.assertEquals(self.capture('unknowns'), 'inertiatic\n')
706
 
        self.run_bzr('add', 'inertiatic/esp')
707
 
        self.assertEquals(self.capture('unknowns'), '')
708
 
 
709
 
        # Multiple unversioned parents
710
 
        self.build_tree(['veil/', 'veil/cerpin/', 'veil/cerpin/taxt'])
711
 
        self.assertEquals(self.capture('unknowns'), 'veil\n')
712
 
        self.run_bzr('add', 'veil/cerpin/taxt')
713
 
        self.assertEquals(self.capture('unknowns'), '')
714
 
 
715
 
        # Check whacky paths work
716
 
        self.build_tree(['cicatriz/', 'cicatriz/esp'])
717
 
        self.assertEquals(self.capture('unknowns'), 'cicatriz\n')
718
 
        self.run_bzr('add', 'inertiatic/../cicatriz/esp')
719
 
        self.assertEquals(self.capture('unknowns'), '')
720
 
 
721
 
    def test_add_in_versioned(self):
722
 
        """Try to add a file in a versioned directory.
723
 
 
724
 
        "bzr add" should do this happily.
725
 
        """
726
 
        from bzrlib.branch import Branch
727
 
        Branch.initialize('.')
728
 
        self.build_tree(['inertiatic/', 'inertiatic/esp'])
729
 
        self.assertEquals(self.capture('unknowns'), 'inertiatic\n')
730
 
        self.run_bzr('add', '--no-recurse', 'inertiatic')
731
 
        self.assertEquals(self.capture('unknowns'), 'inertiatic'+os.sep+'esp\n')
732
 
        self.run_bzr('add', 'inertiatic/esp')
733
 
        self.assertEquals(self.capture('unknowns'), '')
734
 
 
735
 
    def test_subdir_add(self):
736
 
        """Add in subdirectory should add only things from there down"""
737
 
        from bzrlib.branch import Branch
738
 
        
739
 
        eq = self.assertEqual
740
 
        ass = self.assert_
741
 
        chdir = os.chdir
742
 
        
743
 
        b = Branch.initialize('.')
744
 
        t = b.working_tree()
745
 
        self.build_tree(['src/', 'README'])
746
 
        
747
 
        eq(sorted(t.unknowns()),
748
 
           ['README', 'src'])
749
 
        
750
 
        self.run_bzr('add', 'src')
751
 
        
752
 
        self.build_tree(['src/foo.c'])
753
 
        
754
 
        chdir('src')
755
 
        self.run_bzr('add')
756
 
        
757
 
        self.assertEquals(self.capture('unknowns'), 'README\n')
758
 
        eq(len(t.read_working_inventory()), 3)
759
 
                
760
 
        chdir('..')
761
 
        self.run_bzr('add')
762
 
        self.assertEquals(self.capture('unknowns'), '')
763
 
        self.run_bzr('check')
764
 
 
765
470
    def test_unknown_command(self):
766
471
        """Handling of unknown command."""
767
472
        out, err = self.run_bzr_captured(['fluffy-badger'],
768
 
                                         retcode=3)
 
473
                                         retcode=1)
769
474
        self.assertEquals(out, '')
770
475
        err.index('unknown command')
771
476
 
772
 
    def create_conflicts(self):
773
 
        """Create a conflicted tree"""
 
477
    def test_conflicts(self):
 
478
        """Handling of merge conflicts"""
774
479
        os.mkdir('base')
775
480
        os.chdir('base')
776
481
        file('hello', 'wb').write("hi world")
790
495
        file('question', 'wb').write("What do you get when you multiply six"
791
496
                                   "times nine?")
792
497
        self.runbzr('commit -m this')
793
 
 
794
 
    def test_remerge(self):
795
 
        """Remerge command works as expected"""
796
 
        self.create_conflicts()
797
 
        self.runbzr('merge ../other --show-base', retcode=1)
798
 
        conflict_text = file('hello').read()
799
 
        assert '|||||||' in conflict_text
800
 
        assert 'hi world' in conflict_text
801
 
        self.runbzr('remerge', retcode=1)
802
 
        conflict_text = file('hello').read()
803
 
        assert '|||||||' not in conflict_text
804
 
        assert 'hi world' not in conflict_text
805
 
        os.unlink('hello.OTHER')
806
 
        self.runbzr('remerge hello --merge-type weave', retcode=1)
807
 
        assert os.path.exists('hello.OTHER')
808
 
        file_id = self.runbzr('file-id hello')
809
 
        file_id = self.runbzr('file-id hello.THIS', retcode=3)
810
 
        self.runbzr('remerge --merge-type weave', retcode=1)
811
 
        assert os.path.exists('hello.OTHER')
812
 
        assert not os.path.exists('hello.BASE')
813
 
        assert '|||||||' not in conflict_text
814
 
        assert 'hi world' not in conflict_text
815
 
        self.runbzr('remerge . --merge-type weave --show-base', retcode=3)
816
 
        self.runbzr('remerge . --merge-type weave --reprocess', retcode=3)
817
 
        self.runbzr('remerge . --show-base --reprocess', retcode=3)
818
 
        self.runbzr('remerge hello --show-base', retcode=1)
819
 
        self.runbzr('remerge hello --reprocess', retcode=1)
820
 
        self.runbzr('resolve --all')
821
 
        self.runbzr('commit -m done',)
822
 
        self.runbzr('remerge', retcode=3)
823
 
 
824
 
 
825
 
    def test_conflicts(self):
826
 
        """Handling of merge conflicts"""
827
 
        self.create_conflicts()
828
 
        self.runbzr('merge ../other --show-base', retcode=1)
829
 
        conflict_text = file('hello').read()
830
 
        self.assert_('<<<<<<<' in conflict_text)
831
 
        self.assert_('>>>>>>>' in conflict_text)
832
 
        self.assert_('=======' in conflict_text)
833
 
        self.assert_('|||||||' in conflict_text)
834
 
        self.assert_('hi world' in conflict_text)
835
 
        self.runbzr('revert')
836
 
        self.runbzr('resolve --all')
837
 
        self.runbzr('merge ../other', retcode=1)
838
 
        conflict_text = file('hello').read()
839
 
        self.assert_('|||||||' not in conflict_text)
840
 
        self.assert_('hi world' not in conflict_text)
 
498
        self.runbzr('merge ../other')
841
499
        result = self.runbzr('conflicts', backtick=1)
842
500
        self.assertEquals(result, "hello\nquestion\n")
843
501
        result = self.runbzr('status', backtick=1)
844
 
        self.assert_("conflicts:\n  hello\n  question\n" in result, result)
 
502
        assert "conflicts:\n  hello\n  question\n" in result, result
845
503
        self.runbzr('resolve hello')
846
504
        result = self.runbzr('conflicts', backtick=1)
847
505
        self.assertEquals(result, "question\n")
848
 
        self.runbzr('commit -m conflicts', retcode=3)
 
506
        self.runbzr('commit -m conflicts', retcode=1)
849
507
        self.runbzr('resolve --all')
850
508
        result = self.runbzr('conflicts', backtick=1)
851
509
        self.runbzr('commit -m conflicts')
856
514
        import bzrlib.gpg
857
515
        oldstrategy = bzrlib.gpg.GPGStrategy
858
516
        branch = Branch.initialize('.')
859
 
        branch.working_tree().commit("base", allow_pointless=True, rev_id='A')
 
517
        branch.commit("base", allow_pointless=True, rev_id='A')
860
518
        try:
861
519
            # monkey patch gpg signing mechanism
862
520
            from bzrlib.testament import Testament
866
524
                             branch.revision_store.get('A', 'sig').read())
867
525
        finally:
868
526
            bzrlib.gpg.GPGStrategy = oldstrategy
869
 
            
870
 
    def test_resign_range(self):
871
 
        import bzrlib.gpg
872
 
        oldstrategy = bzrlib.gpg.GPGStrategy
873
 
        branch = Branch.initialize('.')
874
 
        branch.working_tree().commit("base", allow_pointless=True, rev_id='A')
875
 
        branch.working_tree().commit("base", allow_pointless=True, rev_id='B')
876
 
        branch.working_tree().commit("base", allow_pointless=True, rev_id='C')
877
 
        try:
878
 
            # monkey patch gpg signing mechanism
879
 
            from bzrlib.testament import Testament
880
 
            bzrlib.gpg.GPGStrategy = bzrlib.gpg.LoopbackGPGStrategy
881
 
            self.runbzr('re-sign -r 1..')
882
 
            self.assertEqual(Testament.from_revision(branch,'A').as_short_text(),
883
 
                             branch.revision_store.get('A', 'sig').read())
884
 
            self.assertEqual(Testament.from_revision(branch,'B').as_short_text(),
885
 
                             branch.revision_store.get('B', 'sig').read())
886
 
            self.assertEqual(Testament.from_revision(branch,'C').as_short_text(),
887
 
                             branch.revision_store.get('C', 'sig').read())
888
 
        finally:
889
 
            bzrlib.gpg.GPGStrategy = oldstrategy
890
 
 
891
 
    def test_push(self):
892
 
        # create a source branch
893
 
        os.mkdir('my-branch')
894
 
        os.chdir('my-branch')
895
 
        self.example_branch()
896
 
 
897
 
        # with no push target, fail
898
 
        self.runbzr('push', retcode=3)
899
 
        # with an explicit target work
900
 
        self.runbzr('push ../output-branch')
901
 
        # with an implicit target work
902
 
        self.runbzr('push')
903
 
        # nothing missing
904
 
        self.runbzr('missing ../output-branch')
905
 
        # advance this branch
906
 
        self.runbzr('commit --unchanged -m unchanged')
907
 
 
908
 
        os.chdir('../output-branch')
909
 
        # There is no longer a difference as long as we have
910
 
        # access to the working tree
911
 
        self.runbzr('diff')
912
 
 
913
 
        # But we should be missing a revision
914
 
        self.runbzr('missing ../my-branch', retcode=1)
915
 
 
916
 
        # diverge the branches
917
 
        self.runbzr('commit --unchanged -m unchanged')
918
 
        os.chdir('../my-branch')
919
 
        # cannot push now
920
 
        self.runbzr('push', retcode=3)
921
 
        # and there are difference
922
 
        self.runbzr('missing ../output-branch', retcode=1)
923
 
        self.runbzr('missing --verbose ../output-branch', retcode=1)
924
 
        # but we can force a push
925
 
        self.runbzr('push --overwrite')
926
 
        # nothing missing
927
 
        self.runbzr('missing ../output-branch')
928
 
        
929
 
        # pushing to a new dir with no parent should fail
930
 
        self.runbzr('push ../missing/new-branch', retcode=3)
931
 
        # unless we provide --create-prefix
932
 
        self.runbzr('push --create-prefix ../missing/new-branch')
933
 
        # nothing missing
934
 
        self.runbzr('missing ../missing/new-branch')
935
 
 
936
 
    def test_external_command(self):
937
 
        """test that external commands can be run by setting the path"""
938
 
        cmd_name = 'test-command'
939
 
        output = 'Hello from test-command'
940
 
        if sys.platform == 'win32':
941
 
            cmd_name += '.bat'
942
 
            output += '\r\n'
943
 
        else:
944
 
            output += '\n'
945
 
 
946
 
        oldpath = os.environ.get('BZRPATH', None)
947
 
 
948
 
        bzr = self.capture
949
 
 
950
 
        try:
951
 
            if os.environ.has_key('BZRPATH'):
952
 
                del os.environ['BZRPATH']
953
 
 
954
 
            f = file(cmd_name, 'wb')
955
 
            if sys.platform == 'win32':
956
 
                f.write('@echo off\n')
957
 
            else:
958
 
                f.write('#!/bin/sh\n')
959
 
            f.write('echo Hello from test-command')
960
 
            f.close()
961
 
            os.chmod(cmd_name, 0755)
962
 
 
963
 
            # It should not find the command in the local 
964
 
            # directory by default, since it is not in my path
965
 
            bzr(cmd_name, retcode=3)
966
 
 
967
 
            # Now put it into my path
968
 
            os.environ['BZRPATH'] = '.'
969
 
 
970
 
            bzr(cmd_name)
971
 
            # The test suite does not capture stdout for external commands
972
 
            # this is because you have to have a real file object
973
 
            # to pass to Popen(stdout=FOO), and StringIO is not one of those.
974
 
            # (just replacing sys.stdout does not change a spawned objects stdout)
975
 
            #self.assertEquals(bzr(cmd_name), output)
976
 
 
977
 
            # Make sure empty path elements are ignored
978
 
            os.environ['BZRPATH'] = os.pathsep
979
 
 
980
 
            bzr(cmd_name, retcode=3)
981
 
 
982
 
        finally:
983
 
            if oldpath:
984
 
                os.environ['BZRPATH'] = oldpath
985
 
 
986
527
 
987
528
def listdir_sorted(dir):
988
529
    L = os.listdir(dir)
1018
559
        self.assertEquals(capture('unknowns'), 'test.txt\n')
1019
560
 
1020
561
        out = capture("status")
1021
 
        self.assertEquals(out, 'unknown:\n  test.txt\n')
 
562
        assert out == 'unknown:\n  test.txt\n'
1022
563
 
1023
564
        out = capture("status --all")
1024
 
        self.assertEquals(out, "unknown:\n  test.txt\n")
 
565
        assert out == "unknown:\n  test.txt\n"
1025
566
 
1026
567
        out = capture("status test.txt --all")
1027
 
        self.assertEquals(out, "unknown:\n  test.txt\n")
 
568
        assert out == "unknown:\n  test.txt\n"
1028
569
 
1029
570
        f = file('test2.txt', 'wt')
1030
571
        f.write('goodbye cruel world...\n')
1031
572
        f.close()
1032
573
 
1033
574
        out = capture("status test.txt")
1034
 
        self.assertEquals(out, "unknown:\n  test.txt\n")
 
575
        assert out == "unknown:\n  test.txt\n"
1035
576
 
1036
577
        out = capture("status")
1037
 
        self.assertEquals(out, ("unknown:\n" "  test.txt\n" "  test2.txt\n"))
 
578
        assert out == ("unknown:\n"
 
579
                       "  test.txt\n"
 
580
                       "  test2.txt\n")
1038
581
 
1039
582
        os.unlink('test2.txt')
1040
583
 
1041
584
        progress("command aliases")
1042
585
        out = capture("st --all")
1043
 
        self.assertEquals(out, ("unknown:\n" "  test.txt\n"))
 
586
        assert out == ("unknown:\n"
 
587
                       "  test.txt\n")
1044
588
 
1045
589
        out = capture("stat")
1046
 
        self.assertEquals(out, ("unknown:\n" "  test.txt\n"))
 
590
        assert out == ("unknown:\n"
 
591
                       "  test.txt\n")
1047
592
 
1048
593
        progress("command help")
1049
594
        runbzr("help st")
1050
595
        runbzr("help")
1051
596
        runbzr("help commands")
1052
 
        runbzr("help slartibartfast", 3)
 
597
        runbzr("help slartibartfast", 1)
1053
598
 
1054
599
        out = capture("help ci")
1055
600
        out.index('aliases: ')
1056
601
 
1057
602
        progress("can't rename unversioned file")
1058
 
        runbzr("rename test.txt new-test.txt", 3)
 
603
        runbzr("rename test.txt new-test.txt", 1)
1059
604
 
1060
605
        progress("adding a file")
1061
606
 
1062
607
        runbzr("add test.txt")
1063
 
        self.assertEquals(capture("unknowns"), '')
1064
 
        self.assertEquals(capture("status --all"), ("added:\n" "  test.txt\n"))
 
608
        assert capture("unknowns") == ''
 
609
        assert capture("status --all") == ("added:\n"
 
610
                                                "  test.txt\n")
1065
611
 
1066
612
        progress("rename newly-added file")
1067
613
        runbzr("rename test.txt hello.txt")
1068
 
        self.assert_(os.path.exists("hello.txt"))
1069
 
        self.assert_(not os.path.exists("test.txt"))
 
614
        assert os.path.exists("hello.txt")
 
615
        assert not os.path.exists("test.txt")
1070
616
 
1071
 
        self.assertEquals(capture("revno"), '0\n')
 
617
        assert capture("revno") == '0\n'
1072
618
 
1073
619
        progress("add first revision")
1074
620
        runbzr(['commit', '-m', 'add first revision'])
1075
621
 
1076
622
        progress("more complex renames")
1077
623
        os.mkdir("sub1")
1078
 
        runbzr("rename hello.txt sub1", 3)
1079
 
        runbzr("rename hello.txt sub1/hello.txt", 3)
1080
 
        runbzr("move hello.txt sub1", 3)
 
624
        runbzr("rename hello.txt sub1", 1)
 
625
        runbzr("rename hello.txt sub1/hello.txt", 1)
 
626
        runbzr("move hello.txt sub1", 1)
1081
627
 
1082
628
        runbzr("add sub1")
1083
629
        runbzr("rename sub1 sub2")
1085
631
        self.assertEqual(capture("relpath sub2/hello.txt"),
1086
632
                         os.path.join("sub2", "hello.txt\n"))
1087
633
 
1088
 
        self.assert_(exists("sub2"))
1089
 
        self.assert_(exists("sub2/hello.txt"))
1090
 
        self.assert_(not exists("sub1"))
1091
 
        self.assert_(not exists("hello.txt"))
 
634
        assert exists("sub2")
 
635
        assert exists("sub2/hello.txt")
 
636
        assert not exists("sub1")
 
637
        assert not exists("hello.txt")
1092
638
 
1093
639
        runbzr(['commit', '-m', 'commit with some things moved to subdirs'])
1094
640
 
1095
641
        mkdir("sub1")
1096
642
        runbzr('add sub1')
1097
643
        runbzr('move sub2/hello.txt sub1')
1098
 
        self.assert_(not exists('sub2/hello.txt'))
1099
 
        self.assert_(exists('sub1/hello.txt'))
 
644
        assert not exists('sub2/hello.txt')
 
645
        assert exists('sub1/hello.txt')
1100
646
        runbzr('move sub2 sub1')
1101
 
        self.assert_(not exists('sub2'))
1102
 
        self.assert_(exists('sub1/sub2'))
 
647
        assert not exists('sub2')
 
648
        assert exists('sub1/sub2')
1103
649
 
1104
650
        runbzr(['commit', '-m', 'rename nested subdirectories'])
1105
651
 
1107
653
        self.assertEquals(capture('root')[:-1],
1108
654
                          os.path.join(self.test_dir, 'branch1'))
1109
655
        runbzr('move ../hello.txt .')
1110
 
        self.assert_(exists('./hello.txt'))
 
656
        assert exists('./hello.txt')
1111
657
        self.assertEquals(capture('relpath hello.txt'),
1112
658
                          os.path.join('sub1', 'sub2', 'hello.txt') + '\n')
1113
 
        self.assertEquals(capture('relpath ../../sub1/sub2/hello.txt'), os.path.join('sub1', 'sub2', 'hello.txt\n'))
 
659
        assert capture('relpath ../../sub1/sub2/hello.txt') == os.path.join('sub1', 'sub2', 'hello.txt\n')
1114
660
        runbzr(['commit', '-m', 'move to parent directory'])
1115
661
        chdir('..')
1116
 
        self.assertEquals(capture('relpath sub2/hello.txt'), os.path.join('sub1', 'sub2', 'hello.txt\n'))
 
662
        assert capture('relpath sub2/hello.txt') == os.path.join('sub1', 'sub2', 'hello.txt\n')
1117
663
 
1118
664
        runbzr('move sub2/hello.txt .')
1119
 
        self.assert_(exists('hello.txt'))
 
665
        assert exists('hello.txt')
1120
666
 
1121
667
        f = file('hello.txt', 'wt')
1122
668
        f.write('some nice new content\n')
1128
674
 
1129
675
        runbzr('commit -F msg.tmp')
1130
676
 
1131
 
        self.assertEquals(capture('revno'), '5\n')
 
677
        assert capture('revno') == '5\n'
1132
678
        runbzr('export -r 5 export-5.tmp')
1133
679
        runbzr('export export.tmp')
1134
680
 
1135
681
        runbzr('log')
1136
682
        runbzr('log -v')
1137
683
        runbzr('log -v --forward')
1138
 
        runbzr('log -m', retcode=3)
 
684
        runbzr('log -m', retcode=1)
1139
685
        log_out = capture('log -m commit')
1140
 
        self.assert_("this is my new commit\n  and" in log_out)
1141
 
        self.assert_("rename nested" not in log_out)
1142
 
        self.assert_('revision-id' not in log_out)
1143
 
        self.assert_('revision-id' in capture('log --show-ids -m commit'))
 
686
        assert "this is my new commit\n  and" in log_out
 
687
        assert "rename nested" not in log_out
 
688
        assert 'revision-id' not in log_out
 
689
        assert 'revision-id' in capture('log --show-ids -m commit')
1144
690
 
1145
691
        log_out = capture('log --line')
1146
692
        for line in log_out.splitlines():
1147
 
            self.assert_(len(line) <= 79, len(line))
1148
 
        self.assert_("this is my new commit and" in log_out)
 
693
            assert len(line) <= 79, len(line)
 
694
        assert "this is my new commit and" in log_out
1149
695
 
1150
696
 
1151
697
        progress("file with spaces in name")
1152
698
        mkdir('sub directory')
1153
699
        file('sub directory/file with spaces ', 'wt').write('see how this works\n')
1154
700
        runbzr('add .')
1155
 
        runbzr('diff', retcode=1)
 
701
        runbzr('diff')
1156
702
        runbzr('commit -m add-spaces')
1157
703
        runbzr('check')
1158
704
 
1168
714
            runbzr('init')
1169
715
            os.symlink("NOWHERE1", "link1")
1170
716
            runbzr('add link1')
1171
 
            self.assertEquals(self.capture('unknowns'), '')
 
717
            assert self.capture('unknowns') == ''
1172
718
            runbzr(['commit', '-m', '1: added symlink link1'])
1173
719
    
1174
720
            mkdir('d1')
1175
721
            runbzr('add d1')
1176
 
            self.assertEquals(self.capture('unknowns'), '')
 
722
            assert self.capture('unknowns') == ''
1177
723
            os.symlink("NOWHERE2", "d1/link2")
1178
 
            self.assertEquals(self.capture('unknowns'), 'd1/link2\n')
 
724
            assert self.capture('unknowns') == 'd1/link2\n'
1179
725
            # is d1/link2 found when adding d1
1180
726
            runbzr('add d1')
1181
 
            self.assertEquals(self.capture('unknowns'), '')
 
727
            assert self.capture('unknowns') == ''
1182
728
            os.symlink("NOWHERE3", "d1/link3")
1183
 
            self.assertEquals(self.capture('unknowns'), 'd1/link3\n')
 
729
            assert self.capture('unknowns') == 'd1/link3\n'
1184
730
            runbzr(['commit', '-m', '2: added dir, symlink'])
1185
731
    
1186
732
            runbzr('rename d1 d2')
1187
733
            runbzr('move d2/link2 .')
1188
734
            runbzr('move link1 d2')
1189
 
            self.assertEquals(os.readlink("./link2"), "NOWHERE2")
1190
 
            self.assertEquals(os.readlink("d2/link1"), "NOWHERE1")
 
735
            assert os.readlink("./link2") == "NOWHERE2"
 
736
            assert os.readlink("d2/link1") == "NOWHERE1"
1191
737
            runbzr('add d2/link3')
1192
 
            runbzr('diff', retcode=1)
 
738
            runbzr('diff')
1193
739
            runbzr(['commit', '-m', '3: rename of dir, move symlinks, add link3'])
1194
740
    
1195
741
            os.unlink("link2")
1196
742
            os.symlink("TARGET 2", "link2")
1197
743
            os.unlink("d2/link1")
1198
744
            os.symlink("TARGET 1", "d2/link1")
1199
 
            runbzr('diff', retcode=1)
1200
 
            self.assertEquals(self.capture("relpath d2/link1"), "d2/link1\n")
 
745
            runbzr('diff')
 
746
            assert self.capture("relpath d2/link1") == "d2/link1\n"
1201
747
            runbzr(['commit', '-m', '4: retarget of two links'])
1202
748
    
1203
749
            runbzr('remove d2/link1')
1204
 
            self.assertEquals(self.capture('unknowns'), 'd2/link1\n')
 
750
            assert self.capture('unknowns') == 'd2/link1\n'
1205
751
            runbzr(['commit', '-m', '5: remove d2/link1'])
1206
752
            # try with the rm alias
1207
753
            runbzr('add d2/link1')
1208
754
            runbzr(['commit', '-m', '6: add d2/link1'])
1209
755
            runbzr('rm d2/link1')
1210
 
            self.assertEquals(self.capture('unknowns'), 'd2/link1\n')
 
756
            assert self.capture('unknowns') == 'd2/link1\n'
1211
757
            runbzr(['commit', '-m', '7: remove d2/link1'])
1212
758
    
1213
759
            os.mkdir("d1")
1214
760
            runbzr('add d1')
1215
761
            runbzr('rename d2/link3 d1/link3new')
1216
 
            self.assertEquals(self.capture('unknowns'), 'd2/link1\n')
 
762
            assert self.capture('unknowns') == 'd2/link1\n'
1217
763
            runbzr(['commit', '-m', '8: remove d2/link1, move/rename link3'])
1218
764
            
1219
765
            runbzr(['check'])
1220
766
            
1221
767
            runbzr(['export', '-r', '1', 'exp1.tmp'])
1222
768
            chdir("exp1.tmp")
1223
 
            self.assertEquals(listdir_sorted("."), [ "link1" ])
1224
 
            self.assertEquals(os.readlink("link1"), "NOWHERE1")
 
769
            assert listdir_sorted(".") == [ "link1" ]
 
770
            assert os.readlink("link1") == "NOWHERE1"
1225
771
            chdir("..")
1226
772
            
1227
773
            runbzr(['export', '-r', '2', 'exp2.tmp'])
1228
774
            chdir("exp2.tmp")
1229
 
            self.assertEquals(listdir_sorted("."), [ "d1", "link1" ])
 
775
            assert listdir_sorted(".") == [ "d1", "link1" ]
1230
776
            chdir("..")
1231
777
            
1232
778
            runbzr(['export', '-r', '3', 'exp3.tmp'])
1233
779
            chdir("exp3.tmp")
1234
 
            self.assertEquals(listdir_sorted("."), [ "d2", "link2" ])
1235
 
            self.assertEquals(listdir_sorted("d2"), [ "link1", "link3" ])
1236
 
            self.assertEquals(os.readlink("d2/link1"), "NOWHERE1")
1237
 
            self.assertEquals(os.readlink("link2")   , "NOWHERE2")
 
780
            assert listdir_sorted(".") == [ "d2", "link2" ]
 
781
            assert listdir_sorted("d2") == [ "link1", "link3" ]
 
782
            assert os.readlink("d2/link1") == "NOWHERE1"
 
783
            assert os.readlink("link2")    == "NOWHERE2"
1238
784
            chdir("..")
1239
785
            
1240
786
            runbzr(['export', '-r', '4', 'exp4.tmp'])
1241
787
            chdir("exp4.tmp")
1242
 
            self.assertEquals(listdir_sorted("."), [ "d2", "link2" ])
1243
 
            self.assertEquals(os.readlink("d2/link1"), "TARGET 1")
1244
 
            self.assertEquals(os.readlink("link2")   , "TARGET 2")
1245
 
            self.assertEquals(listdir_sorted("d2"), [ "link1", "link3" ])
 
788
            assert listdir_sorted(".") == [ "d2", "link2" ]
 
789
            assert os.readlink("d2/link1") == "TARGET 1"
 
790
            assert os.readlink("link2")    == "TARGET 2"
 
791
            assert listdir_sorted("d2") == [ "link1", "link3" ]
1246
792
            chdir("..")
1247
793
            
1248
794
            runbzr(['export', '-r', '5', 'exp5.tmp'])
1249
795
            chdir("exp5.tmp")
1250
 
            self.assertEquals(listdir_sorted("."), [ "d2", "link2" ])
1251
 
            self.assert_(os.path.islink("link2"))
1252
 
            self.assert_(listdir_sorted("d2")== [ "link3" ])
 
796
            assert listdir_sorted(".") == [ "d2", "link2" ]
 
797
            assert os.path.islink("link2")
 
798
            assert listdir_sorted("d2")== [ "link3" ]
1253
799
            chdir("..")
1254
800
            
1255
801
            runbzr(['export', '-r', '8', 'exp6.tmp'])
1256
802
            chdir("exp6.tmp")
1257
803
            self.assertEqual(listdir_sorted("."), [ "d1", "d2", "link2"])
1258
 
            self.assertEquals(listdir_sorted("d1"), [ "link3new" ])
1259
 
            self.assertEquals(listdir_sorted("d2"), [])
1260
 
            self.assertEquals(os.readlink("d1/link3new"), "NOWHERE3")
 
804
            assert listdir_sorted("d1") == [ "link3new" ]
 
805
            assert listdir_sorted("d2") == []
 
806
            assert os.readlink("d1/link3new") == "NOWHERE3"
1261
807
            chdir("..")
1262
808
        else:
1263
809
            progress("skipping symlink tests")
1269
815
    def test_branch(self):
1270
816
        os.mkdir('from')
1271
817
        branch = Branch.initialize('from')
1272
 
        branch.working_tree().commit('empty commit for nonsense', allow_pointless=True)
 
818
        branch.commit('empty commit for nonsense', allow_pointless=True)
1273
819
        url = self.get_remote_url('from')
1274
820
        self.run_bzr('branch', url, 'to')
1275
821
        branch = Branch.open('to')
1276
822
        self.assertEqual(1, len(branch.revision_history()))
1277
823
 
1278
 
    def test_log(self):
1279
 
        self.build_tree(['branch/', 'branch/file'])
1280
 
        branch = Branch.initialize('branch')
1281
 
        branch.working_tree().add(['file'])
1282
 
        branch.working_tree().commit('add file', rev_id='A')
1283
 
        url = self.get_remote_url('branch/file')
1284
 
        output = self.capture('log %s' % url)
1285
 
        self.assertEqual(8, len(output.split('\n')))
1286
 
        
1287
 
    def test_check(self):
1288
 
        self.build_tree(['branch/', 'branch/file'])
1289
 
        branch = Branch.initialize('branch')
1290
 
        branch.working_tree().add(['file'])
1291
 
        branch.working_tree().commit('add file', rev_id='A')
1292
 
        url = self.get_remote_url('branch/')
1293
 
        self.run_bzr('check', url)
 
824