From 06d9815b83bebbfebc7441892c8a77965c5689d9 Mon Sep 17 00:00:00 2001 From: pxin Date: Fri, 27 Nov 2020 18:07:27 +0800 Subject: [PATCH 1/4] * posixpath.expanduser() returns the input path unchanged if user home directory is None. * Skip test_expanduser and test_expanduser_pwd on VxWorks --- Lib/posixpath.py | 3 +++ Lib/test/test_pathlib.py | 2 ++ Lib/test/test_posixpath.py | 3 +++ 3 files changed, 8 insertions(+) diff --git a/Lib/posixpath.py b/Lib/posixpath.py index ecb4e5a8f7072c..cfe3d0d2ffc082 100644 --- a/Lib/posixpath.py +++ b/Lib/posixpath.py @@ -262,6 +262,9 @@ def expanduser(path): # password database, return the path unchanged return path userhome = pwent.pw_dir + # if the current user has no home directory, return the path unchanged + if userhome is None: + return path if isinstance(path, bytes): userhome = os.fsencode(userhome) root = b'/' diff --git a/Lib/test/test_pathlib.py b/Lib/test/test_pathlib.py index 5e5e065b988aaf..6c50434227f03d 100644 --- a/Lib/test/test_pathlib.py +++ b/Lib/test/test_pathlib.py @@ -2465,6 +2465,8 @@ def test_rglob(self): @unittest.skipUnless(hasattr(pwd, 'getpwall'), 'pwd module does not expose getpwall()') + @unittest.skipIf(sys.platform == "vxworks", + "no home directory on VxWorks") def test_expanduser(self): P = self.cls import_helper.import_module('pwd') diff --git a/Lib/test/test_posixpath.py b/Lib/test/test_posixpath.py index 42fd8ef8b17465..e18d01f4635a3a 100644 --- a/Lib/test/test_posixpath.py +++ b/Lib/test/test_posixpath.py @@ -1,5 +1,6 @@ import os import posixpath +import sys import unittest from posixpath import realpath, abspath, dirname, basename from test import test_genericpath @@ -262,6 +263,8 @@ def test_expanduser_home_envvar(self): self.assertEqual(posixpath.expanduser("~/"), "/") self.assertEqual(posixpath.expanduser("~/foo"), "/foo") + @unittest.skipIf(sys.platform == "vxworks", + "no home directory on VxWorks") def test_expanduser_pwd(self): pwd = import_helper.import_module('pwd') From fc412303478de4d776259130075996a9479adc69 Mon Sep 17 00:00:00 2001 From: pxin Date: Fri, 27 Nov 2020 18:13:13 +0800 Subject: [PATCH 2/4] add news --- .../next/Library/2020-11-27-18-09-59.bpo-31904.g8k43d.rst | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 Misc/NEWS.d/next/Library/2020-11-27-18-09-59.bpo-31904.g8k43d.rst diff --git a/Misc/NEWS.d/next/Library/2020-11-27-18-09-59.bpo-31904.g8k43d.rst b/Misc/NEWS.d/next/Library/2020-11-27-18-09-59.bpo-31904.g8k43d.rst new file mode 100644 index 00000000000000..3c65a588e3799b --- /dev/null +++ b/Misc/NEWS.d/next/Library/2020-11-27-18-09-59.bpo-31904.g8k43d.rst @@ -0,0 +1,2 @@ +:func:`posixpath.expanduser` returns the input *path* unchanged if +user home directory is None. From 0665512ee034d93fda2642a2f739bfded2710172 Mon Sep 17 00:00:00 2001 From: pxin Date: Tue, 15 Dec 2020 15:59:41 +0800 Subject: [PATCH 3/4] revert the fix from test_pathlib.py and test_posixpath.py --- Lib/test/test_pathlib.py | 2 -- Lib/test/test_posixpath.py | 3 --- 2 files changed, 5 deletions(-) diff --git a/Lib/test/test_pathlib.py b/Lib/test/test_pathlib.py index 6c50434227f03d..5e5e065b988aaf 100644 --- a/Lib/test/test_pathlib.py +++ b/Lib/test/test_pathlib.py @@ -2465,8 +2465,6 @@ def test_rglob(self): @unittest.skipUnless(hasattr(pwd, 'getpwall'), 'pwd module does not expose getpwall()') - @unittest.skipIf(sys.platform == "vxworks", - "no home directory on VxWorks") def test_expanduser(self): P = self.cls import_helper.import_module('pwd') diff --git a/Lib/test/test_posixpath.py b/Lib/test/test_posixpath.py index e18d01f4635a3a..42fd8ef8b17465 100644 --- a/Lib/test/test_posixpath.py +++ b/Lib/test/test_posixpath.py @@ -1,6 +1,5 @@ import os import posixpath -import sys import unittest from posixpath import realpath, abspath, dirname, basename from test import test_genericpath @@ -263,8 +262,6 @@ def test_expanduser_home_envvar(self): self.assertEqual(posixpath.expanduser("~/"), "/") self.assertEqual(posixpath.expanduser("~/foo"), "/foo") - @unittest.skipIf(sys.platform == "vxworks", - "no home directory on VxWorks") def test_expanduser_pwd(self): pwd = import_helper.import_module('pwd') From 2ab98e9193d87d21f6c1a29f0f84c43b38ac777b Mon Sep 17 00:00:00 2001 From: pxin Date: Thu, 17 Dec 2020 16:49:13 +0800 Subject: [PATCH 4/4] limit the behaviour of no user home to only on VxWorks --- Lib/posixpath.py | 4 ++-- .../next/Library/2020-11-27-18-09-59.bpo-31904.g8k43d.rst | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Lib/posixpath.py b/Lib/posixpath.py index cfe3d0d2ffc082..62afbd0ccf0f0f 100644 --- a/Lib/posixpath.py +++ b/Lib/posixpath.py @@ -262,8 +262,8 @@ def expanduser(path): # password database, return the path unchanged return path userhome = pwent.pw_dir - # if the current user has no home directory, return the path unchanged - if userhome is None: + # if no user home, return the path unchanged on VxWorks + if userhome is None and sys.platform == "vxworks": return path if isinstance(path, bytes): userhome = os.fsencode(userhome) diff --git a/Misc/NEWS.d/next/Library/2020-11-27-18-09-59.bpo-31904.g8k43d.rst b/Misc/NEWS.d/next/Library/2020-11-27-18-09-59.bpo-31904.g8k43d.rst index 3c65a588e3799b..5a687d1eb32deb 100644 --- a/Misc/NEWS.d/next/Library/2020-11-27-18-09-59.bpo-31904.g8k43d.rst +++ b/Misc/NEWS.d/next/Library/2020-11-27-18-09-59.bpo-31904.g8k43d.rst @@ -1,2 +1,2 @@ :func:`posixpath.expanduser` returns the input *path* unchanged if -user home directory is None. +user home directory is None on VxWorks.