~landscape/zope3/ztk-1.1.3

« back to all changes in this revision

Viewing changes to src/zope/testing/testrunner/tb_format.py

  • Committer: Thomas Hervé
  • Date: 2009-09-21 06:45:37 UTC
  • mfrom: (7.1.2 newer-zope-testing)
  • Revision ID: thomas@canonical.com-20090921064537-zcfyuv32hxj9eah0
Merge newer-zope-testing [a=sidnei] [f=429702] [r=therve,free.ekayanaka]

Update zope.testing to 3.8.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
##############################################################################
 
2
#
 
3
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
 
4
# All Rights Reserved.
 
5
#
 
6
# This software is subject to the provisions of the Zope Public License,
 
7
# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
 
8
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
 
9
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 
10
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
 
11
# FOR A PARTICULAR PURPOSE.
 
12
#
 
13
##############################################################################
 
14
"""Set up testing environment
 
15
 
 
16
$Id: __init__.py 68482 2006-06-04 14:58:55Z jim $
 
17
"""
 
18
 
 
19
import StringIO
 
20
import os
 
21
import sys
 
22
import traceback
 
23
import zope.exceptions.exceptionformatter
 
24
import zope.testing.testrunner.feature
 
25
 
 
26
 
 
27
def format_exception(t, v, tb, limit=None):
 
28
    fmt = zope.exceptions.exceptionformatter.TextExceptionFormatter(
 
29
        limit=None, with_filenames=True)
 
30
    return fmt.formatException(t, v, tb)
 
31
 
 
32
 
 
33
def print_exception(t, v, tb, limit=None, file=None):
 
34
    if file is None:
 
35
        file = sys.stdout
 
36
    file.writelines(format_exception(t, v, tb, limit))
 
37
 
 
38
 
 
39
class Traceback(zope.testing.testrunner.feature.Feature):
 
40
 
 
41
    active = True
 
42
 
 
43
    def global_setup(self):
 
44
        self.old_format = traceback.format_exception
 
45
        traceback.format_exception = format_exception
 
46
 
 
47
        self.old_print = traceback.print_exception
 
48
        traceback.print_exception = print_exception
 
49
 
 
50
    def global_teardown(self):
 
51
        traceback.format_exception = self.old_format
 
52
        traceback.print_exception = self.old_print