Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5106d04

Browse files
Issue #7665: Fixed tests test_ntpath and test_urllib2 when ran in the
directory containing a backslash.
1 parent 624caf7 commit 5106d04

2 files changed

Lines changed: 5 additions & 4 deletions

File tree

Lib/test/test_ntpath.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -306,13 +306,14 @@ def test_abspath(self):
306306
self.skipTest('nt module not available')
307307

308308
def test_relpath(self):
309-
currentdir = os.path.split(os.getcwd())[-1]
310309
tester('ntpath.relpath("a")', 'a')
311310
tester('ntpath.relpath(os.path.abspath("a"))', 'a')
312311
tester('ntpath.relpath("a/b")', 'a\\b')
313312
tester('ntpath.relpath("../a/b")', '..\\a\\b')
314-
tester('ntpath.relpath("a", "../b")', '..\\'+currentdir+'\\a')
315-
tester('ntpath.relpath("a/b", "../c")', '..\\'+currentdir+'\\a\\b')
313+
with support.temp_cwd(support.TESTFN) as cwd_dir:
314+
currentdir = os.path.basename(cwd_dir)
315+
tester('ntpath.relpath("a", "../b")', '..\\'+currentdir+'\\a')
316+
tester('ntpath.relpath("a/b", "../c")', '..\\'+currentdir+'\\a\\b')
316317
tester('ntpath.relpath("a", "b/c")', '..\\..\\a')
317318
tester('ntpath.relpath("c:/foo/bar/bat", "c:/x/y")', '..\\..\\foo\\bar\\bat')
318319
tester('ntpath.relpath("//conky/mountpoint/a", "//conky/mountpoint/b/c")', '..\\..\\a')

Lib/test/test_urllib2.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def test_trivial(self):
4444
self.assertRaises(ValueError, urllib.request.urlopen, 'bogus url')
4545

4646
# XXX Name hacking to get this to work on Windows.
47-
fname = os.path.abspath(urllib.request.__file__).replace('\\', '/')
47+
fname = os.path.abspath(urllib.request.__file__).replace(os.sep, '/')
4848

4949
if os.name == 'nt':
5050
file_url = "file:///%s" % fname

0 commit comments

Comments
 (0)