diff options
author | Anthony Sottile <asottile@umich.edu> | 2019-03-12 15:39:57 (GMT) |
---|---|---|
committer | Steve Dower <steve.dower@microsoft.com> | 2019-03-12 15:39:57 (GMT) |
commit | 25ec4a45dcc36c8087f93bd1634b311613244fc6 (patch) | |
tree | 1e5e08a4ee2c9f1625ad980528285cd7b3d4d5fd /Lib | |
parent | 410aea1ebf2f56364369be3b477763ce78577c07 (diff) | |
download | cpython-25ec4a45dcc36c8087f93bd1634b311613244fc6.zip cpython-25ec4a45dcc36c8087f93bd1634b311613244fc6.tar.gz cpython-25ec4a45dcc36c8087f93bd1634b311613244fc6.tar.bz2 |
bpo-36264: Don't honor POSIX HOME in os.path.expanduser on Windows (GH-12282)
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/distutils/tests/test_config.py | 1 | ||||
-rw-r--r-- | Lib/distutils/tests/test_dist.py | 2 | ||||
-rw-r--r-- | Lib/ntpath.py | 4 | ||||
-rw-r--r-- | Lib/test/test_netrc.py | 1 | ||||
-rw-r--r-- | Lib/test/test_ntpath.py | 21 |
5 files changed, 15 insertions, 14 deletions
diff --git a/Lib/distutils/tests/test_config.py b/Lib/distutils/tests/test_config.py index 77ef788..344084a 100644 --- a/Lib/distutils/tests/test_config.py +++ b/Lib/distutils/tests/test_config.py @@ -60,6 +60,7 @@ class BasePyPIRCCommandTestCase(support.TempdirManager, super(BasePyPIRCCommandTestCase, self).setUp() self.tmp_dir = self.mkdtemp() os.environ['HOME'] = self.tmp_dir + os.environ['USERPROFILE'] = self.tmp_dir self.rc = os.path.join(self.tmp_dir, '.pypirc') self.dist = Distribution() diff --git a/Lib/distutils/tests/test_dist.py b/Lib/distutils/tests/test_dist.py index 0a19f0f..cc34725 100644 --- a/Lib/distutils/tests/test_dist.py +++ b/Lib/distutils/tests/test_dist.py @@ -463,7 +463,7 @@ class MetadataTestCase(support.TempdirManager, support.EnvironGuard, # win32-style if sys.platform == 'win32': # home drive should be found - os.environ['HOME'] = temp_dir + os.environ['USERPROFILE'] = temp_dir files = dist.find_config_files() self.assertIn(user_filename, files, '%r not found in %r' % (user_filename, files)) diff --git a/Lib/ntpath.py b/Lib/ntpath.py index 11bb297..b5e1d12 100644 --- a/Lib/ntpath.py +++ b/Lib/ntpath.py @@ -299,9 +299,7 @@ def expanduser(path): while i < n and path[i] not in _get_bothseps(path): i += 1 - if 'HOME' in os.environ: - userhome = os.environ['HOME'] - elif 'USERPROFILE' in os.environ: + if 'USERPROFILE' in os.environ: userhome = os.environ['USERPROFILE'] elif not 'HOMEPATH' in os.environ: return path diff --git a/Lib/test/test_netrc.py b/Lib/test/test_netrc.py index ae53988..7ce7e56 100644 --- a/Lib/test/test_netrc.py +++ b/Lib/test/test_netrc.py @@ -154,6 +154,7 @@ class NetrcTestCase(unittest.TestCase): called.append(s) with support.EnvironmentVarGuard() as environ: environ.set('HOME', fake_home) + environ.set('USERPROFILE', fake_home) result = orig_expanduser(s) return result diff --git a/Lib/test/test_ntpath.py b/Lib/test/test_ntpath.py index 223e50f..fc2398c 100644 --- a/Lib/test/test_ntpath.py +++ b/Lib/test/test_ntpath.py @@ -262,20 +262,21 @@ class TestNtpath(unittest.TestCase): env['USERPROFILE'] = 'C:\\eric\\idle' tester('ntpath.expanduser("~test")', 'C:\\eric\\test') tester('ntpath.expanduser("~")', 'C:\\eric\\idle') - - env.clear() - env['HOME'] = 'C:\\idle\\eric' - tester('ntpath.expanduser("~test")', 'C:\\idle\\test') - tester('ntpath.expanduser("~")', 'C:\\idle\\eric') - tester('ntpath.expanduser("~test\\foo\\bar")', - 'C:\\idle\\test\\foo\\bar') + 'C:\\eric\\test\\foo\\bar') tester('ntpath.expanduser("~test/foo/bar")', - 'C:\\idle\\test/foo/bar') + 'C:\\eric\\test/foo/bar') tester('ntpath.expanduser("~\\foo\\bar")', - 'C:\\idle\\eric\\foo\\bar') + 'C:\\eric\\idle\\foo\\bar') tester('ntpath.expanduser("~/foo/bar")', - 'C:\\idle\\eric/foo/bar') + 'C:\\eric\\idle/foo/bar') + + # bpo-36264: ignore `HOME` when set on windows + env.clear() + env['HOME'] = 'F:\\' + env['USERPROFILE'] = 'C:\\eric\\idle' + tester('ntpath.expanduser("~test")', 'C:\\eric\\test') + tester('ntpath.expanduser("~")', 'C:\\eric\\idle') @unittest.skipUnless(nt, "abspath requires 'nt' module") def test_abspath(self): |