/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

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

  • Committer: Robert Collins
  • Date: 2006-04-28 11:01:38 UTC
  • mfrom: (1687 +trunk)
  • mto: (1704.1.1 integration)
  • mto: This revision was merged to the branch mainline in revision 1706.
  • Revision ID: robertc@robertcollins.net-20060428110138-0e69ecb765434f9d
MergeĀ fromĀ mainline.

Show diffs side-by-side

added added

removed removed

Lines of Context:
40
40
import shutil
41
41
import sys
42
42
 
 
43
import bzrlib
43
44
from bzrlib.branch import Branch
44
45
import bzrlib.bzrdir as bzrdir
45
46
from bzrlib.errors import BzrCommandError
52
53
 
53
54
class TestCommands(ExternalBase):
54
55
 
55
 
    def test_help_commands(self):
56
 
        self.runbzr('--help')
57
 
        self.runbzr('help')
58
 
        self.runbzr('help commands')
59
 
        self.runbzr('help help')
60
 
        self.runbzr('commit -h')
61
 
 
62
 
    def test_init_branch(self):
63
 
        self.runbzr(['init'])
64
 
 
65
 
        # Can it handle subdirectories as well?
66
 
        self.runbzr('init subdir1')
67
 
        self.assert_(os.path.exists('subdir1'))
68
 
        self.assert_(os.path.exists('subdir1/.bzr'))
69
 
 
70
 
        self.runbzr('init subdir2/nothere', retcode=3)
71
 
        
72
 
        os.mkdir('subdir2')
73
 
        self.runbzr('init subdir2')
74
 
        self.runbzr('init subdir2', retcode=3)
75
 
 
76
 
        self.runbzr('init subdir2/subsubdir1')
77
 
        self.assert_(os.path.exists('subdir2/subsubdir1/.bzr'))
78
 
 
79
56
    def test_whoami(self):
80
57
        # this should always identify something, if only "john@localhost"
81
58
        self.runbzr("whoami")
87
64
    def test_whoami_branch(self):
88
65
        """branch specific user identity works."""
89
66
        self.runbzr('init')
90
 
        f = file('.bzr/email', 'wt')
91
 
        f.write('Branch Identity <branch@identi.ty>')
92
 
        f.close()
 
67
        b = bzrlib.branch.Branch.open('.')
 
68
        b.control_files.put_utf8('email', 'Branch Identity <branch@identi.ty>')
93
69
        bzr_email = os.environ.get('BZREMAIL')
94
70
        if bzr_email is not None:
95
71
            del os.environ['BZREMAIL']
303
279
        self.example_branch()
304
280
        os.chdir('..')
305
281
        self.runbzr('branch a b')
306
 
        self.assertFileEqual('b\n', 'b/.bzr/branch-name')
 
282
        b = bzrlib.branch.Branch.open('b')
 
283
        self.assertEqual('b\n', b.control_files.get_utf8('branch-name').read())
307
284
        self.runbzr('branch a c -r 1')
308
285
        os.chdir('b')
309
286
        self.runbzr('commit -m foo --unchanged')
329
306
        self.assertEqual('2', target.open_workingtree().last_revision())
330
307
        self.assertTrue(target.open_branch().repository.has_revision('2'))
331
308
 
332
 
    def test_merge(self):
333
 
        from bzrlib.branch import Branch
334
 
        
335
 
        os.mkdir('a')
336
 
        os.chdir('a')
337
 
        self.example_branch()
338
 
        os.chdir('..')
339
 
        self.runbzr('branch a b')
340
 
        os.chdir('b')
341
 
        file('goodbye', 'wt').write('quux')
342
 
        self.runbzr(['commit',  '-m',  "more u's are always good"])
343
 
 
344
 
        os.chdir('../a')
345
 
        file('hello', 'wt').write('quuux')
346
 
        # We can't merge when there are in-tree changes
347
 
        self.runbzr('merge ../b', retcode=3)
348
 
        self.runbzr(['commit', '-m', "Like an epidemic of u's"])
349
 
        self.runbzr('merge ../b -r last:1..last:1 --merge-type blooof',
350
 
                    retcode=3)
351
 
        self.runbzr('merge ../b -r last:1..last:1 --merge-type merge3')
352
 
        self.runbzr('revert --no-backup')
353
 
        self.runbzr('merge ../b -r last:1..last:1 --merge-type weave')
354
 
        self.runbzr('revert --no-backup')
355
 
        self.runbzr('merge ../b -r last:1..last:1 --reprocess')
356
 
        self.runbzr('revert --no-backup')
357
 
        self.runbzr('merge ../b -r last:1')
358
 
        self.check_file_contents('goodbye', 'quux')
359
 
        # Merging a branch pulls its revision into the tree
360
 
        a = WorkingTree.open('.')
361
 
        b = Branch.open('../b')
362
 
        a.branch.repository.get_revision_xml(b.last_revision())
363
 
        self.log('pending merges: %s', a.pending_merges())
364
 
        self.assertEquals(a.pending_merges(),
365
 
                          [b.last_revision()])
366
 
        self.runbzr('commit -m merged')
367
 
        self.runbzr('merge ../b -r last:1')
368
 
        self.assertEqual(a.pending_merges(), [])
369
 
 
370
 
    def test_merge_with_missing_file(self):
371
 
        """Merge handles missing file conflicts"""
372
 
        os.mkdir('a')
373
 
        os.chdir('a')
374
 
        os.mkdir('sub')
375
 
        print >> file('sub/a.txt', 'wb'), "hello"
376
 
        print >> file('b.txt', 'wb'), "hello"
377
 
        print >> file('sub/c.txt', 'wb'), "hello"
378
 
        self.runbzr('init')
379
 
        self.runbzr('add')
380
 
        self.runbzr(('commit', '-m', 'added a'))
381
 
        self.runbzr('branch . ../b')
382
 
        print >> file('sub/a.txt', 'ab'), "there"
383
 
        print >> file('b.txt', 'ab'), "there"
384
 
        print >> file('sub/c.txt', 'ab'), "there"
385
 
        self.runbzr(('commit', '-m', 'Added there'))
386
 
        os.unlink('sub/a.txt')
387
 
        os.unlink('sub/c.txt')
388
 
        os.rmdir('sub')
389
 
        os.unlink('b.txt')
390
 
        self.runbzr(('commit', '-m', 'Removed a.txt'))
391
 
        os.chdir('../b')
392
 
        print >> file('sub/a.txt', 'ab'), "something"
393
 
        print >> file('b.txt', 'ab'), "something"
394
 
        print >> file('sub/c.txt', 'ab'), "something"
395
 
        self.runbzr(('commit', '-m', 'Modified a.txt'))
396
 
        self.runbzr('merge ../a/', retcode=1)
397
 
        self.assert_(os.path.exists('sub/a.txt.THIS'))
398
 
        self.assert_(os.path.exists('sub/a.txt.BASE'))
399
 
        os.chdir('../a')
400
 
        self.runbzr('merge ../b/', retcode=1)
401
 
        self.assert_(os.path.exists('sub/a.txt.OTHER'))
402
 
        self.assert_(os.path.exists('sub/a.txt.BASE'))
403
 
 
404
309
    def test_inventory(self):
405
310
        bzr = self.runbzr
406
311
        def output_equals(value, *args):
732
637
        assert '|||||||' not in conflict_text
733
638
        assert 'hi world' not in conflict_text
734
639
        os.unlink('hello.OTHER')
 
640
        os.unlink('question.OTHER')
 
641
        self.runbzr('remerge jello --merge-type weave', retcode=3)
735
642
        self.runbzr('remerge hello --merge-type weave', retcode=1)
736
643
        assert os.path.exists('hello.OTHER')
 
644
        self.assertIs(False, os.path.exists('question.OTHER'))
737
645
        file_id = self.runbzr('file-id hello')
738
646
        file_id = self.runbzr('file-id hello.THIS', retcode=3)
739
647
        self.runbzr('remerge --merge-type weave', retcode=1)
742
650
        assert '|||||||' not in conflict_text
743
651
        assert 'hi world' not in conflict_text
744
652
        self.runbzr('remerge . --merge-type weave --show-base', retcode=3)
745
 
        self.runbzr('remerge . --merge-type weave --reprocess', retcode=3)
746
653
        self.runbzr('remerge . --show-base --reprocess', retcode=3)
 
654
        self.runbzr('remerge . --merge-type weave --reprocess', retcode=1)
747
655
        self.runbzr('remerge hello --show-base', retcode=1)
748
656
        self.runbzr('remerge hello --reprocess', retcode=1)
749
657
        self.runbzr('resolve --all')
783
691
        self.assert_('|||||||' not in conflict_text)
784
692
        self.assert_('hi world' not in conflict_text)
785
693
        result = self.runbzr('conflicts', backtick=1)
786
 
        self.assertEquals(result, "hello\nquestion\n")
 
694
        self.assertEquals(result, "Text conflict in hello\nText conflict in"
 
695
                                  " question\n")
787
696
        result = self.runbzr('status', backtick=1)
788
 
        self.assert_("conflicts:\n  hello\n  question\n" in result, result)
 
697
        self.assert_("conflicts:\n  Text conflict in hello\n"
 
698
                     "  Text conflict in question\n" in result, result)
789
699
        self.runbzr('resolve hello')
790
700
        result = self.runbzr('conflicts', backtick=1)
791
 
        self.assertEquals(result, "question\n")
 
701
        self.assertEquals(result, "Text conflict in question\n")
792
702
        self.runbzr('commit -m conflicts', retcode=3)
793
703
        self.runbzr('resolve --all')
794
704
        result = self.runbzr('conflicts', backtick=1)
795
705
        self.runbzr('commit -m conflicts')
796
706
        self.assertEquals(result, "")
797
707
 
798
 
    def test_resign(self):
799
 
        """Test re signing of data."""
800
 
        import bzrlib.gpg
801
 
        oldstrategy = bzrlib.gpg.GPGStrategy
802
 
        wt = self.make_branch_and_tree('.')
