This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: test_unicode_file fails with non-ascii path
Type: behavior Stage: resolved
Components: Tests Versions: Python 2.7
Status: closed Resolution: duplicate
Dependencies: Superseder:
Assigned To: Nosy List: ezio.melotti, flox
Priority: normal Keywords:

Created on 2010-01-10 18:18 by flox, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (3)
msg97537 - (view) Author: Florent Xicluna (flox) * (Python committer) Date: 2010-01-10 18:18
/tmp/py2u…→unicode $ ./python Lib/test/ test_unicode_file
test test_unicode_file failed -- Traceback (most recent call last):
  File "/tmp/py2u…→unicode/Lib/test/", line 173, in test_single_files
  File "/tmp/py2u…→unicode/Lib/test/", line 147, in _test_single
  File "/tmp/py2u…→unicode/Lib/test/", line 48, in _do_single
  File "/tmp/py2u…→unicode/Lib/", line 338, in abspath
    path = join(os.getcwd(), path)
  File "/tmp/py2u…→unicode/Lib/", line 70, in join
    path += '/' + b
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 29: ordinal not in range(128)

1 test failed:
msg97642 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2010-01-12 18:16
This is because in "path = join(os.getcwd(), path)" os.getcwd() returns a non-ascii byte string and path is unicode, so the cwd is implicitly decoded with the ascii codec in join and the error is raised.
Using getcwdu() when the path is unicode seems to fix the problem:

 def abspath(path):
     """Return an absolute path."""
     if not isabs(path):
-        path = join(os.getcwd(), path)
+        if isinstance(path, unicode):
+            path = join(os.getcwdu(), path)
+        else:
+            path = join(os.getcwd(), path)
     return normpath(path)
msg97646 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2010-01-12 18:31
See #3426.
Date User Action Args
2022-04-11 14:56:56adminsetgithub: 51918
2010-01-12 18:31:58ezio.melottisetstatus: open -> closed
priority: normal
messages: + msg97646

resolution: duplicate
stage: resolved
2010-01-12 18:30:57ezio.melottilinkissue3426 superseder
2010-01-12 18:16:08ezio.melottisetnosy: + ezio.melotti
messages: + msg97642
2010-01-10 18:18:26floxcreate