mirror of
https://github.com/python/cpython.git
synced 2025-08-01 07:33:08 +00:00
New environment variable PYTHONIOENCODING.
This commit is contained in:
parent
7f7ca35f5b
commit
99815892f6
10 changed files with 152 additions and 51 deletions
|
@ -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)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue