[Python-checkins] r47230 - in sandbox/trunk/pdb: mconnection.py mpdb.py test/test_mpdb.py

matt.fleming python-checkins at python.org
Tue Jul 4 23:47:08 CEST 2006


Author: matt.fleming
Date: Tue Jul  4 23:47:08 2006
New Revision: 47230

Modified:
   sandbox/trunk/pdb/mconnection.py
   sandbox/trunk/pdb/mpdb.py
   sandbox/trunk/pdb/test/test_mpdb.py
Log:
Avoid infinte loops in test cases. Allow REUSEADDR socket option to be set
when connect() is called, and no longer need to override Pydb's msg_nocr method
because Rocky applied a patch to CVS.


Modified: sandbox/trunk/pdb/mconnection.py
==============================================================================
--- sandbox/trunk/pdb/mconnection.py	(original)
+++ sandbox/trunk/pdb/mconnection.py	Tue Jul  4 23:47:08 2006
@@ -100,7 +100,7 @@
         self._sock = self.output = self.input = None
 	MConnectionInterface.__init__(self)
         
-    def connect(self, addr):
+    def connect(self, addr, reuseaddr=False):
         """Set to allow a connection from a client. 'addr' specifies
         the hostname and port combination of the server.
         """
@@ -112,6 +112,9 @@
         self.port = int(p)
         if not self.listening:
             self._sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+            if reuseaddr:
+                self._sock.setsockopt(socket.SOL_SOCKET,
+                                      socket.SO_REUSEADDR, 1)
             try:
                 self._sock.bind((self.host, self.port))
             except socket.error, e:

Modified: sandbox/trunk/pdb/mpdb.py
==============================================================================
--- sandbox/trunk/pdb/mpdb.py	(original)
+++ sandbox/trunk/pdb/mpdb.py	Tue Jul  4 23:47:08 2006
@@ -142,20 +142,6 @@
         if hasattr(self, 'local_prompt'):
             self.prompt = self.local_prompt
 
-    def msg_nocr(self, msg, out=None):
-        """Common routine for reporting messages. Derived classes may want
-        to override this to capture output.
-        """
-        do_print = True
-        if self.logging:
-            if self.logging_fileobj is not None:
-                print >> self.logging_fileobj, msg,
-            do_print = not self.logging_redirect
-        if do_print:
-            if out is None:
-                out = self.stdout
-            print >> out, msg,
-
     def do_info(self, arg):
         """Extends pydb do_info() to give info about the Mpdb extensions."""
         if not arg:

Modified: sandbox/trunk/pdb/test/test_mpdb.py
==============================================================================
--- sandbox/trunk/pdb/test/test_mpdb.py	(original)
+++ sandbox/trunk/pdb/test/test_mpdb.py	Tue Jul  4 23:47:08 2006
@@ -28,7 +28,7 @@
         address = __addr__
     client.connection = MConnectionClientTCP()
     
-    while True:
+    for i in range(MAXTRIES):
         try:
             client.connection.connect(address)
         except ConnectionFailed, e:
@@ -52,8 +52,7 @@
         MPdb.__init__(self)
         threading.Thread.__init__(self)
         self.botframe = None
-        script = os.path.abspath('thread_script.py')
-        self._sys_argv = [script]
+        self._sys_argv = ['python', '-c', '"pass"']
 
         
     def run(self):
@@ -121,8 +120,10 @@
         self.assertEquals(errmsg, line)
 
         server.disconnect()
-        while server._sock != None:
-            time.sleep(0.1)
+
+        for i in range(MAXTRIES):
+            if server._sock != None: pass
+            else: break
 
     def testRebindOutput(self):
         """ Test rebinding output. """
@@ -168,8 +169,9 @@
         self.client1.onecmd('restart')
         self.client1.connection.write('rquit\n')
 
-        while server.connection != None:
-            time.sleep(0.1)
+        for i in range(MAXTRIES):
+            if server.connection != None: pass
+            else: break
 
 def test_main():
     test_support.run_unittest(TestRemoteDebugging)


More information about the Python-checkins mailing list