~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Robert Collins
  • Date: 2005-11-28 05:13:41 UTC
  • mfrom: (1185.33.54 merge-recovered)
  • Revision ID: robertc@robertcollins.net-20051128051341-059936f2f29a12c8
Merge from Martin. Adjust check to work with HTTP again.

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
 
27
27
# XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
28
28
# Note: Please don't add new tests here, it's too big and bulky.  Instead add
29
 
# them into small suites for the particular function that's tested.
 
29
# them into small suites in bzrlib.tests.blackbox.test_FOO for the particular
 
30
# UI command/aspect that is being tested.
30
31
 
31
32
 
32
33
from cStringIO import StringIO
39
40
from bzrlib.clone import copy_branch
40
41
from bzrlib.errors import BzrCommandError
41
42
from bzrlib.osutils import has_symlinks
42
 
from bzrlib.selftest import TestCaseInTempDir, BzrTestBase
43
 
from bzrlib.selftest.HTTPTestUtil import TestCaseWithWebserver
 
43
from bzrlib.tests import TestCaseInTempDir, BzrTestBase
 
44
from bzrlib.tests.HTTPTestUtil import TestCaseWithWebserver
44
45
 
45
46
 
46
47
class ExternalBase(TestCaseInTempDir):
170
171
        self.runbzr('commit -m newstuff branch')
171
172
        self.runbzr('commit -m newstuff branch', retcode=3)
172
173
 
173
 
 
174
174
    def test_ignore_patterns(self):
175
175
        from bzrlib.branch import Branch
176
 
        
177
 
        b = Branch.initialize('.')
178
 
        self.assertEquals(list(b.unknowns()), [])
 
176
        Branch.initialize('.')
 
177
        self.assertEquals(self.capture('unknowns'), '')
179
178
 
180
179
        file('foo.tmp', 'wt').write('tmp files are ignored')
181
 
        self.assertEquals(list(b.unknowns()), [])
182
180
        self.assertEquals(self.capture('unknowns'), '')
183
181
 
184
182
        file('foo.c', 'wt').write('int main() {}')
185
 
        self.assertEquals(list(b.unknowns()), ['foo.c'])
186
183
        self.assertEquals(self.capture('unknowns'), 'foo.c\n')
187
184
 
188
185
        self.runbzr(['add', 'foo.c'])
190
187
 
191
188
        # 'ignore' works when creating the .bzignore file
192
189
        file('foo.blah', 'wt').write('blah')
193
 
        self.assertEquals(list(b.unknowns()), ['foo.blah'])
 
190
        self.assertEquals(self.capture('unknowns'), 'foo.blah\n')
194
191
        self.runbzr('ignore *.blah')
195
 
        self.assertEquals(list(b.unknowns()), [])
 
192
        self.assertEquals(self.capture('unknowns'), '')
196
193
        self.assertEquals(file('.bzrignore', 'rU').read(), '*.blah\n')
197
194
 
198
195
        # 'ignore' works when then .bzrignore file already exists
199
196
        file('garh', 'wt').write('garh')
200
 
        self.assertEquals(list(b.unknowns()), ['garh'])
201
197
        self.assertEquals(self.capture('unknowns'), 'garh\n')
202
198
        self.runbzr('ignore garh')
203
 
        self.assertEquals(list(b.unknowns()), [])
 
199
        self.assertEquals(self.capture('unknowns'), '')
204
200
        self.assertEquals(file('.bzrignore', 'rU').read(), '*.blah\ngarh\n')
205
201
 
206
202
    def test_revert(self):
315
311
        self.assertEqual(file('../first.gz/hello', 'rt').read(), 'foo')
316
312
        self.runbzr('export ../first.bz2 -r 1')
317
313
        self.assertEqual(file('../first.bz2/hello', 'rt').read(), 'foo')
 
314
 
 
315
        from tarfile import TarFile
318
316
        self.runbzr('export ../first.tar -r 1')
319
317
        self.assert_(os.path.isfile('../first.tar'))
320
 
        from tarfile import TarFile
321
318
        tf = TarFile('../first.tar')
322
319
        self.assert_('first/hello' in tf.getnames(), tf.getnames())
323
320
        self.assertEqual(tf.extractfile('first/hello').read(), 'foo')
329
326
        self.assert_(os.path.isfile('../first.tar.bz2'))
330
327
        self.runbzr('export ../first.tar.tbz2 -r 1')
331
328
        self.assert_(os.path.isfile('../first.tar.tbz2'))
 
329
 
332
330
        from bz2 import BZ2File
333
331
        tf = TarFile('../first.tar.tbz2', 
334
332
                     fileobj=BZ2File('../first.tar.tbz2', 'r'))
338
336
        tf = TarFile('../first2.tar')
339
337
        self.assert_('pizza/hello' in tf.getnames(), tf.getnames())
340
338
 
 
339
        from zipfile import ZipFile
 
340
        self.runbzr('export ../first.zip -r 1')
 
341
        self.failUnlessExists('../first.zip')
 
342
        zf = ZipFile('../first.zip')
 
343
        self.assert_('first/hello' in zf.namelist(), zf.namelist())
 
344
        self.assertEqual(zf.read('first/hello'), 'foo')
 
345
 
 
346
        self.runbzr('export ../first2.zip -r 1 --root pizza')
 
347
        zf = ZipFile('../first2.zip')
 
