~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

[merge] update from bzr.dev

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
 
from bzrlib.clone import copy_branch
45
44
from bzrlib.errors import BzrCommandError
46
45
from bzrlib.osutils import has_symlinks, pathjoin
47
46
from bzrlib.tests.HTTPTestUtil import TestCaseWithWebserver
 
47
from bzrlib.tests.test_sftp_transport import TestCaseWithSFTPServer
48
48
from bzrlib.tests.blackbox import ExternalBase
 
49
from bzrlib.workingtree import WorkingTree
 
50
 
49
51
 
50
52
class TestCommands(ExternalBase):
51
53
 
163
165
        self.runbzr('commit -m newstuff branch', retcode=3)
164
166
 
165
167
    def test_ignore_patterns(self):
166
 
        from bzrlib.branch import Branch
167
 
        Branch.initialize('.')
 
168
        self.runbzr('init')
168
169
        self.assertEquals(self.capture('unknowns'), '')
169
170
 
170
171
        file('foo.tmp', 'wt').write('tmp files are ignored')
258
259
 
259
260
    def test_mv_modes(self):
260
261
        """Test two modes of operation for mv"""
261
 
        from bzrlib.branch import Branch
262
 
        b = Branch.initialize('.')
 
262
        self.runbzr('init')
263
263
        self.build_tree(['a', 'c', 'subdir/'])
264
264
        self.run_bzr_captured(['add', self.test_dir])
265
265
        self.run_bzr_captured(['mv', 'a', 'b'])
345
345
        zf = ZipFile('../first-zip')
346
346
        self.assert_('first-zip/hello' in zf.namelist(), zf.namelist())
347
347
 
348
 
    def test_diff(self):
349
 
        self.example_branch()
350
 
        file('hello', 'wt').write('hello world!')
351
 
        self.runbzr('commit -m fixing hello')
352
 
        output = self.runbzr('diff -r 2..3', backtick=1, retcode=1)
353
 
        self.assert_('\n+hello world!' in output)
354
 
        output = self.runbzr('diff -r last:3..last:1', backtick=1, retcode=1)
355
 
        self.assert_('\n+baz' in output)
356
 
        file('moo', 'wb').write('moo')
357
 
        self.runbzr('add moo')
358
 
        os.unlink('moo')
359
 
        self.runbzr('diff')
360
 
 
361
 
    def test_diff_branches(self):
362
 
        self.build_tree(['branch1/', 'branch1/file', 'branch2/'], line_endings='binary')
363
 
        branch = Branch.initialize('branch1')
364
 
        branch.working_tree().add(['file'])
365
 
        branch.working_tree().commit('add file')
366
 
        copy_branch(branch, 'branch2')
367
 
        print >> open('branch2/file', 'wb'), 'new content'
368
 
        branch2 = Branch.open('branch2')
369
 
        branch2.working_tree().commit('update file')
370
 
        # should open branch1 and diff against branch2, 
371
 
        output = self.run_bzr_captured(['diff', '-r', 'branch:branch2', 
372
 
                                        'branch1'],
373
 
                                       retcode=1)
374
 
        self.assertEquals(("=== modified file 'file'\n"
375
 
                           "--- file\t\n"
376
 
                           "+++ file\t\n"
377
 
                           "@@ -1,1 +1,1 @@\n"
378
 
                           "-new content\n"
379
 
                           "+contents of branch1/file\n"
380
 
                           "\n", ''), output)
381
 
        output = self.run_bzr_captured(['diff', 'branch2', 'branch1'],
382
 
                                       retcode=1)
383
 
        self.assertEqualDiff(("=== modified file 'file'\n"
384
 
                              "--- file\t\n"
385
 
                              "+++ file\t\n"
386
 
                              "@@ -1,1 +1,1 @@\n"
387
 
                              "-new content\n"
388
 
                              "+contents of branch1/file\n"
389
 
                              "\n", ''), output)
390
 
 
391
 
 
392
348
    def test_branch(self):
393
349
        """Branch from one branch to another."""
394
350
        os.mkdir('a')
438
394
        # Merging a branch pulls its revision into the tree
439
395
        a = Branch.open('.')
440
396
        b = Branch.open('../b')
441
 
        a.get_revision_xml(b.last_revision())
 
397
        a.repository.get_revision_xml(b.last_revision())
442
398
        self.log('pending merges: %s', a.working_tree().pending_merges())
443
399
        self.assertEquals(a.working_tree().pending_merges(),
444
400
                          [b.last_revision()])
597
553
                  'subdir/b\n'
598
554
                  , '--versioned')
599
555
 
 
556
    def test_cat(self):
 
557
        self.runbzr('init')
 
558
        file("myfile", "wb").write("My contents\n")
 
559
        self.runbzr('add')
 
560
        self.runbzr('commit -m myfile')
 
561
        self.run_bzr_captured('cat -r 1 myfile'.split(' '))
 
562
 
600
563
    def test_pull_verbose(self):
601
564
        """Pull changes from one branch to another and watch the output."""
