Skip to content

Commit b4dfafa

Browse files
Trying to make the tests work in Windows and Solaris, everywhere
else just works
1 parent 62c744e commit b4dfafa

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

Lib/test/test_urllib.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -549,25 +549,28 @@ def server(evt):
549549
serv = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
550550
serv.settimeout(3)
551551
serv.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
552-
serv.bind(("", 9091))
552+
serv.bind(("", 9093))
553553
serv.listen(5)
554554
try:
555555
conn, addr = serv.accept()
556-
except socket.timeout:
557-
pass
558-
else:
559556
conn.send("1 Hola mundo\n")
560-
conn.recv(13)
557+
cantdata = 0
558+
while cantdata < 13:
559+
print "len:", cantdata
560+
data = conn.recv(13-cantdata)
561+
cantdata += len(data)
561562
conn.send("2 No more lines\n")
562563
conn.close()
564+
except socket.timeout:
565+
pass
563566
finally:
564567
serv.close()
565568
evt.set()
566569

567570
class FTPWrapperTests(unittest.TestCase):
568571

569572
def setUp(self):
570-
ftplib.FTP.port = 9091
573+
ftplib.FTP.port = 9093
571574
self.evt = threading.Event()
572575
threading.Thread(target=server, args=(self.evt,)).start()
573576
time.sleep(.1)
@@ -577,28 +580,27 @@ def tearDown(self):
577580

578581
def testBasic(self):
579582
# connects
580-
ftp = urllib.ftpwrapper("myuser", "mypass", "localhost", 9091, [])
583+
ftp = urllib.ftpwrapper("myuser", "mypass", "localhost", 9093, [])
581584
ftp.ftp.sock.close()
582585

583586
def testTimeoutDefault(self):
584587
# default
585-
ftp = urllib.ftpwrapper("myuser", "mypass", "localhost", 9091, [])
588+
ftp = urllib.ftpwrapper("myuser", "mypass", "localhost", 9093, [])
586589
self.assertTrue(ftp.ftp.sock.gettimeout() is None)
587590
ftp.ftp.sock.close()
588591

589592
def testTimeoutValue(self):
590593
# a value
591-
ftp = urllib.ftpwrapper("myuser", "mypass", "localhost", 9091, [], timeout=30)
594+
ftp = urllib.ftpwrapper("myuser", "mypass", "localhost", 9093, [], timeout=30)
592595
self.assertEqual(ftp.ftp.sock.gettimeout(), 30)
593596
ftp.ftp.sock.close()
594597

595-
596598
def testTimeoutNone(self):
597599
# None, having other default
598600
previous = socket.getdefaulttimeout()
599601
socket.setdefaulttimeout(30)
600602
try:
601-
ftp = urllib.ftpwrapper("myuser", "mypass", "localhost", 9091, [], timeout=30)
603+
ftp = urllib.ftpwrapper("myuser", "mypass", "localhost", 9093, [])
602604
finally:
603605
socket.setdefaulttimeout(previous)
604606
self.assertEqual(ftp.ftp.sock.gettimeout(), 30)

0 commit comments

Comments
 (0)