~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: 2011-08-03 17:45:55 UTC
  • mfrom: (6042.2.4 testtools-0.9.12)
  • Revision ID: pqm@pqm.ubuntu.com-20110803174555-pmpu6ms4lgjudxzf
(jelmer) Fix support for testtools 0.9.12. (Jelmer Vernooij)

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
from testtools import (
30
30
    ExtendedToOriginalDecorator,
31
31
    MultiTestResult,
 
32
    __version__ as testtools_version,
32
33
    )
33
34
from testtools.content import Content
34
35
from testtools.content_type import ContentType
1072
1073
                self.expectFailure("No absolute truth", self.assertTrue, True)
1073
1074
        runner = tests.TextTestRunner(stream=StringIO())
1074
1075
        result = self.run_test_runner(runner, Test("test_truth"))
1075
 
        self.assertContainsRe(runner.stream.getvalue(),
1076
 
            "=+\n"
1077
 
            "FAIL: \\S+\.test_truth\n"
1078
 
            "-+\n"
1079
 
            "(?:.*\n)*"
1080
 
            "No absolute truth\n"
1081
 
            "(?:.*\n)*"
1082
 
            "-+\n"
1083
 
            "Ran 1 test in .*\n"
1084
 
            "\n"
1085
 
            "FAILED \\(failures=1\\)\n\\Z")
 
1076
        if testtools_version <= (0, 9, 11):
 
1077
            self.assertContainsRe(runner.stream.getvalue(),
 
1078
                "=+\n"
 
1079
                "FAIL: \\S+\.test_truth\n"
 
1080
                "-+\n"
 
1081
                "(?:.*\n)*"
 
1082
                "No absolute truth\n"
 
1083
                "(?:.*\n)*"
 
1084
                "-+\n"
 
1085
                "Ran 1 test in .*\n"
 
1086
                "\n"
 
1087
                "FAILED \\(failures=1\\)\n\\Z")
 
1088
        else:
 
1089
            self.assertContainsRe(runner.stream.getvalue(),
 
1090
                "=+\n"
 
1091
                "FAIL: \\S+\.test_truth\n"
 
1092
                "-+\n"
 
1093
                "Empty attachments:\n"
 
1094
                "  log\n"
 
1095
                "\n"
 
1096
                "reason: {{{No absolute truth}}}\n"
 
1097
                "-+\n"
 
1098
                "Ran 1 test in .*\n"
 
1099
                "\n"
 
1100
                "FAILED \\(failures=1\\)\n\\Z")
1086
1101
 
1087
1102
    def test_result_decorator(self):
1088
1103
        # decorate results
1247
1262
            lambda trace=False: "ascii")
1248
1263
        result = self.run_test_runner(tests.TextTestRunner(stream=out),
1249
1264
            FailureWithUnicode("test_log_unicode"))
1250
 
        self.assertContainsRe(out.getvalue(),
1251
 
            "Text attachment: log\n"
1252
 
            "-+\n"
1253
 
            "\d+\.\d+  \\\\u2606\n"
1254
 
            "-+\n")
 
1265
        if testtools_version > (0, 9, 11):
 
1266
            self.assertContainsRe(out.getvalue(), "log: {{{\d+\.\d+  \\\\u2606}}}")
 
1267
        else:
 
1268
            self.assertContainsRe(out.getvalue(),
 
1269
                "Text attachment: log\n"
 
1270
                "-+\n"
 
1271
                "\d+\.\d+  \\\\u2606\n"
 
1272
                "-+\n")
1255
1273
 
1256
1274
 
1257
1275
class SampleTestCase(tests.TestCase):
1736
1754
        result = self._run_test('test_fail')
1737
1755
        self.assertEqual(1, len(result.failures))
1738
1756
        result_content = result.failures[0][1]
1739
 
        self.assertContainsRe(result_content, 'Text attachment: log')
 
1757
        if testtools_version < (0, 9, 12):
 
1758
            self.assertContainsRe(result_content, 'Text attachment: log')
1740
1759
        self.assertContainsRe(result_content, 'this was a failing test')
1741
1760
 
1742
1761
    def test_error_has_log(self):
1743
1762
        result = self._run_test('test_error')
1744
1763
        self.assertEqual(1, len(result.errors))
1745
1764
        result_content = result.errors[0][1]
1746
 
        self.assertContainsRe(result_content, 'Text attachment: log')
 
1765
        if testtools_version < (0, 9, 12):
 
1766
            self.assertContainsRe(result_content, 'Text attachment: log')
1747
1767
        self.assertContainsRe(result_content, 'this test errored')
1748
1768
 
1749
1769
    def test_skip_has_no_log(self):