602
565
 
669
632
        
670
633
    def test_add_reports(self):
671
634
        """add command prints the names of added files."""
672
 
        b = Branch.initialize('.')
 
635
        self.runbzr('init')
673
636
        self.build_tree(['top.txt', 'dir/', 'dir/sub.txt', 'CVS'])
674
637
        out = self.run_bzr_captured(['add'], retcode=0)[0]
675
638
        # the ordering is not defined at the moment
690
653
 
691
654
    def test_add_quiet_is(self):
692
655
        """add -q does not print the names of added files."""
693
 
        b = Branch.initialize('.')
 
656
        self.runbzr('init')
694
657
        self.build_tree(['top.txt', 'dir/', 'dir/sub.txt'])
695
658
        out = self.run_bzr_captured(['add', '-q'], retcode=0)[0]
696
659
        # the ordering is not defined at the moment
702
665
 
703
666
        "bzr add" should add the parent(s) as necessary.
704
667
        """
705
 
        from bzrlib.branch import Branch
706
 
        Branch.initialize('.')
 
668
        self.runbzr('init')
707
669
        self.build_tree(['inertiatic/', 'inertiatic/esp'])
708
670
        self.assertEquals(self.capture('unknowns'), 'inertiatic\n')
709
671
        self.run_bzr('add', 'inertiatic/esp')
726
688
 
727
689
        "bzr add" should do this happily.
728
690
        """
729
 
        from bzrlib.branch import Branch
730
 
        Branch.initialize('.')
 
691
        self.runbzr('init')
731
692
        self.build_tree(['inertiatic/', 'inertiatic/esp'])
732
693
        self.assertEquals(self.capture('unknowns'), 'inertiatic\n')
733
694
        self.run_bzr('add', '--no-recurse', 'inertiatic')
737
698
 
738
699
    def test_subdir_add(self):
739
700
        """Add in subdirectory should add only things from there down"""
740
 
        from bzrlib.branch import Branch
 
701
        from bzrlib.workingtree import WorkingTree
741
702
        
742
703
        eq = self.assertEqual
743
704
        ass = self.assert_
744
705
        chdir = os.chdir
745
706
        
746
 
        b = Branch.initialize('.')
747
 
        t = b.working_tree()
 
707
        t = WorkingTree.create_standalone('.')
 
708
        b = t.branch
748
709
        self.build_tree(['src/', 'README'])
749
710
        
