~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_selftest.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2006-09-24 18:53:11 UTC
  • mfrom: (2036.1.2 fail-test-keep-log)
  • Revision ID: pqm@pqm.ubuntu.com-20060924185311-aa722847c6e4c74c
(jam) don't delete logs for failed tests (and ensure this with new tests)

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
750
751
            revision_id = workingtree.get_parent_ids()[0]
751
752
            self.assertEndsWith(output_string.rstrip(), revision_id)
752
753
 
 
754
    def test_success_log_deleted(self):
 
755
        """Successful tests have their log deleted"""
 
756
 
 
757
        class LogTester(TestCase):
 
758
 
 
759
            def test_success(self):
 
760
                self.log('this will be removed\n')
 
761
 
 
762
        sio = cStringIO.StringIO()
 
763
        runner = TextTestRunner(stream=sio)
 
764
        test = LogTester('test_success')
 
765
        result = self.run_test_runner(runner, test)
 
766
 
 
767
        log = test._get_log()
 
768
        self.assertEqual("DELETED log file to reduce memory footprint", log)
 
769
        self.assertEqual('', test._log_contents)
 
770
        self.assertIs(None, test._log_file_name)
 
771
 
 
772
    def test_fail_log_kept(self):
 
773
        """Failed tests have their log kept"""
 
774
 
 
775
        class LogTester(TestCase):
 
776
 
 
777
            def test_fail(self):
 
778
                self.log('this will be kept\n')
 
779
                self.fail('this test fails')
 
780
 
 
781
        sio = cStringIO.StringIO()
 
782
        runner = TextTestRunner(stream=sio)
 
783
        test = LogTester('test_fail')
 
784
        result = self.run_test_runner(runner, test)
 
785
 
 
786
        text = sio.getvalue()
 
787
        self.assertContainsRe(text, 'this will be kept')
 
788
        self.assertContainsRe(text, 'this test fails')
 
789
 
 
790
        log = test._get_log()
 
791
        self.assertContainsRe(log, 'this will be kept')
 
792
        self.assertEqual(log, test._log_contents)
 
793
 
 
794
    def test_error_log_kept(self):
 
795
        """Tests with errors have their log kept"""
 
796
 
 
797
        class LogTester(TestCase):
 
798
 
 
799
            def test_error(self):
 
800
                self.log('this will be kept\n')
 
801
                raise ValueError('random exception raised')
 
802
 
 
803
        sio = cStringIO.StringIO()
 
804
        runner = TextTestRunner(stream=sio)
 
805
        test = LogTester('test_error')
 
806
        result = self.run_test_runner(runner, test)
 
807
 
 
808
        text = sio.getvalue()
 
809
        self.assertContainsRe(text, 'this will be kept')
 
810
        self.assertContainsRe(text, 'random exception raised')
 
811
 
 
812
        log = test._get_log()
 
813
        self.assertContainsRe(log, 'this will be kept')
 
814
        self.assertEqual(log, test._log_contents)
 
815
 
753
816
 
754
817
class TestTestCase(TestCase):
755
818
    """Tests that test the core bzrlib TestCase."""