[Jython-checkins] jython: Correct use of encoding in test_os_jy test of getcwd. Fixes #2646.
jeff.allen
jython-checkins at python.org
Sun Nov 26 13:10:07 EST 2017
https://hg.python.org/jython/rev/320911f1aeba
changeset: 8145:320911f1aeba
user: Jeff Allen <ja.py at farowl.co.uk>
date: Sun Nov 26 17:19:57 2017 +0000
summary:
Correct use of encoding in test_os_jy test of getcwd. Fixes #2646.
All information is in the FS encoding, so decode() was spurious, and
only passed because of a false conception of == between str and unicode,
corrected in #2630. We re-enable the test for Windows, as it keeps
catching us out, add a similar test for getcwdu, and beef up comments.
files:
Lib/test/regrtest.py | 2 +-
Lib/test/test_os_jy.py | 26 ++++++++++++++++++++------
2 files changed, 21 insertions(+), 7 deletions(-)
diff --git a/Lib/test/regrtest.py b/Lib/test/regrtest.py
--- a/Lib/test/regrtest.py
+++ b/Lib/test/regrtest.py
@@ -1370,7 +1370,7 @@
'java.nt': # Expected to fail on Windows
"""
test_mailbox # fails miserably and ruins other tests
- test_os_jy # Locale tests fail on Cygwin (but not Windows)
+ # test_os_jy # Locale tests fail on Cygwin (but not Windows)
# test_popen # Passes, but see http://bugs.python.org/issue1559298
test_select_new # Hangs (Windows), though ok run singly
test_urllib2 # file not on local host (likely Windows only)
diff --git a/Lib/test/test_os_jy.py b/Lib/test/test_os_jy.py
--- a/Lib/test/test_os_jy.py
+++ b/Lib/test/test_os_jy.py
@@ -231,16 +231,30 @@
'sys.stdout.write(os.getenv("TEST_HOME"))'],
stdout=subprocess.PIPE,
env=newenv)
- # Decode with default encoding utf-8 (because ... ?)
+ # Decode with FS encoding used by subprocess communication
self.assertEqual(p.stdout.read().decode('utf-8'), expected)
def test_getcwd(self):
with test_support.temp_cwd(name=u"tempcwd-中文") as temp_cwd:
- p = subprocess.Popen([sys.executable, "-c",
- 'import sys,os;' \
- 'sys.stdout.write(os.getcwd().encode("utf-8"))'],
- stdout=subprocess.PIPE)
- self.assertEqual(p.stdout.read().decode("utf-8"), temp_cwd)
+ # os.getcwd reports the working directory as an FS-encoded str,
+ # which is also the encoding used in subprocess communication.
+ p = subprocess.Popen([
+ sys.executable, "-c",
+ 'import sys,os;' \
+ 'sys.stdout.write(os.getcwd())'],
+ stdout=subprocess.PIPE)
+ self.assertEqual(p.stdout.read(), temp_cwd)
+
+ def test_getcwdu(self):
+ with test_support.temp_cwd(name=u"tempcwd-中文") as temp_cwd:
+ # os.getcwdu reports the working directory as unicode,
+ # which must be encoded for subprocess communication.
+ p = subprocess.Popen([
+ sys.executable, "-c",
+ 'import sys,os;' \
+ 'sys.stdout.write(os.getcwdu().encode(sys.getfilesystemencoding()))'],
+ stdout=subprocess.PIPE)
+ self.assertEqual(p.stdout.read(), temp_cwd)
def test_listdir(self):
# It is hard to avoid Unicode paths on systems like OS X. Use relative
--
Repository URL: https://hg.python.org/jython
More information about the Jython-checkins
mailing list