750
711
        eq(sorted(t.unknowns()),
824
785
        self.runbzr('commit -m done',)
825
786
        self.runbzr('remerge', retcode=3)
826
787
 
 
788
    def test_status(self):
 
789
        os.mkdir('branch1')
 
790
        os.chdir('branch1')
 
791
        self.runbzr('init')
 
792
        self.runbzr('commit --unchanged --message f')
 
793
        self.runbzr('branch . ../branch2')
 
794
        self.runbzr('branch . ../branch3')
 
795
        self.runbzr('commit --unchanged --message peter')
 
796
        os.chdir('../branch2')
 
797
        self.runbzr('merge ../branch1')
 
798
        self.runbzr('commit --unchanged --message pumpkin')
 
799
        os.chdir('../branch3')
 
800
        self.runbzr('merge ../branch2')
 
801
        message = self.capture('status')
 
802
 
827
803
 
828
804
    def test_conflicts(self):
829
805
        """Handling of merge conflicts"""
858
834
        """Test re signing of data."""
859
835
        import bzrlib.gpg
860
836
        oldstrategy = bzrlib.gpg.GPGStrategy
861
 
        branch = Branch.initialize('.')
862
 
        branch.working_tree().commit("base", allow_pointless=True, rev_id='A')
 
837
        wt = WorkingTree.create_standalone('.')
 
838
        branch = wt.branch
 
839
        wt.commit("base", allow_pointless=True, rev_id='A')
863
840
        try:
864
841
            # monkey patch gpg signing mechanism
865
842
            from bzrlib.testament import Testament
866
843
            bzrlib.gpg.GPGStrategy = bzrlib.gpg.LoopbackGPGStrategy
867
844
            self.runbzr('re-sign -r revid:A')
868
 
            self.assertEqual(Testament.from_revision(branch,'A').as_short_text(),
869
 
                             branch.revision_store.get('A', 'sig').read())
 
845
            self.assertEqual(Testament.from_revision(branch.repository,
 
846
                             'A').as_short_text(),
 
847
                             branch.repository.revision_store.get('A', 
 
848
                             'sig').read())
870
849
        finally:
871
850
            bzrlib.gpg.GPGStrategy = oldstrategy
872
851
            
873
852
    def test_resign_range(self):
874
853
        import bzrlib.gpg
875
854
        oldstrategy = bzrlib.gpg.GPGStrategy
876
 
        branch = Branch.initialize('.')
877
 
        branch.working_tree().commit("base", allow_pointless=True, rev_id='A')
878
 
        branch.working_tree().commit("base", allow_pointless=True, rev_id='B')
879
 
        branch.working_tree().commit("base", allow_pointless=True, rev_id='C')
 
855
        wt = WorkingTree.create_standalone('.')
 
856
        branch = wt.branch
 
857
        wt.commit("base", allow_pointless=True, rev_id='A')
 
858
        wt.commit("base", allow_pointless=True, rev_id='B')
 
859
        wt.commit("base", allow_pointless=True, rev_id='C')
880
860
        try:
881
861
            # monkey patch gpg signing mechanism
882
862
            from bzrlib.testament import Testament
883
863
            bzrlib.gpg.GPGStrategy = bzrlib.gpg.LoopbackGPGStrategy
884
864
            self.runbzr('re-sign -r 1..')
885
 
            self.assertEqual(Testament.from_revision(branch,'A').as_short_text(),
886
 
                             branch.revision_store.get('A', 'sig').read())
887
 
            self.assertEqual(Testament.from_revision(branch,'B').as_short_text(),
888
 
                             branch.revision_store.get('B', 'sig').read())
889
 
            self.assertEqual(Testament.from_revision(branch,'C').as_short_text(),
890
 
                             branch.revision_store.get('C', 'sig').read())
 
865
            self.assertEqual(
 
866
                Testament.from_revision(branch.repository,'A').as_short_text(),
 
867
                branch.repository.revision_store.get('A', 'sig').read())
 
868
            self.assertEqual(
 
869
                Testament.from_revision(branch.repository,'B').as_short_text(),
 
870
                branch.repository.revision_store.get('B', 'sig').read())
 
871
            self.assertEqual(Testament.from_revision(branch.repository,
 
872
                             'C').as_short_text(),
 
873
                             branch.repository.revision_store.get('C', 
 
874
                             'sig').read())
891
875
        finally:
892
876
            bzrlib.gpg.GPGStrategy = oldstrategy
893
877
 
1266
1250
            progress("skipping symlink tests")
1267
1251
 
1268
1252
 
1269
 
class HttpTests(TestCaseWithWebserver):
 
1253
class RemoteTests(object):
1270
1254
    """Test bzr ui commands against remote branches."""
1271
1255
 
1272
1256
    def test_branch(self):
1273
1257
        os.mkdir('from')
1274
 
        branch = Branch.initialize('from')
1275
 
        branch.working_tree().commit('empty commit for nonsense', allow_pointless=True)
 
1258
        wt = WorkingTree.create_standalone('from')
 
1259
        branch = wt.branch
 
1260
        wt.commit('empty commit for nonsense', allow_pointless=True)
1276
1261
        url = self.get_remote_url('from')
1277
1262
        self.run_bzr('branch', url, 'to')
1278
1263
        branch = Branch.open('to')
1280
1265
 
1281
1266
    def test_log(self):
1282
1267
        self.build_tree(['branch/', 'branch/file'])
1283
 
        branch = Branch.initialize('branch')
1284
 
        branch.working_tree().add(['file'])
1285
 
        branch.working_tree().commit('add file', rev_id='A')
 
1268
        self.capture('init branch')
 
1269
        self.capture('add branch/file')
 
1270
        self.capture('commit -m foo branch')
1286
1271
        url = self.get_remote_url('branch/file')
1287
1272
        output = self.capture('log %s' % url)
1288
1273
        self.assertEqual(8, len(output.split('\n')))
1289
1274
        
1290
1275
    def test_check(self):
1291
1276
        self.build_tree(['branch/', 'branch/file'])
1292
 
        branch = Branch.initialize('branch')
1293
 
        branch.working_tree().add(['file'])
1294
 
        branch.working_tree().commit('add file', rev_id='A')
 
1277
        self.capture('init branch')
 
1278
        self.capture('add branch/file')
 
1279
        self.capture('commit -m foo branch')
1295
1280
        url = self.get_remote_url('branch/')
1296
1281
        self.run_bzr('check', url)
 
1282
    
 
1283
    
 
1284
class HTTPTests(TestCaseWithWebserver, RemoteTests):
 
1285
    """Test various commands against a HTTP server."""
 
1286
    
 
1287
    
 
1288
class SFTPTestsAbsolute(TestCaseWithSFTPServer, RemoteTests):
 
1289
    """Test various commands against a SFTP server using abs paths."""
 
1290
 
 
1291
    
 
1292
class SFTPTestsAbsoluteSibling(TestCaseWithSFTPServer, RemoteTests):
 
1293
    """Test various commands against a SFTP server using abs paths."""
 
1294
 
 
1295
    def setUp(self):
 
1296
        super(SFTPTestsAbsoluteSibling, self).setUp()
 
1297
        self._override_home = '/dev/noone/runs/tests/here'
 
1298
 
 
1299
    
 
1300
class SFTPTestsRelative(TestCaseWithSFTPServer, RemoteTests):
 
1301
    """Test various commands against a SFTP server using homedir rel paths."""
 
1302
 
 
1303
    def setUp(self):
 
1304
        super(SFTPTestsRelative, self).setUp()
 
1305
        self._get_remote_is_absolute = False