Skip to content

Commit 985fee0

Browse files
committed
Update by review
1 parent 83851a2 commit 985fee0

1 file changed

Lines changed: 8 additions & 17 deletions

File tree

Lib/test/test_urllib2.py

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -850,28 +850,19 @@ def test_file(self):
850850
self.assertEqual(headers["Last-modified"], modified)
851851
self.assertEqual(respurl, canonurl)
852852

853-
_, cwd = os.path.splitdrive(os.getcwd())
854-
cwd = cwd.replace("\\", "/")
853+
with open(TESTFN, "wb") as f:
854+
f.write(towrite)
855+
self.addCleanup(os.remove, TESTFN)
855856
for url in [
856857
parsed._replace(netloc='localhost:80').geturl(),
857858
"file:///file_does_not_exist.txt",
858859
"file://not-a-local-host.com//dir/file.txt",
859-
"file://%s:80%s/%s" % (socket.gethostbyname('localhost'),
860-
cwd, TESTFN),
861-
"file://somerandomhost.ontheinternet.com%s/%s" %
862-
(cwd, TESTFN),
860+
"file://%s:80%s" % (socket.gethostbyname('localhost'),
861+
urllib.request.pathname2url(os.path.join(os.getcwd(), TESTFN))),
862+
"file://somerandomhost.ontheinternet.com%s" %
863+
urllib.request.pathname2url(os.path.join(os.getcwd(), TESTFN)),
863864
]:
864-
try:
865-
f = open(TESTFN, "wb")
866-
try:
867-
f.write(towrite)
868-
finally:
869-
f.close()
870-
871-
self.assertRaises(urllib.error.URLError,
872-
h.file_open, Request(url))
873-
finally:
874-
os.remove(TESTFN)
865+
self.assertRaises(urllib.error.URLError, h.file_open, Request(url))
875866

876867
h = urllib.request.FileHandler()
877868
o = h.parent = MockOpener()

0 commit comments

Comments
 (0)