Skip to content

Commit 4b320b8

Browse files
committed
Fix Windows tests
1 parent b91afca commit 4b320b8

1 file changed

Lines changed: 10 additions & 7 deletions

File tree

Lib/test/test_urllib2.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -827,14 +827,17 @@ def test_file(self):
827827
urls = [
828828
"file://localhost%s" % urlpath,
829829
"file://%s" % urlpath,
830-
"file://%s%s" % (socket.gethostbyname('localhost'), urlpath),
831830
]
832-
try:
833-
localaddr = socket.gethostbyname(socket.gethostname())
834-
except socket.gaierror:
835-
localaddr = ''
836-
if localaddr:
837-
urls.append("file://%s%s" % (localaddr, urlpath))
831+
if os.name != 'nt':
832+
# On POSIX the local hostname may appear in a local file URL.
833+
# On Windows this would be decoded as a UNC path.
834+
urls.append("file://%s%s" % (socket.gethostbyname('localhost'), urlpath))
835+
try:
836+
localaddr = socket.gethostbyname(socket.gethostname())
837+
except socket.gaierror:
838+
localaddr = ''
839+
if localaddr:
840+
urls.append("file://%s%s" % (localaddr, urlpath))
838841

839842
for url in urls:
840843
f = open(TESTFN, "wb")

0 commit comments

Comments
 (0)