mirror of
				https://github.com/python/cpython.git
				synced 2025-11-04 07:31:38 +00:00 
			
		
		
		
	svn+ssh://pythondev@svn.python.org/python/branches/py3k
................
  r77163 | benjamin.peterson | 2009-12-30 13:52:54 -0600 (Wed, 30 Dec 2009) | 16 lines
  Merged revisions 77160 via svnmerge from
  svn+ssh://pythondev@svn.python.org/python/trunk
  ................
    r77160 | benjamin.peterson | 2009-12-30 13:44:23 -0600 (Wed, 30 Dec 2009) | 9 lines
    Merged revisions 77158 via svnmerge from
    svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3
    ........
      r77158 | benjamin.peterson | 2009-12-30 13:41:03 -0600 (Wed, 30 Dec 2009) | 1 line
      clean up logging's global state after the test finishes
    ........
  ................
................
		
	
			
		
			
				
	
	
		
			41 lines
		
	
	
	
		
			1.3 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			41 lines
		
	
	
	
		
			1.3 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
# -*- coding: utf-8 -*-
 | 
						|
import sys
 | 
						|
import codecs
 | 
						|
import logging
 | 
						|
import io
 | 
						|
import unittest
 | 
						|
 | 
						|
from lib2to3 import main
 | 
						|
 | 
						|
 | 
						|
class TestMain(unittest.TestCase):
 | 
						|
 | 
						|
    def tearDown(self):
 | 
						|
        # Clean up logging configuration down by main.
 | 
						|
        del logging.root.handlers[:]
 | 
						|
 | 
						|
    def run_2to3_capture(self, args, in_capture, out_capture, err_capture):
 | 
						|
        save_stdin = sys.stdin
 | 
						|
        save_stdout = sys.stdout
 | 
						|
        save_stderr = sys.stderr
 | 
						|
        sys.stdin = in_capture
 | 
						|
        sys.stdout = out_capture
 | 
						|
        sys.stderr = err_capture
 | 
						|
        try:
 | 
						|
            return main.main("lib2to3.fixes", args)
 | 
						|
        finally:
 | 
						|
            sys.stdin = save_stdin
 | 
						|
            sys.stdout = save_stdout
 | 
						|
            sys.stderr = save_stderr
 | 
						|
 | 
						|
    def test_unencodable_diff(self):
 | 
						|
        input_stream = io.StringIO("print 'nothing'\nprint u'über'\n")
 | 
						|
        out = io.BytesIO()
 | 
						|
        out_enc = codecs.getwriter("ascii")(out)
 | 
						|
        err = io.StringIO()
 | 
						|
        ret = self.run_2to3_capture(["-"], input_stream, out_enc, err)
 | 
						|
        self.assertEqual(ret, 0)
 | 
						|
        output = out.getvalue().decode("ascii")
 | 
						|
        self.assertTrue("-print 'nothing'" in output)
 | 
						|
        self.assertTrue("WARNING: couldn't encode <stdin>'s diff for "
 | 
						|
                        "your terminal" in err.getvalue())
 |