[Python-checkins] r47045 - in sandbox/trunk/pdb: README.txt mconnection.py mpdb.py test/Makefile test/mpdbtest.py
matt.fleming
python-checkins at python.org
Tue Jun 20 16:57:59 CEST 2006
Author: matt.fleming
Date: Tue Jun 20 16:57:58 2006
New Revision: 47045
Added:
sandbox/trunk/pdb/test/Makefile
sandbox/trunk/pdb/test/mpdbtest.py
Modified:
sandbox/trunk/pdb/README.txt
sandbox/trunk/pdb/mconnection.py
sandbox/trunk/pdb/mpdb.py
Log:
Added a unit test for the pdbserver and target commands, and a Makefile to
make it easier to run the tests. Use mpdb.msg() for all output in mpdb.py now.
Added some items to the TODO list.
Modified: sandbox/trunk/pdb/README.txt
==============================================================================
--- sandbox/trunk/pdb/README.txt (original)
+++ sandbox/trunk/pdb/README.txt Tue Jun 20 16:57:58 2006
@@ -9,7 +9,7 @@
aims to correct this wish.
-=[TODO]=-
-* Write more unit tests
+* Write more unit tests, test the pdbserver and target commands.
* sort out the namespace corruption -
"""
c:\soc\pdb\test.py(3)x()
@@ -17,5 +17,7 @@
(MPdb)p i
*** NameError: <exceptions.NameError instance at 0x00BF6990>
"""
-
+* Write a signal handler that scripts can import from mpdb that, when
+ the signal is received, start remote debugging.
+* info target,threads command needs to be written.
Modified: sandbox/trunk/pdb/mconnection.py
==============================================================================
--- sandbox/trunk/pdb/mconnection.py (original)
+++ sandbox/trunk/pdb/mconnection.py Tue Jun 20 16:57:58 2006
@@ -157,7 +157,6 @@
def readline(self, bufsize=2048):
line = self._sock.recv(bufsize)
return line
-
def flush(self):
pass
Modified: sandbox/trunk/pdb/mpdb.py
==============================================================================
--- sandbox/trunk/pdb/mpdb.py (original)
+++ sandbox/trunk/pdb/mpdb.py Tue Jun 20 16:57:58 2006
@@ -50,7 +50,6 @@
""" This method rebinds the debugger's input to the object specified
by 'new_input'.
"""
- self.stdin.flush()
self.use_rawinput = False
self.stdin = new_input
@@ -116,7 +115,11 @@
target serial -- Use a remote computer via a serial line
target tcp -- Use a remote computer via a socket connection
"""
- target, addr = args.split(' ')
+ try:
+ target, addr = args.split(' ')
+ except ValueError:
+ self.msg('Invalid arguments')
+ return
if self.target == 'remote':
self.msg('Already connected to a remote machine.')
return
@@ -184,7 +187,11 @@
`pdbserver ConnectionClass comm scriptfile [args ...]'
"""
- target, comm, scriptfile_and_args = args.split(' ')
+ try:
+ target, comm, scriptfile_and_args = args.split(' ')
+ except ValueError:
+ self.msg('Invalid arguments')
+ return
if self.target == 'remote':
self.msg('Already connected remotely')
return
@@ -208,6 +215,8 @@
self._rebind_output(self.connection)
self._rebind_input(self.connection)
+# This is a mess. It's only here so that I can test other features of the
+# debugger whilst I'm writing them. It will be removed at some point.
def main(options):
opts = options[0]
args = options[1]
@@ -222,21 +231,21 @@
mpdb._runscript(mainpyfile)
if mpdb._user_requested_quit:
break
- print "The program finished and will be restarted"
+ self.msg("The program finished and will be restarted")
except SystemExit:
# In most cases SystemExit does not warrant a post-mortem session.
- print "The program exited via sys.exit(). " + \
- "Exit status:",sys.exc_info()[1]
+ mpdb.msg("The program exited via sys.exit(). " + \
+ "Exit status:",sys.exc_info()[1])
except:
- print traceback.format_exc()
- print "Uncaught exception. Entering post mortem debugging"
- print "Running 'cont' or 'step' will restart the program"
+ mpdb.msg(traceback.format_exc())
+ mpdb.msg("Uncaught exception. Entering post mortem debugging")
+ mpdb.msg("Running 'cont' or 'step' will restart the program")
t = sys.exc_info()[2]
while t.tb_next is not None:
t = t.tb_next
mpdb.interaction(t.tb_frame,t)
- print "Post mortem debugger finished. The " + \
- mainpyfile + " will be restarted"
+ mpdb.msg("Post mortem debugger finished. The " + \
+ mainpyfile + " will be restarted")
# Utility functions
Added: sandbox/trunk/pdb/test/Makefile
==============================================================================
--- (empty file)
+++ sandbox/trunk/pdb/test/Makefile Tue Jun 20 16:57:58 2006
@@ -0,0 +1,17 @@
+# Makefile for mpdb's unit tests.
+#
+# To run all tests type:
+#
+# make test
+#
+# or 'make target' to run a specific test, such as 'make tcptest'
+
+PY = python2.5
+
+test: mpdbtest tcptest
+
+mpdbtest:
+ $(PY) mpdbtest.py
+
+tcptest:
+ $(PY) tcptest.py
Added: sandbox/trunk/pdb/test/mpdbtest.py
==============================================================================
--- (empty file)
+++ sandbox/trunk/pdb/test/mpdbtest.py Tue Jun 20 16:57:58 2006
@@ -0,0 +1,43 @@
+#!/usr/bin/env python
+
+import sys
+import socket
+import thread
+import threading
+import unittest
+
+__addr__ = 'localhost:8000'
+script = ""
+
+sys.path.append("..")
+from mpdb import MPdb
+from mconnection import MServerConnectionTCP, MClientConnectionTCP
+
+def doTargetConnect():
+ global g_client
+ while True:
+ try:
+ g_client.do_target('tcp '+__addr__)
+ if CONNECTED:
+ break
+ except error:
+ pass
+ g_client.onecmd('help')
+ g_client.onecmd('quit')
+
+class TestRemoteDebugging(unittest.TestCase):
+ def testPdbserver(self):
+ global g_server, g_client, CONNECTED
+ g_server = MPdb()
+ g_client = MPdb()
+
+ self.server_tid = thread.start_new_thread(doTargetConnect, ())
+ g_server.do_pdbserver('tcp '+__addr__+' '+script)
+ CONNECTED = True
+
+ # XXX mpdb needs a bottom frame before it exits
+ g_server.botframe = None
+ g_server.cmdloop()
+
+if __name__ == '__main__':
+ unittest.main()
More information about the Python-checkins
mailing list