diff options
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_ntpath.py | 43 | ||||
-rw-r--r-- | Lib/test/test_pathlib.py | 2 |
2 files changed, 29 insertions, 16 deletions
diff --git a/Lib/test/test_ntpath.py b/Lib/test/test_ntpath.py index a8f764f48c..f97aca5f94 100644 --- a/Lib/test/test_ntpath.py +++ b/Lib/test/test_ntpath.py @@ -503,34 +503,47 @@ class TestNtpath(NtpathTestCase): env.clear() tester('ntpath.expanduser("~test")', '~test') - env['HOMEPATH'] = 'eric\\idle' env['HOMEDRIVE'] = 'C:\\' - tester('ntpath.expanduser("~test")', 'C:\\eric\\test') - tester('ntpath.expanduser("~")', 'C:\\eric\\idle') + env['HOMEPATH'] = 'Users\\eric' + env['USERNAME'] = 'eric' + tester('ntpath.expanduser("~test")', 'C:\\Users\\test') + tester('ntpath.expanduser("~")', 'C:\\Users\\eric') del env['HOMEDRIVE'] - tester('ntpath.expanduser("~test")', 'eric\\test') - tester('ntpath.expanduser("~")', 'eric\\idle') + tester('ntpath.expanduser("~test")', 'Users\\test') + tester('ntpath.expanduser("~")', 'Users\\eric') env.clear() - env['USERPROFILE'] = 'C:\\eric\\idle' - tester('ntpath.expanduser("~test")', 'C:\\eric\\test') - tester('ntpath.expanduser("~")', 'C:\\eric\\idle') + env['USERPROFILE'] = 'C:\\Users\\eric' + env['USERNAME'] = 'eric' + tester('ntpath.expanduser("~test")', 'C:\\Users\\test') + tester('ntpath.expanduser("~")', 'C:\\Users\\eric') tester('ntpath.expanduser("~test\\foo\\bar")', - 'C:\\eric\\test\\foo\\bar') + 'C:\\Users\\test\\foo\\bar') tester('ntpath.expanduser("~test/foo/bar")', - 'C:\\eric\\test/foo/bar') + 'C:\\Users\\test/foo/bar') tester('ntpath.expanduser("~\\foo\\bar")', - 'C:\\eric\\idle\\foo\\bar') + 'C:\\Users\\eric\\foo\\bar') tester('ntpath.expanduser("~/foo/bar")', - 'C:\\eric\\idle/foo/bar') + 'C:\\Users\\eric/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') + env['USERPROFILE'] = 'C:\\Users\\eric' + env['USERNAME'] = 'eric' + tester('ntpath.expanduser("~test")', 'C:\\Users\\test') + tester('ntpath.expanduser("~")', 'C:\\Users\\eric') + + # bpo-39899: don't guess another user's home directory if + # `%USERNAME% != basename(%USERPROFILE%)` + env.clear() + env['USERPROFILE'] = 'C:\\Users\\eric' + env['USERNAME'] = 'idle' + tester('ntpath.expanduser("~test")', '~test') + tester('ntpath.expanduser("~")', 'C:\\Users\\eric') + + @unittest.skipUnless(nt, "abspath requires 'nt' module") def test_abspath(self): diff --git a/Lib/test/test_pathlib.py b/Lib/test/test_pathlib.py index 2643119352..0c89b6ef14 100644 --- a/Lib/test/test_pathlib.py +++ b/Lib/test/test_pathlib.py @@ -2609,7 +2609,7 @@ class WindowsPathTest(_BasePathTest, unittest.TestCase): env.pop('USERNAME', None) self.assertEqual(p1.expanduser(), P('C:/Users/alice/My Documents')) - self.assertRaises(KeyError, p2.expanduser) + self.assertRaises(RuntimeError, p2.expanduser) env['USERNAME'] = 'alice' self.assertEqual(p2.expanduser(), P('C:/Users/alice/My Documents')) |