Message9431
Writing the new proposed test properly would have been better - don't mix up encode/decode ;)
def test_env_bytes(self):
with test_support.temp_cwd(name=u"tempcwd-中文"):
newenv = os.environ.copy()
newenv["TEST_HOME"] = u"首页".encode("utf-8")
p = subprocess.Popen([sys.executable, "-c",
'import sys,os;' \
'sys.stdout.write(os.getenv("TEST_HOME"))'],
stdout=subprocess.PIPE,
env=newenv)
self.assertEqual(p.stdout.read().decode("utf-8"), u"首页")
======================================================================
FAIL: test_env_bytes (__main__.OSUnicodeTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
File "dist/Lib/test/test_os_jy.py", line 153, in test_env_bytes
self.assertEqual(p.stdout.read().decode("utf-8"), u"首页")
AssertionError: u'\xe9\xa6\x96\xe9\xa1\xb5' != u'\u9996\u9875'
- \xe9\xa6\x96\xe9\xa1\xb5
+ \u9996\u9875
So one can pass through bytes in this fashion, but an additional level of UTF-8 encoding was added; to "fix" the assertion requires
self.assertEqual(p.stdout.read().decode("utf-8").decode("utf-8"), u"首页")
which is obviously not desirable. |
|
Date |
User |
Action |
Args |
2015-01-20 23:40:58 | zyasoft | set | messageid: <1421797258.17.0.340562625442.issue1841@psf.upfronthosting.co.za> |
2015-01-20 23:40:58 | zyasoft | set | recipients:
+ zyasoft, fwierzbicki, amak, pekka.klarck |
2015-01-20 23:40:58 | zyasoft | link | issue1841 messages |
2015-01-20 23:40:57 | zyasoft | create | |
|