1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
# Copyright 2009 Canonical Ltd. This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).
"""Runn test_logger.txt."""
__metaclass__ = type
__all__ = []
import doctest
from sys import exc_info
import unittest
from testtools.matchers import DocTestMatches
from lp.testing.layers import BaseLayer
from lp.services.scripts.logger import LaunchpadFormatter
from lp.services.utils import traceback_info
from lp.testing import TestCase
from lp.testing.systemdocs import LayeredDocFileSuite
DOCTEST_FLAGS = (
doctest.ELLIPSIS |
doctest.NORMALIZE_WHITESPACE |
doctest.REPORT_NDIFF)
class TestLaunchpadFormatter(TestCase):
"""Tests of `LaunchpadFormatter`."""
def test_traceback_info(self):
# LaunchpadFormatter inherits from zope.exceptions.log.Formatter, so
# __traceback_info__ annotations are included in formatted exceptions.
traceback_info("Captain Kirk")
try:
0/0
except ZeroDivisionError:
info = exc_info()
self.assertThat(
LaunchpadFormatter().formatException(info),
DocTestMatches(
flags=DOCTEST_FLAGS, example="""
Traceback (most recent call last):
...
__traceback_info__: Captain Kirk
ZeroDivisionError: ...
"""))
def test_suite():
suite = unittest.TestSuite()
suite.addTest(
LayeredDocFileSuite(
'test_logger.txt', layer=BaseLayer))
suite.addTest(
unittest.TestLoader().loadTestsFromName(__name__))
return suite
|