~ubuntu-branches/ubuntu/natty/python3.1/natty-security

« back to all changes in this revision

Viewing changes to Lib/distutils/tests/test_log.py

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2010-07-06 16:52:42 UTC
  • mfrom: (1.2.1 upstream) (2.1.11 sid)
  • Revision ID: james.westby@ubuntu.com-20100706165242-2xv4i019r3et6c0j
Tags: 3.1.2+20100706-1ubuntu1
* Merge with Debian; remaining changes:
  - Regenerate the control file.
  - Add debian/patches/overwrite-semaphore-check for Lucid buildds.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
"""Tests for distutils.log"""
 
2
 
 
3
import sys
 
4
import unittest
 
5
from tempfile import NamedTemporaryFile
 
6
 
 
7
from distutils import log
 
8
 
 
9
class TestLog(unittest.TestCase):
 
10
    def test_non_ascii(self):
 
11
        # Issue #8663: test that non-ASCII text is escaped with
 
12
        # backslashreplace error handler (stream use ASCII encoding and strict
 
13
        # error handler)
 
14
        old_stdout = sys.stdout
 
15
        old_stderr = sys.stderr
 
16
        try:
 
17
            log.set_threshold(log.DEBUG)
 
18
            with NamedTemporaryFile(mode="w+", encoding='ascii') as stdout, \
 
19
                 NamedTemporaryFile(mode="w+", encoding='ascii') as stderr:
 
20
                sys.stdout = stdout
 
21
                sys.stderr = stderr
 
22
                log.debug("debug:\xe9")
 
23
                log.fatal("fatal:\xe9")
 
24
                stdout.seek(0)
 
25
                self.assertEquals(stdout.read().rstrip(), "debug:\\xe9")
 
26
                stderr.seek(0)
 
27
                self.assertEquals(stderr.read().rstrip(), "fatal:\\xe9")
 
28
        finally:
 
29
            sys.stdout = old_stdout
 
30
            sys.stderr = old_stderr
 
31
 
 
32
def test_suite():
 
33
    return unittest.makeSuite(TestLog)
 
34
 
 
35
if __name__ == "__main__":
 
36
    unittest.main(defaultTest="test_suite")