/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: John Arbash Meinel
  • Date: 2006-03-08 14:31:23 UTC
  • mfrom: (1598 +trunk)
  • mto: (1685.1.1 bzr-encoding)
  • mto: This revision was merged to the branch mainline in revision 1752.
  • Revision ID: john@arbash-meinel.com-20060308143123-448308b0db4de410
[merge] bzr.dev 1573, lots of updates

Show diffs side-by-side

added added

removed removed

Lines of Context:
41
41
import sys
42
42
 
43
43
from bzrlib.branch import Branch
 
44
import bzrlib.bzrdir as bzrdir
44
45
from bzrlib.errors import BzrCommandError
45
46
from bzrlib.osutils import has_symlinks, pathjoin
46
47
from bzrlib.tests.HTTPTestUtil import TestCaseWithWebserver
51
52
 
52
53
class TestCommands(ExternalBase):
53
54
 
54
 
    def test_help_commands(self):
55
 
        self.runbzr('--help')
56
 
        self.runbzr('help')
57
 
        self.runbzr('help commands')
58
 
        self.runbzr('help help')
59
 
        self.runbzr('commit -h')
60
 
 
61
55
    def test_init_branch(self):
62
56
        self.runbzr(['init'])
63
57
 
117
111
        nick = self.runbzr("nick",backtick=True)
118
112
        self.assertEqual(nick, 'moo\n')
119
113
 
120
 
 
121
114
    def test_invalid_commands(self):
122
115
        self.runbzr("pants", retcode=3)
123
116
        self.runbzr("--pants off", retcode=3)
124
117
        self.runbzr("diff --message foo", retcode=3)
125
118
 
126
 
    def test_empty_commit(self):
127
 
        self.runbzr("init")
128
 
        self.build_tree(['hello.txt'])
129
 
        self.runbzr("commit -m empty", retcode=3)
130
 
        self.runbzr("add hello.txt")
131
 
        self.runbzr("commit -m added")       
132
 
 
133
 
    def test_empty_commit_message(self):
134
 
        self.runbzr("init")
135
 
        file('foo.c', 'wt').write('int main() {}')
136
 
        self.runbzr(['add', 'foo.c'])
137
 
        self.runbzr(["commit", "-m", ""] , retcode=3) 
138
 
 
139
119
    def test_remove_deleted(self):
140
120
        self.runbzr("init")
141
121
        self.build_tree(['a'])
144
124
        os.unlink('a')
145
125
        self.runbzr(['remove', 'a'])
146
126
 
147
 
    def test_other_branch_commit(self):
148
 
        # this branch is to ensure consistent behaviour, whether we're run
149
 
        # inside a branch, or not.
150
 
        os.mkdir('empty_branch')
151
 
        os.chdir('empty_branch')
152
 
        self.runbzr('init')
153
 
        os.mkdir('branch')
154
 
        os.chdir('branch')
155
 
        self.runbzr('init')
156
 
        file('foo.c', 'wt').write('int main() {}')
157
 
        file('bar.c', 'wt').write('int main() {}')
158
 
        os.chdir('..')
159
 
        self.runbzr(['add', 'branch/foo.c'])
160
 
        self.runbzr(['add', 'branch'])
161
 
        # can't commit files in different trees; sane error
162
 
        self.runbzr('commit -m newstuff branch/foo.c .', retcode=3)
163
 
        self.runbzr('commit -m newstuff branch/foo.c')
164
 
        self.runbzr('commit -m newstuff branch')
165
 
        self.runbzr('commit -m newstuff branch', retcode=3)
166
 
 
167
127
    def test_ignore_patterns(self):
168
128
        self.runbzr('init')
169
129
        self.assertEquals(self.capture('unknowns'), '')
341
301
        os.chdir('b')
342
302
        self.runbzr('commit -m foo --unchanged')
343
303
        os.chdir('..')
344
 
        # naughty - abstraction violations RBC 20050928  
345
 
        print "test_branch used to delete the stores, how is this meant to work ?"
346
 
        #shutil.rmtree('a/.bzr/revision-store')
347
 
        #shutil.rmtree('a/.bzr/inventory-store', ignore_errors=True)
348
 
        #shutil.rmtree('a/.bzr/text-store', ignore_errors=True)
349
 
        self.runbzr('branch a d --basis b')
 
304
 
 
305
    def test_branch_basis(self):
 
306
        # ensure that basis really does grab from the basis by having incomplete source
 
307
        tree = self.make_branch_and_tree('commit_tree')
 
308
        self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
 
309
        tree.add('foo')
 
310
        tree.commit('revision 1', rev_id='1')
 
311
        source = self.make_branch_and_tree('source')
 
312
        # this gives us an incomplete repository
 
313
        tree.bzrdir.open_repository().copy_content_into(source.branch.repository)
 
314
        tree.commit('revision 2', rev_id='2', allow_pointless=True)
 
