classification
Title: test_unicode_file fails with non-ascii path
Type: behavior Stage: resolved
Components: Tests Versions: Python 2.7
process
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 2010-01-12 18:31 by ezio.melotti. 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/regrtest.py test_unicode_file
test_unicode_file
test test_unicode_file failed -- Traceback (most recent call last):
  File "/tmp/py2u…→unicode/Lib/test/test_unicode_file.py", line 173, in test_single_files
    self._test_single(TESTFN_UNICODE)
  File "/tmp/py2u…→unicode/Lib/test/test_unicode_file.py", line 147, in _test_single
    self._do_single(filename)
  File "/tmp/py2u…→unicode/Lib/test/test_unicode_file.py", line 48, in _do_single
    self.assertTrue(os.path.exists(os.path.abspath(filename)))
  File "/tmp/py2u…→unicode/Lib/posixpath.py", line 338, in abspath
    path = join(os.getcwd(), path)
  File "/tmp/py2u…→unicode/Lib/posixpath.py", 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:
    test_unicode_file
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.
History
Date User Action Args
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