/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/test_selftest.py

  • Committer: John Arbash Meinel
  • Date: 2006-10-06 05:53:44 UTC
  • mfrom: (2063 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2071.
  • Revision ID: john@arbash-meinel.com-20061006055344-e73b97b7c6ca6e72
[merge] bzr.dev 2063

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
 
16
16
"""Tests for the test framework."""
17
17
 
 
18
import cStringIO
18
19
import os
19
20
from StringIO import StringIO
20
21
import sys
22
23
import unittest
23
24
import warnings
24
25
 
25
 
from bzrlib import osutils
 
26
from bzrlib import osutils, memorytree
26
27
import bzrlib
27
28
from bzrlib.progress import _BaseProgressBar
28
29
from bzrlib.tests import (
29
30
                          ChrootedTestCase,
30
31
                          TestCase,
31
32
                          TestCaseInTempDir,
 
33
                          TestCaseWithMemoryTransport,
32
34
                          TestCaseWithTransport,
33
35
                          TestSkipped,
34
36
                          TestSuite,
35
37
                          TextTestRunner,
36
38
                          )
 
39
from bzrlib.tests.test_sftp_transport import TestCaseWithSFTPServer
37
40
from bzrlib.tests.TestUtil import _load_module_by_name
38
41
import bzrlib.errors as errors
39
42
from bzrlib import symbol_versioning
40
43
from bzrlib.symbol_versioning import zero_ten, zero_eleven
41
44
from bzrlib.trace import note
 
45
from bzrlib.transport.memory import MemoryServer, MemoryTransport
42
46
from bzrlib.version import _get_bzr_source_tree
43
47
 
44
48
 
60
64
        """Test logs are captured when a test fails."""
61
65
        self.log('a test message')
62
66
        self._log_file.flush()
63
 
        self.assertContainsRe(self._get_log(), 'a test message\n')
 
67
        self.assertContainsRe(self._get_log(keep_log_file=True),
 
68
                              'a test message\n')
64
69
 
65
70
 
66
71
class TestTreeShape(TestCaseInTempDir):
430
435
        self.assertEqual(self.test_home_dir, os.environ['HOME'])
431
436
 
432
437
 
 
438
class TestTestCaseWithMemoryTransport(TestCaseWithMemoryTransport):
 
439
 
 
440
    def test_home_is_non_existant_dir_under_root(self):
 
441
        """The test_home_dir for TestCaseWithMemoryTransport is missing.
 
442
 
 
443
        This is because TestCaseWithMemoryTransport is for tests that do not
 
444
        need any disk resources: they should be hooked into bzrlib in such a 
 
445
        way that no global settings are being changed by the test (only a 
 
446
        few tests should need to do that), and having a missing dir as home is
 
447
        an effective way to ensure that this is the case.
 
448
        """
 
449
        self.assertEqual(self.TEST_ROOT + "/MemoryTransportMissingHomeDir",
 
450
            self.test_home_dir)
 
451
        self.assertEqual(self.test_home_dir, os.environ['HOME'])
 
452
        
 
453
    def test_cwd_is_TEST_ROOT(self):
 
454
        self.assertEqual(self.test_dir, self.TEST_ROOT)
 
455
        cwd = osutils.getcwd()
 
456
        self.assertEqual(self.test_dir, cwd)
 
457
 
 
458
    def test_make_branch_and_memory_tree(self):
 
459
        """In TestCaseWithMemoryTransport we should not make the branch on disk.
 
460
 
 
461
        This is hard to comprehensively robustly test, so we settle for making
 
462
        a branch and checking no directory was created at its relpath.
 
463
        """
 
464
        tree = self.make_branch_and_memory_tree('dir')
 
465
        self.failIfExists('dir')
 
466
        self.assertIsInstance(tree, memorytree.MemoryTree)
 
467
 
 
468
 
433
469
class TestTestCaseWithTransport(TestCaseWithTransport):
434
470
    """Tests for the convenience functions TestCaseWithTransport introduces."""
435
471
 
474
510
        self.assertRaises(AssertionError, self.assertIsDirectory, 'not_here', t)
475
511
 
476
512
 
 
513
class TestTestCaseTransports(TestCaseWithTransport):
 
514
 
 
515
    def setUp(self):
 
516
        super(TestTestCaseTransports, self).setUp()
 
517
        self.transport_server = MemoryServer
 
518
 
 
519
    def test_make_bzrdir_preserves_transport(self):
 
520
        t = self.get_transport()
 
521
        result_bzrdir = self.make_bzrdir('subdir')
 
522
        self.assertIsInstance(result_bzrdir.transport, 
 
523
                              MemoryTransport)
 
524
        # should not be on disk, should only be in memory
 
525
        self.failIfExists('subdir')
 
526
 
 
527
 
477
528
class TestChrootedTest(ChrootedTestCase):
478
529
 
479
530
    def test_root_is_root(self):
732
783
            revision_id = workingtree.get_parent_ids()[0]
733
784
            self.assertEndsWith(output_string.rstrip(), revision_id)
734
785
 
 
786
    def test_success_log_deleted(self):
 
787
        """Successful tests have their log deleted"""
 
788
 
 
789
        class LogTester(TestCase):
 
790
 
 
791
            def test_success(self):
 
792
                self.log('this will be removed\n')
 
793
 
 
794
        sio = cStringIO.StringIO()
 
795
        runner = TextTestRunner(stream=sio)
 
796
        test = LogTester('test_success')
 
797
        result = self.run_test_runner(runner, test)
 
798
 
 
799
        log = test._get_log()
 
800
        self.assertEqual("DELETED log file to reduce memory footprint", log)
 
801
        self.assertEqual('', test._log_contents)
 
802
        self.assertIs(None, test._log_file_name)
 
803
 
 
804
    def test_fail_log_kept(self):
 
805
        """Failed tests have their log kept"""
 
806
 
 
807
        class LogTester(TestCase):
 
808
 
 
809
            def test_fail(self):
 
810
                self.log('this will be kept\n')
 
811
                self.fail('this test fails')
 
812
 
 
813
        sio = cStringIO.StringIO()
 
814
        runner = TextTestRunner(stream=sio)
 
815
        test = LogTester('test_fail')
 
816
        result = self.run_test_runner(runner, test)
 
817
 
 
818
        text = sio.getvalue()
 
819
        self.assertContainsRe(text, 'this will be kept')
 
820
        self.assertContainsRe(text, 'this test fails')
 
821
 
 
822
        log = test._get_log()
 
823
        self.assertContainsRe(log, 'this will be kept')
 
824
        self.assertEqual(log, test._log_contents)
 
825
 
 
826
    def test_error_log_kept(self):
 
827
        """Tests with errors have their log kept"""
 
828
 
 
829
        class LogTester(TestCase):
 
830
 
 
831
            def test_error(self):
 
832
                self.log('this will be kept\n')
 
833
                raise ValueError('random exception raised')
 
834
 
 
835
        sio = cStringIO.StringIO()
 
836
        runner = TextTestRunner(stream=sio)
 
837
        test = LogTester('test_error')
 
838
        result = self.run_test_runner(runner, test)
 
839
 
 
840
        text = sio.getvalue()
 
841
        self.assertContainsRe(text, 'this will be kept')
 
842
        self.assertContainsRe(text, 'random exception raised')
 
843
 
 
844
        log = test._get_log()
 
845
        self.assertContainsRe(log, 'this will be kept')
 
846
        self.assertEqual(log, test._log_contents)
 
847
 
735
848
 
736
849
class TestTestCase(TestCase):
737
850
    """Tests that test the core bzrlib TestCase."""
903
1016
        self.assertIsInstance(bzrlib.bzrdir.BzrDir.open('b')._format,
904
1017
                              bzrlib.bzrdir.BzrDirFormat6)
905
1018
 
 
1019
    def test_make_branch_and_memory_tree(self):
 
1020
        # we should be able to get a new branch and a mutable tree from
 
1021
        # TestCaseWithTransport
 
1022
        tree = self.make_branch_and_memory_tree('a')
 
1023
        self.assertIsInstance(tree, bzrlib.memorytree.MemoryTree)
 
1024
 
 
1025
 
 
1026
class TestSFTPMakeBranchAndTree(TestCaseWithSFTPServer):
 
1027
 
 
1028
    def test_make_tree_for_sftp_branch(self):
 
1029
        """Transports backed by local directories create local trees."""
 
1030
 
 
1031
        tree = self.make_branch_and_tree('t1')
 
1032
        base = tree.bzrdir.root_transport.base
 
1033
        self.failIf(base.startswith('sftp'),
 
1034
                'base %r is on sftp but should be local' % base)
 
1035
        self.assertEquals(tree.bzrdir.root_transport,
 
1036
                tree.branch.bzrdir.root_transport)
 
1037
        self.assertEquals(tree.bzrdir.root_transport,
 
1038
                tree.branch.repository.bzrdir.root_transport)
 
1039
 
906
1040
 
907
1041
class TestSelftest(TestCase):
908
1042
    """Tests of bzrlib.tests.selftest."""