~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/selftest/blackbox.py

Fix http server tests for win32/macos (John)

Show diffs side-by-side

added added

removed removed

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