New environment variable PYTHONIOENCODING.

This commit is contained in:
Martin v. Löwis 2008-06-01 07:20:46 +00:00
parent 7f7ca35f5b
commit 99815892f6
10 changed files with 152 additions and 51 deletions

View file

@ -385,6 +385,26 @@ class SysModuleTest(unittest.TestCase):
## self.assert_(r[0][2] > 100, r[0][2])
## self.assert_(r[1][2] > 100, r[1][2])
def test_ioencoding(self):
import subprocess,os
env = dict(os.environ)
# Test character: cent sign, encoded as 0x4A (ASCII J) in CP424,
# not representable in ASCII.
env["PYTHONIOENCODING"] = "cp424"
p = subprocess.Popen([sys.executable, "-c", 'print unichr(0xa2)'],
stdout = subprocess.PIPE, env=env)
out = p.stdout.read().strip()
self.assertEqual(out, unichr(0xa2).encode("cp424"))
env["PYTHONIOENCODING"] = "ascii:replace"
p = subprocess.Popen([sys.executable, "-c", 'print unichr(0xa2)'],
stdout = subprocess.PIPE, env=env)
out = p.stdout.read().strip()
self.assertEqual(out, '?')
def test_main():
test.test_support.run_unittest(SysModuleTest)