315
        tree.bzrdir.open_branch().copy_content_into(source.branch)
 
316
        tree.copy_content_into(source)
 
317
        self.assertFalse(source.branch.repository.has_revision('2'))
 
318
        dir = source.bzrdir
 
319
        self.runbzr('branch source target --basis commit_tree')
 
320
        target = bzrdir.BzrDir.open('target')
 
321
        self.assertEqual('2', target.open_branch().last_revision())
 
322
        self.assertEqual('2', target.open_workingtree().last_revision())
 
323
        self.assertTrue(target.open_branch().repository.has_revision('2'))
350
324
 
351
325
    def test_merge(self):
352
326
        from bzrlib.branch import Branch
376
350
        self.runbzr('merge ../b -r last:1')
377
351
        self.check_file_contents('goodbye', 'quux')
378
352
        # Merging a branch pulls its revision into the tree
379
 
        a = Branch.open('.')
 
353
        a = WorkingTree.open('.')
380
354
        b = Branch.open('../b')
381
 
        a.repository.get_revision_xml(b.last_revision())
382
 
        self.log('pending merges: %s', a.working_tree().pending_merges())
383
 
        self.assertEquals(a.working_tree().pending_merges(),
 
355
        a.branch.repository.get_revision_xml(b.last_revision())
 
356
        self.log('pending merges: %s', a.pending_merges())
 
357
        self.assertEquals(a.pending_merges(),
384
358
                          [b.last_revision()])
385
359
        self.runbzr('commit -m merged')
386
360
        self.runbzr('merge ../b -r last:1')
387
 
        self.assertEqual(Branch.open('.').working_tree().pending_merges(), [])
 
361
        self.assertEqual(a.pending_merges(), [])
388
362
 
389
363
    def test_merge_with_missing_file(self):
390
364
        """Merge handles missing file conflicts"""
688
662
        ass = self.assert_
689
663
        chdir = os.chdir
690
664
        
691
 
        t = WorkingTree.create_standalone('.')
 
665
        t = self.make_branch_and_tree('.')
692
666
        b = t.branch
693
667
        self.build_tree(['src/', 'README'])
694
668
        
751
725
        assert '|||||||' not in conflict_text
752
726
        assert 'hi world' not in conflict_text
753
727
        os.unlink('hello.OTHER')
 
728
        os.unlink('question.OTHER')
 
729
        self.runbzr('remerge jello --merge-type weave', retcode=3)
754
730
        self.runbzr('remerge hello --merge-type weave', retcode=1)
755
731
        assert os.path.exists('hello.OTHER')
 
732
        self.assertIs(False, os.path.exists('question.OTHER'))
756
733
        file_id = self.runbzr('file-id hello')
757
734
        file_id = self.runbzr('file-id hello.THIS', retcode=3)
758
735
        self.runbzr('remerge --merge-type weave', retcode=1)
814
791
        self.runbzr('commit -m conflicts')
815
792
        self.assertEquals(result, "")
816
793
 
817
 
    def test_resign(self):
818
 
        """Test re signing of data."""
819
 
        import bzrlib.gpg
820
 
        oldstrategy = bzrlib.gpg.GPGStrategy
821
 
        wt = WorkingTree.create_standalone('.')
822
 
        branch = wt.branch
823
 
        wt.commit("base", allow_pointless=True, rev_id='A')
824
 
        try:
825
 
            # monkey patch gpg signing mechanism
826
 
            from bzrlib.testament import Testament
827
 
            bzrlib.gpg.GPGStrategy = bzrlib.gpg.LoopbackGPGStrategy
828
 
            self.runbzr('re-sign -r revid:A')
829
 
            self.assertEqual(Testament.from_revision(branch.repository,
830
 
                             'A').as_short_text(),
831
 
                             branch.repository.revision_store.get('A', 
832
 
                             'sig').read())
833
 
        finally:
834
 
            bzrlib.gpg.GPGStrategy = oldstrategy
835
 
            
836
 
    def test_resign_range(self):
837
 
        import bzrlib.gpg
838
 
        oldstrategy = bzrlib.gpg.GPGStrategy
839
 
        wt = WorkingTree.create_standalone('.')
840
 
        branch = wt.branch
841
 
        wt.commit("base", allow_pointless=True, rev_id='A')
842
 
        wt.commit("base", allow_pointless=True, rev_id='B')
843
 
        wt.commit("base", allow_pointless=True, rev_id='C')
844
 
        try:
845
 
            # monkey patch gpg signing mechanism
846
 
            from bzrlib.testament import Testament
847
 
            bzrlib.gpg.GPGStrategy = bzrlib.gpg.LoopbackGPGStrategy
848
 
            self.runbzr('re-sign -r 1..')
849
 
            self.assertEqual(
850
 
                Testament.from_revision(branch.repository,'A').as_short_text(),
851
 
                branch.repository.revision_store.get('A', 'sig').read())
852
 
            self.assertEqual(
853
 
                Testament.from_revision(branch.repository,'B').as_short_text(),
854
 
                branch.repository.revision_store.get('B', 'sig').read())
855
 
            self.assertEqual(Testament.from_revision(branch.repository,
856
 
                             'C').as_short_text(),
857
 
                             branch.repository.revision_store.get('C', 
858
 
                             'sig').read())
859
 
        finally:
860
 
            bzrlib.gpg.GPGStrategy = oldstrategy
861
 
 
862
794
    def test_push(self):
863
795
        # create a source branch
864
796
        os.mkdir('my-branch')
905
837
        self.runbzr('missing ../missing/new-branch')
906
838
 
907
839
    def test_external_command(self):
908
 
        """test that external commands can be run by setting the path"""
 
840
        """Test that external commands can be run by setting the path
 
841
        """
 
842
        # We don't at present run bzr in a subprocess for blackbox tests, and so 
 
843
        # don't really capture stdout, only the internal python stream.
 
844
        # Therefore we don't use a subcommand that produces any output or does
 
845
        # anything -- we just check that it can be run successfully.  
909
846
        cmd_name = 'test-command'
910
 
        output = 'Hello from test-command'
911
847
        if sys.platform == 'win32':
912
848
            cmd_name += '.bat'
913
 
            output += '\r\n'
914
 
        else:
915
 
            output += '\n'
916
 
 
917
849
        oldpath = os.environ.get('BZRPATH', None)
918
 
 
919
850
        bzr = self.capture
920
 
 
921
851
        try:
922
852
            if os.environ.has_key('BZRPATH'):
923
853
                del os.environ['BZRPATH']
927
857
                f.write('@echo off\n')
928
858
            else:
929
859
                f.write('#!/bin/sh\n')
930
 
            f.write('echo Hello from test-command')
 
860
            # f.write('echo Hello from test-command')
931
861
            f.close()
932
862
            os.chmod(cmd_name, 0755)
933
863
 
939
869
            os.environ['BZRPATH'] = '.'
940
870
 
941
871
            bzr(cmd_name)
942
 
            # The test suite does not capture stdout for external commands
943
 
            # this is because you have to have a real file object
944
 
            # to pass to Popen(stdout=FOO), and StringIO is not one of those.
945
 
            # (just replacing sys.stdout does not change a spawned objects stdout)
946
 
            #self.assertEquals(bzr(cmd_name), output)
947
872
 
948
873
            # Make sure empty path elements are ignored
949
874
            os.environ['BZRPATH'] = os.pathsep
1239
1164
 
1240
1165
    def test_branch(self):
1241
1166
        os.mkdir('from')
1242
 
        wt = WorkingTree.create_standalone('from')
 
1167
        wt = self.make_branch_and_tree('from')
1243
1168
        branch = wt.branch
1244
1169
        wt.commit('empty commit for nonsense', allow_pointless=True)
1245
 
        url = self.get_remote_url('from')
 
1170
        url = self.get_readonly_url('from')
1246
1171
        self.run_bzr('branch', url, 'to')
1247
1172
        branch = Branch.open('to')
1248
1173
        self.assertEqual(1, len(branch.revision_history()))
 
1174
        # the branch should be set in to to from
 
1175
        self.assertEqual(url + '/', branch.get_parent())
1249
1176
 
1250
1177
    def test_log(self):
1251
1178
        self.build_tree(['branch/', 'branch/file'])
1252
1179
        self.capture('init branch')
1253
1180
        self.capture('add branch/file')
1254
1181
        self.capture('commit -m foo branch')
1255
 
        url = self.get_remote_url('branch/file')
 
1182
        url = self.get_readonly_url('branch/file')
1256
1183
        output = self.capture('log %s' % url)
1257
1184
        self.assertEqual(8, len(output.split('\n')))
1258
1185
        
1261
1188
        self.capture('init branch')
1262
1189
        self.capture('add branch/file')
1263
1190
        self.capture('commit -m foo branch')
1264
 
        url = self.get_remote_url('branch/')
 
1191
        url = self.get_readonly_url('branch/')
1265
1192
        self.run_bzr('check', url)
1266
1193
    
 
1194
    def test_push(self):
 
1195
        # create a source branch
 
1196
        os.mkdir('my-branch')
 
1197
        os.chdir('my-branch')
 
1198
        self.run_bzr('init')
 
1199
        file('hello', 'wt').write('foo')
 
1200
        self.run_bzr('add', 'hello')
 
1201
        self.run_bzr('commit', '-m', 'setup')
 
1202
 
 
1203
        # with an explicit target work
 
1204
        self.run_bzr('push', self.get_url('output-branch'))
 
1205
 
1267
1206
    
1268
1207
class HTTPTests(TestCaseWithWebserver, RemoteTests):
1269
1208
    """Test various commands against a HTTP server."""