Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Lib/distutils/tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ def setUp(self):
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()

Expand Down
2 changes: 1 addition & 1 deletion Lib/distutils/tests/test_dist.py
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ def test_custom_pydistutils(self):
# 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))
Expand Down
4 changes: 1 addition & 3 deletions Lib/ntpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions Lib/test/test_netrc.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ def fake_expanduser(s):
called.append(s)
with support.EnvironmentVarGuard() as environ:
environ.set('HOME', fake_home)
environ.set('USERPROFILE', fake_home)
result = orig_expanduser(s)
return result

Expand Down
21 changes: 11 additions & 10 deletions Lib/test/test_ntpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,20 +262,21 @@ def test_expanduser(self):
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):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Don't honor POSIX ``HOME`` in ``os.path.expanduser`` on windows. Patch by
Anthony Sottile.