diff options
Diffstat (limited to 'Lib/lib2to3/tests/test_main.py')
-rw-r--r-- | Lib/lib2to3/tests/test_main.py | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/Lib/lib2to3/tests/test_main.py b/Lib/lib2to3/tests/test_main.py new file mode 100644 index 0000000..23d1b56 --- /dev/null +++ b/Lib/lib2to3/tests/test_main.py @@ -0,0 +1,36 @@ +# -*- coding: utf-8 -*- +import sys +import codecs +import io +import unittest + +from lib2to3 import main + + +class TestMain(unittest.TestCase): + + 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.StringIO() + 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() + self.assertTrue("-print 'nothing'" in output) + self.assertTrue("WARNING: couldn't encode <stdin>'s diff for " + "your terminal" in err.getvalue()) |