[Python-Dev] test_unicode_file.py
Martin v. Loewis
martin@v.loewis.de
Tue, 15 Jan 2002 22:13:16 +0100
> In the most recent CVS checkout on the trunk, test_unicode_file has
> started to fail. Traceback:
>
> Traceback (most recent call last):
> File "../Lib/test/test_unicode_file.py", line 61, in ?
> if base not in os.listdir(path):
> UnicodeError: ASCII decoding error: ordinal not in range(128)
Until PEP 277 is approved, the tests that Mark recently added is
bogus: The return value of os.listdir is (currently) a list of byte
strings, and you cannot (portably) compare those to a Unicode string
if the byte strings contain non-ASCII characters.
I'm surprised the test passed for Mark; he either has Neil's patches
installed, or has set the default encoding to "mbcs" on his system.
I recommend to apply the attached patch.
Regards,
Martin
Index: test_unicode_file.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_unicode_file.py,v
retrieving revision 1.3
diff -u -r1.3 test_unicode_file.py
--- test_unicode_file.py 2002/01/07 02:11:43 1.3
+++ test_unicode_file.py 2002/01/15 21:06:24
@@ -55,11 +55,12 @@
print "File doesn't exist after creating it"
path, base = os.path.split(os.path.abspath(TESTFN_ENCODED))
-if base not in os.listdir(path):
- print "Filename did not appear in os.listdir()"
-path, base = os.path.split(os.path.abspath(TESTFN_UNICODE))
-if base not in os.listdir(path):
- print "Unicode filename did not appear in os.listdir()"
+# Until PEP 277 is adopted, this test is not portable
+# if base not in os.listdir(path):
+# print "Filename did not appear in os.listdir()"
+# path, base = os.path.split(os.path.abspath(TESTFN_UNICODE))
+# if base not in os.listdir(path):
+# print "Unicode filename did not appear in os.listdir()"
if os.path.abspath(TESTFN_ENCODED) != os.path.abspath(glob.glob(TESTFN_ENCODED)[0]):
print "Filename did not appear in glob.glob()"