~testtools-dev/testtools/0.9

« back to all changes in this revision

Viewing changes to testtools/tests/test_testresult.py

  • Committer: Robert Collins
  • Date: 2009-12-01 10:38:07 UTC
  • mfrom: (33.7.19 py3-support)
  • Revision ID: robertc@robertcollins.net-20091201103807-w4hd1u5ztvu25oyl
Merge Benjamin Peterson's Python 3 support patch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
__metaclass__ = type
6
6
 
7
7
import datetime
8
 
from cStringIO import StringIO
 
8
try:
 
9
    from cStringIO import StringIO
 
10
except ImportError:
 
11
    from io import StringIO
9
12
import doctest
10
13
import sys
11
14
import threading
21
24
    )
22
25
from testtools.content import Content, ContentType
23
26
from testtools.matchers import DocTestMatches
 
27
from testtools.utils import _u, _b
24
28
from testtools.tests.helpers import (
25
29
    LoggingResult,
26
30
    Python26TestResult,
27
31
    Python27TestResult,
28
32
    ExtendedTestResult,
 
33
    an_exc_info
29
34
    )
30
35
 
31
36
 
35
40
    def test_addExpectedFailure(self):
36
41
        # Calling addExpectedFailure(test, exc_info) completes ok.
37
42
        result = self.makeResult()
38
 
        result.addExpectedFailure(self, sys.exc_info())
 
43
        result.addExpectedFailure(self, an_exc_info)
39
44
 
40
45
    def test_addExpectedFailure_details(self):
41
46
        # Calling addExpectedFailure(test, details=xxx) completes ok.
55
60
    def test_addSkipped(self):
56
61
        # Calling addSkip(test, reason) completes ok.
57
62
        result = self.makeResult()
58
 
        result.addSkip(self, u"Skipped for some reason")
 
63
        result.addSkip(self, _u("Skipped for some reason"))
59
64
 
60
65
    def test_addSkipped_details(self):
61
66
        # Calling addSkip(test, reason) completes ok.
121
126
        # Calling addSkip on a TestResult records the test that was skipped in
122
127
        # its skip_reasons dict.
123
128
        result = self.makeResult()
124
 
        result.addSkip(self, u"Skipped for some reason")
125
 
        self.assertEqual({u"Skipped for some reason":[self]},
126
 
            result.skip_reasons)
127
 
        result.addSkip(self, u"Skipped for some reason")
128
 
        self.assertEqual({u"Skipped for some reason":[self, self]},
129
 
            result.skip_reasons)
130
 
        result.addSkip(self, u"Skipped for another reason")
131
 
        self.assertEqual({u"Skipped for some reason":[self, self],
132
 
            u"Skipped for another reason":[self]},
 
129
        result.addSkip(self, _u("Skipped for some reason"))
 
130
        self.assertEqual({_u("Skipped for some reason"):[self]},
 
131
            result.skip_reasons)
 
132
        result.addSkip(self, _u("Skipped for some reason"))
 
133
        self.assertEqual({_u("Skipped for some reason"):[self, self]},
 
134
            result.skip_reasons)
 
135
        result.addSkip(self, _u("Skipped for another reason"))
 
136
        self.assertEqual({_u("Skipped for some reason"):[self, self],
 
137
            _u("Skipped for another reason"):[self]},
133
138
            result.skip_reasons)
134
139
 
135
140
    def test_now_datetime_now(self):
202
207
    def test_addSkipped(self):
203
208
        # Calling `addSkip` on a `MultiTestResult` calls addSkip on its
204
209
        # results.
205
 
        reason = u"Skipped for some reason"
 
210
        reason = _u("Skipped for some reason")
206
211
        self.multiResult.addSkip(self, reason)
207
212
        self.assertResultLogsEqual([('addSkip', self, reason)])
208
213
 
278
283
        self.assertEqual("fp", result.stream)
279
284
 
280
285
    def reset_output(self):
281
 
        self.result.stream.reset()
282
 
        self.result.stream.truncate()
 
286
        self.result.stream = StringIO()
283
287
 
284
288
    def test_startTestRun(self):
285
289
        self.result.startTestRun()
292
296
        self.result.stopTest(test)
293
297
        self.result.startTest(test)
294
298
        self.result.stopTest(test)
295
 
        self.result.stream.reset()
296
 
        self.result.stream.truncate()
 
299
        self.result.stream = StringIO()
297
300
        self.result.stopTestRun()
298
301
        self.assertThat(self.getvalue(),
299
302
            DocTestMatches("Ran 2 tests in ...s\n...", doctest.ELLIPSIS))
368
371
    testMethod()
369
372
  File "...testtools/tests/test_testresult.py", line ..., in error
370
373
    1/0
371
 
ZeroDivisionError: integer division or modulo by zero
 
374
ZeroDivisionError: int... division or modulo by zero
372
375
------------
373
376
======================================================================
374
377
FAIL: testtools.tests.test_testresult.Test.failed
422
425
        self.result1.addError(self, exc_info1)
423
426
        exc_info2 = self.makeExceptionInfo(AssertionError, 'failure')
424
427
        self.result1.addFailure(self, exc_info2)
425
 
        reason = u"Skipped for some reason"
 
428
        reason = _u("Skipped for some reason")
426
429
        self.result1.addSkip(self, reason)
427
430
        self.result1.addSuccess(self)
428
431
        self.assertEqual([('startTest', self),
467
470
 
468
471
    def get_details_and_string(self):
469
472
        """Get a details dict and expected string."""
470
 
        text1 = lambda:["1\n2\n"]
471
 
        text2 = lambda:["3\n4\n"]
472
 
        bin1 = lambda:["5\n"]
 
473
        text1 = lambda:[_b("1\n2\n")]
 
474
        text2 = lambda:[_b("3\n4\n")]
 
475
        bin1 = lambda:[_b("5\n")]
473
476
        details = {'text 1': Content(ContentType('text', 'plain'), text1),
474
477
            'text 2': Content(ContentType('text', 'strange'), text2),
475
478
            'bin 1': Content(ContentType('application', 'binary'), bin1)}