803
 
        branch = wt.branch
804
 
        wt.commit("base", allow_pointless=True, rev_id='A')
805
 
        try:
806
 
            # monkey patch gpg signing mechanism
807
 
            from bzrlib.testament import Testament
808
 
            bzrlib.gpg.GPGStrategy = bzrlib.gpg.LoopbackGPGStrategy
809
 
            self.runbzr('re-sign -r revid:A')
810
 
            self.assertEqual(Testament.from_revision(branch.repository,
811
 
                             'A').as_short_text(),
812
 
                             branch.repository.revision_store.get('A', 
813
 
                             'sig').read())
814
 
        finally:
815
 
            bzrlib.gpg.GPGStrategy = oldstrategy
816
 
            
817
 
    def test_resign_range(self):
818
 
        import bzrlib.gpg
819
 
        oldstrategy = bzrlib.gpg.GPGStrategy
820
 
        wt = self.make_branch_and_tree('.')
821
 
        branch = wt.branch
822
 
        wt.commit("base", allow_pointless=True, rev_id='A')
823
 
        wt.commit("base", allow_pointless=True, rev_id='B')
824
 
        wt.commit("base", allow_pointless=True, rev_id='C')
825
 
        try:
826
 
            # monkey patch gpg signing mechanism
827
 
            from bzrlib.testament import Testament
828
 
            bzrlib.gpg.GPGStrategy = bzrlib.gpg.LoopbackGPGStrategy
829
 
            self.runbzr('re-sign -r 1..')
830
 
            self.assertEqual(
831
 
                Testament.from_revision(branch.repository,'A').as_short_text(),
832
 
                branch.repository.revision_store.get('A', 'sig').read())
833
 
            self.assertEqual(
834
 
                Testament.from_revision(branch.repository,'B').as_short_text(),
835
 
                branch.repository.revision_store.get('B', 'sig').read())
836
 
            self.assertEqual(Testament.from_revision(branch.repository,
837
 
                             'C').as_short_text(),
838
 
                             branch.repository.revision_store.get('C', 
839
 
                             'sig').read())
840
 
        finally:
841
 
            bzrlib.gpg.GPGStrategy = oldstrategy
842
 
 
843
708
    def test_push(self):
844
709
        # create a source branch
845
710
        os.mkdir('my-branch')
886
751
        self.runbzr('missing ../missing/new-branch')
887
752
 
888
753
    def test_external_command(self):
889
 
        """test that external commands can be run by setting the path"""
 
754
        """Test that external commands can be run by setting the path
 
755
        """
 
756
        # We don't at present run bzr in a subprocess for blackbox tests, and so 
 
757
        # don't really capture stdout, only the internal python stream.
 
758
        # Therefore we don't use a subcommand that produces any output or does
 
759
        # anything -- we just check that it can be run successfully.  
890
760
        cmd_name = 'test-command'
891
 
        output = 'Hello from test-command'
892
761
        if sys.platform == 'win32':
893
762
            cmd_name += '.bat'
894
 
            output += '\r\n'
895
 
        else:
896
 
            output += '\n'
897
 
 
898
763
        oldpath = os.environ.get('BZRPATH', None)
899
 
 
900
764
        bzr = self.capture
901
 
 
902
765
        try:
903
766
            if os.environ.has_key('BZRPATH'):
904
767
                del os.environ['BZRPATH']
908
771
                f.write('@echo off\n')
909
772
            else:
910
773
                f.write('#!/bin/sh\n')
911
 
            f.write('echo Hello from test-command')
 
774
            # f.write('echo Hello from test-command')
912
775
            f.close()
913
776
            os.chmod(cmd_name, 0755)
914
777
 
920
783
            os.environ['BZRPATH'] = '.'
921
784
 
922
785
            bzr(cmd_name)
923
 
            # The test suite does not capture stdout for external commands
924
 
            # this is because you have to have a real file object
925
 
            # to pass to Popen(stdout=FOO), and StringIO is not one of those.
926
 
            # (just replacing sys.stdout does not change a spawned objects stdout)
927
 
            #self.assertEquals(bzr(cmd_name), output)
928
786
 
929
787
            # Make sure empty path elements are ignored
930
788
            os.environ['BZRPATH'] = os.pathsep
1247
1105
        url = self.get_readonly_url('branch/')
1248
1106
        self.run_bzr('check', url)
1249
1107
    
 
1108
    def test_push(self):
 
1109
        # create a source branch
 
1110
        os.mkdir('my-branch')
 
1111
        os.chdir('my-branch')
 
1112
        self.run_bzr('init')
 
1113
        file('hello', 'wt').write('foo')
 
1114
        self.run_bzr('add', 'hello')
 
1115
        self.run_bzr('commit', '-m', 'setup')
 
1116
 
 
1117
        # with an explicit target work
 
1118
        self.run_bzr('push', self.get_url('output-branch'))
 
1119
 
1250
1120
    
1251
1121
class HTTPTests(TestCaseWithWebserver, RemoteTests):
1252
1122
    """Test various commands against a HTTP server."""