Allow use of other ports so the test can pass if 9091 is in use
This commit is contained in:
parent
8b9091fba0
commit
023cd00ccc
|
@ -6,12 +6,14 @@ import time
|
|||
from unittest import TestCase
|
||||
from test import test_support
|
||||
|
||||
PORT = 9091
|
||||
|
||||
def server(evt):
|
||||
serv = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
serv.settimeout(3)
|
||||
serv.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
||||
serv.bind(("", 9091))
|
||||
global PORT
|
||||
PORT = test_support.bind_port(serv, "", PORT)
|
||||
serv.listen(5)
|
||||
evt.set()
|
||||
try:
|
||||
|
@ -36,24 +38,24 @@ class GeneralTests(TestCase):
|
|||
|
||||
def testBasic(self):
|
||||
# connects
|
||||
telnet = telnetlib.Telnet("localhost", 9091)
|
||||
telnet = telnetlib.Telnet("localhost", PORT)
|
||||
telnet.sock.close()
|
||||
|
||||
def testTimeoutDefault(self):
|
||||
# default
|
||||
telnet = telnetlib.Telnet("localhost", 9091)
|
||||
telnet = telnetlib.Telnet("localhost", PORT)
|
||||
self.assertTrue(telnet.sock.gettimeout() is None)
|
||||
telnet.sock.close()
|
||||
|
||||
def testTimeoutValue(self):
|
||||
# a value
|
||||
telnet = telnetlib.Telnet("localhost", 9091, timeout=30)
|
||||
telnet = telnetlib.Telnet("localhost", PORT, timeout=30)
|
||||
self.assertEqual(telnet.sock.gettimeout(), 30)
|
||||
telnet.sock.close()
|
||||
|
||||
def testTimeoutDifferentOrder(self):
|
||||
telnet = telnetlib.Telnet(timeout=30)
|
||||
telnet.open("localhost", 9091)
|
||||
telnet.open("localhost", PORT)
|
||||
self.assertEqual(telnet.sock.gettimeout(), 30)
|
||||
telnet.sock.close()
|
||||
|
||||
|
@ -62,7 +64,7 @@ class GeneralTests(TestCase):
|
|||
previous = socket.getdefaulttimeout()
|
||||
socket.setdefaulttimeout(30)
|
||||
try:
|
||||
telnet = telnetlib.Telnet("localhost", 9091, timeout=None)
|
||||
telnet = telnetlib.Telnet("localhost", PORT, timeout=None)
|
||||
finally:
|
||||
socket.setdefaulttimeout(previous)
|
||||
self.assertEqual(telnet.sock.gettimeout(), 30)
|
||||
|
|
Loading…
Reference in New Issue