348
        self.assert_('pizza/hello' in zf.namelist(), zf.namelist())
 
349
        
 
350
        self.runbzr('export ../first-zip --format=zip -r 1')
 
351
        zf = ZipFile('../first-zip')
 
352
        self.assert_('first-zip/hello' in zf.namelist(), zf.namelist())
 
353
 
341
354
    def test_diff(self):
342
355
        self.example_branch()
343
356
        file('hello', 'wt').write('hello world!')
354
367
    def test_diff_branches(self):
355
368
        self.build_tree(['branch1/', 'branch1/file', 'branch2/'], line_endings='binary')
356
369
        branch = Branch.initialize('branch1')
357
 
        branch.add(['file'])
 
370
        branch.working_tree().add(['file'])
358
371
        branch.working_tree().commit('add file')
359
372
        copy_branch(branch, 'branch2')
360
373
        print >> open('branch2/file', 'wb'), 'new content'
737
750
        results = sorted(out.rstrip('\n').split('\n'))
738
751
        self.assertEquals([''], results)
739
752
 
 
753
    def test_add_in_unversioned(self):
 
754
        """Try to add a file in an unversioned directory.
 
755
 
 
756
        "bzr add" should add the parent(s) as necessary.
 
757
        """
 
758
        from bzrlib.branch import Branch
 
759
        Branch.initialize('.')
 
760
        self.build_tree(['inertiatic/', 'inertiatic/esp'])
 
761
        self.assertEquals(self.capture('unknowns'), 'inertiatic\n')
 
762
        self.run_bzr('add', 'inertiatic/esp')
 
763
        self.assertEquals(self.capture('unknowns'), '')
 
764
 
 
765
        # Multiple unversioned parents
 
766
        self.build_tree(['veil/', 'veil/cerpin/', 'veil/cerpin/taxt'])
 
767
        self.assertEquals(self.capture('unknowns'), 'veil\n')
 
768
        self.run_bzr('add', 'veil/cerpin/taxt')
 
769
        self.assertEquals(self.capture('unknowns'), '')
 
770
 
 
771
        # Check whacky paths work
 
772
        self.build_tree(['cicatriz/', 'cicatriz/esp'])
 
773
        self.assertEquals(self.capture('unknowns'), 'cicatriz\n')
 
774
        self.run_bzr('add', 'inertiatic/../cicatriz/esp')
 
775
        self.assertEquals(self.capture('unknowns'), '')
 
776
 
 
777
    def test_add_in_versioned(self):
 
778
        """Try to add a file in a versioned directory.
 
779
 
 
780
        "bzr add" should do this happily.
 
781
        """
 
782
        from bzrlib.branch import Branch
 
783
        Branch.initialize('.')
 
784
        self.build_tree(['inertiatic/', 'inertiatic/esp'])
 
785
        self.assertEquals(self.capture('unknowns'), 'inertiatic\n')
 
786
        self.run_bzr('add', '--no-recurse', 'inertiatic')
 
787
        self.assertEquals(self.capture('unknowns'), 'inertiatic'+os.sep+'esp\n')
 
788
        self.run_bzr('add', 'inertiatic/esp')
 
789
        self.assertEquals(self.capture('unknowns'), '')
 
790
 
 
791
    def test_subdir_add(self):
 
792
        """Add in subdirectory should add only things from there down"""
 
793
        from bzrlib.branch import Branch
 
794
        
 
795
        eq = self.assertEqual
 
796
        ass = self.assert_
 
797
        chdir = os.chdir
 
798
        
 
799
        b = Branch.initialize('.')
 
800
        t = b.working_tree()
 
801
        self.build_tree(['src/', 'README'])
 
802
        
 
803
        eq(sorted(t.unknowns()),
 
804
           ['README', 'src'])
 
805
        
 
806
        self.run_bzr('add', 'src')
 
807
        
 
808
        self.build_tree(['src/foo.c'])
 
809
        
 
810
        chdir('src')
 
811
        self.run_bzr('add')
 
812
        
 
813
        self.assertEquals(self.capture('unknowns'), 'README\n')
 
814
        eq(len(t.read_working_inventory()), 3)
 
815
                
 
816
        chdir('..')
 
817
        self.run_bzr('add')
 
818
        self.assertEquals(self.capture('unknowns'), '')
 
819
        self.run_bzr('check')
 
820
 
740
821
    def test_unknown_command(self):
741
822
        """Handling of unknown command."""
742
823
        out, err = self.run_bzr_captured(['fluffy-badger'],
1251
1332
    def test_log(self):
1252
1333
        self.build_tree(['branch/', 'branch/file'])
1253
1334
        branch = Branch.initialize('branch')
1254
 
        branch.add(['file'])
 
1335
        branch.working_tree().add(['file'])
1255
1336
        branch.working_tree().commit('add file', rev_id='A')
1256
1337
        url = self.get_remote_url('branch/file')
1257
1338
        output = self.capture('log %s' % url)
1260
1341
    def test_check(self):
1261
1342
        self.build_tree(['branch/', 'branch/file'])
1262
1343
        branch = Branch.initialize('branch')
1263
 
        branch.add(['file'])
 
1344
        branch.working_tree().add(['file'])
1264
1345
        branch.working_tree().commit('add file', rev_id='A')
1265
 
        url = self.get_remote_url('branch/file')
 
1346
        url = self.get_remote_url('branch/')
1266
1347
        self.run_bzr('check', url)