~certify-web-dev/twisted/certify-trunk

« back to all changes in this revision

Viewing changes to twisted/test/test_log.py

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2006-01-16 19:56:10 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20060116195610-ykmxbia4mnnod9o2
Tags: 2.1.0-0ubuntu2
debian/copyright: Include copyright for python 2.3; some 2.3 files
are included in the upstream tarball, but not in the binary packages.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# -*- test-case-name: "twisted.test.test_log" -*-
2
1
# Copyright (c) 2001-2004 Twisted Matrix Laboratories.
3
2
# See LICENSE for details.
4
3
 
5
4
#
6
5
 
 
6
import sys
 
7
 
7
8
from twisted.trial import unittest
8
9
 
9
10
from twisted.python import log
73
74
        self.assertEquals(len(L2), 3)
74
75
        self.assertEquals(L1[2]['message'], ("Howdy, y'all.",))
75
76
        self.assertEquals(L2[2]['message'], ("Howdy, y'all.",))
 
77
 
 
78
 
 
79
class FakeFile(list):
 
80
    def write(self, bytes):
 
81
        self.append(bytes)
 
82
 
 
83
    def flush(self):
 
84
        pass
 
85
 
 
86
 
 
87
class LogPublisherTestCase(unittest.TestCase):
 
88
    def setUpClass(self):
 
89
        # Fuck you Python.
 
90
        reload(sys)
 
91
        self._origEncoding = sys.getdefaultencoding()
 
92
        sys.setdefaultencoding('ascii')
 
93
 
 
94
    def tearDownClass(self):
 
95
        sys.setdefaultencoding(self._origEncoding)
 
96
        # Fuck you very much.
 
97
        del sys.setdefaultencoding
 
98
 
 
99
    def setUp(self):
 
100
        self.out = FakeFile()
 
101
        self.lp = log.LogPublisher()
 
102
        self.flo = log.FileLogObserver(self.out)
 
103
        self.lp.addObserver(self.flo.emit)
 
104
 
 
105
    def tearDown(self):
 
106
        for chunk in self.out:
 
107
            self.failUnless(isinstance(chunk, str), "%r was not a string" % (chunk,))
 
108
 
 
109
    def testSingleString(self):
 
110
        self.lp.msg("Hello, world.")
 
111
        self.assertEquals(len(self.out), 1)
 
112
 
 
113
    def testMultipleString(self):
 
114
        # Test some stupid behavior that will be deprecated real soon.
 
115
        # If you are reading this and trying to learn how the logging
 
116
        # system works, *do not use this feature*.
 
117
        self.lp.msg("Hello, ", "world.")
 
118
        self.assertEquals(len(self.out), 1)
 
119
 
 
120
    def testSingleUnicode(self):
 
121
        self.assertRaises(
 
122
            UnicodeError,
 
123
            self.lp.msg, u"Hello, \N{VULGAR FRACTION ONE HALF} world.")
 
124
        self.assertEquals(len(self.out), 0)