From 023cd00ccc9bae7b26ad2dfd7b2d887c2f7b8e3d Mon Sep 17 00:00:00 2001 From: Neal Norwitz Date: Fri, 28 Mar 2008 04:41:34 +0000 Subject: [PATCH] Allow use of other ports so the test can pass if 9091 is in use --- Lib/test/test_telnetlib.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/Lib/test/test_telnetlib.py b/Lib/test/test_telnetlib.py index 3a53ad9079c..8eee6667af5 100644 --- a/Lib/test/test_telnetlib.py +++ b/Lib/test/test_telnetlib.py @@ -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)