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.

classification
Title: FAIL: test_expanduser when $HOME ends with /
Type: behavior Stage: resolved
Components: Tests Versions: Python 3.3, Python 3.4
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: ezio.melotti Nosy List: ezio.melotti, koobs, pitrou, python-dev
Priority: normal Keywords: patch

Created on 2013-04-21 05:37 by koobs, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
expanduser.log koobs, 2013-04-21 05:37
test_posixpath.patch koobs, 2013-05-05 04:33
test_posixpath_v2.diff koobs, 2013-05-08 08:39 review
Messages (8)
msg187494 - (view) Author: Kubilay Kocak (koobs) (Python triager) Date: 2013-04-21 05:37
test_expanduser in test.test_posixpath.PosixPathTest fails when the users $HOME ends with "/"

======================================================================
FAIL: test_expanduser (test.test_posixpath.PosixPathTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/home/buildbot/python/3.x.koobs-freebsd/build/Lib/test/test_posixpath.py", line 264, in test_expanduser
    self.assertEqual(posixpath.expanduser("~"), home)
AssertionError: '/usr/home/buildbot' != '/usr/home/buildbot/'
- /usr/home/buildbot
+ /usr/home/buildbot/
?                   +
----------------------------------------------------------------------

Test failures can be seen in the following FreeBSD 9-STABLE buildbots on all branches except 2.7:

3.x - http://buildbot.python.org/all/builders/AMD64%20FreeBSD%209.0%20dtrace%203.x/builds/1256/steps/test/logs/stdio
3.3 - http://buildbot.python.org/all/builders/AMD64%20FreeBSD%209.0%20dtrace%203.3/builds/546/steps/test/logs/stdio
3.2 - http://buildbot.python.org/all/builders/AMD64%20FreeBSD%209.0%20dtrace%203.2/builds/490/steps/test/logs/stdio

It is also reproducible outside of the buildbot environment using fresh Python 3.3.1 sources with default build configuration (see attached expanduser.log)

Commenting out Lib/test/test_posixpath.py#l264 results in the test passing
msg187913 - (view) Author: Kubilay Kocak (koobs) (Python triager) Date: 2013-04-27 15:45
After some sleuthing with Ezio (thank you for the help) and some amateur debugging, all conditions in expanduser return the the home directory after stripping trailing slashes.

The assertion in Lib/test/test_posixpath.py:264 compares expanduser(path) with a path obtained directly from pwd.getpwuidpw_dir "without" submitting it to the same treatment,  and thus the test fails when $HOME ends in a "/".

The assertion was added in f11da6cecffd (2011-03-17) in order to show that expanduser() "does" infact derive a path from pw_dir, when $HOME is undefined, as the test indicates by deleting the environment variable

In so far as using exact path equivalence to make that assertion, the 'home' variable in the test either ought to be subjected to the same treatment as paths derived via expanduser(), or the assertion relaxed to use assertIsNotNone.

Given the comment in the test: "# expanduser should fall back to using the password database", my feeling is that the failure case is that no path is returned if a username is not provided in the path passed to expanduser, and as such assertIsNotNone is the more specific assertion, but I'll leave it in the hands of the experts to make the call.
msg188426 - (view) Author: Kubilay Kocak (koobs) (Python triager) Date: 2013-05-05 04:33
The attached patch strips the trailing slash from the home directory obtained from pw_dir in test_expanduser

./python -m test -j3 test_posixpath
[1/1] test_posixpath
1 test OK.

Can someone take care of the commit please, and thank you again Ezio for the assistance
msg188430 - (view) Author: Kubilay Kocak (koobs) (Python triager) Date: 2013-05-05 06:37
Thanks Antoine, I'm removing the 'Library' component on this one given the proposed resolution.

Additionally, given the trivial nature and isolation of the change strictly to the test, I'd like to request this go into 3.2 as well. 

For any future security fixes to 3.2 until its EoL, having our buildbots 'green' is imperative and a prerequisite for identifying regressions
msg188711 - (view) Author: Kubilay Kocak (koobs) (Python triager) Date: 2013-05-08 08:39
Spoil Ezio and learn me some python dev guide conventions, with an updated patch generated via hg diff, containing a comment, and including a bug #ID reference
msg188716 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2013-05-08 11:31
Looks good to me.
msg188768 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2013-05-09 12:25
New changeset dee0a2dea11e by Ezio Melotti in branch '3.3':
#17809: fix a test failure in test_expanduser when $HOME has a trailing /.  Patch by Kubilay Kocak.
http://hg.python.org/cpython/rev/dee0a2dea11e

New changeset 489f075430de by Ezio Melotti in branch 'default':
#17809: merge with 3.3.
http://hg.python.org/cpython/rev/489f075430de
msg188771 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2013-05-09 12:27
Fixed, thanks for the patch!
History
Date User Action Args
2022-04-11 14:57:44adminsetgithub: 62009
2013-05-09 12:27:37ezio.melottisetstatus: open -> closed
resolution: fixed
messages: + msg188771

stage: commit review -> resolved
2013-05-09 12:25:24python-devsetnosy: + python-dev
messages: + msg188768
2013-05-08 11:31:59pitrousetnosy: + pitrou

messages: + msg188716
stage: patch review -> commit review
2013-05-08 08:39:11koobssetfiles: + test_posixpath_v2.diff

messages: + msg188711
2013-05-05 06:37:11koobssetmessages: + msg188430
components: - Library (Lib)
2013-05-05 06:24:39pitrousetassignee: ezio.melotti
stage: patch review
2013-05-05 04:33:58koobssetfiles: + test_posixpath.patch
keywords: + patch
messages: + msg188426
2013-04-27 15:57:23ezio.melottisetnosy: + ezio.melotti

type: behavior
versions: - Python 3.2, Python 3.5
2013-04-27 15:45:11koobssetmessages: + msg187913
2013-04-21 05:37:29koobscreate