[Python-checkins] r47063 - sandbox/trunk/pdb/test/Makefile sandbox/trunk/pdb/test/mpdbtest.py sandbox/trunk/pdb/test/tcptest.py sandbox/trunk/pdb/test/test_mconnection.py sandbox/trunk/pdb/test/test_mpdb.py
matt.fleming
python-checkins at python.org
Thu Jun 22 02:09:12 CEST 2006
Author: matt.fleming
Date: Thu Jun 22 02:09:11 2006
New Revision: 47063
Added:
sandbox/trunk/pdb/test/test_mconnection.py
- copied, changed from r47045, sandbox/trunk/pdb/test/tcptest.py
sandbox/trunk/pdb/test/test_mpdb.py
- copied, changed from r47045, sandbox/trunk/pdb/test/mpdbtest.py
Removed:
sandbox/trunk/pdb/test/mpdbtest.py
sandbox/trunk/pdb/test/tcptest.py
Modified:
sandbox/trunk/pdb/test/Makefile
Log:
Using test_* filename convention. Also added some more test cases for the
mconnection file.
Modified: sandbox/trunk/pdb/test/Makefile
==============================================================================
--- sandbox/trunk/pdb/test/Makefile (original)
+++ sandbox/trunk/pdb/test/Makefile Thu Jun 22 02:09:11 2006
@@ -6,15 +6,15 @@
#
# or 'make target' to run a specific test, such as 'make tcptest'
-PY = python2.4
+PY = python
-.PHONY: all test mpdbtest tcptest
+.PHONY: all test test_mpdb test_mconnection
all: test
-test: mpdbtest tcptest
+test: test_mpdb test_mconnection
-mpdbtest:
- @$(PY) mpdbtest.py
+test_mpdb:
+ @$(PY) test_mpdb.py
-tcptest:
- @$(PY) tcptest.py
+test_mconnection:
+ @$(PY) test_mconnection.py
Deleted: /sandbox/trunk/pdb/test/mpdbtest.py
==============================================================================
--- /sandbox/trunk/pdb/test/mpdbtest.py Thu Jun 22 02:09:11 2006
+++ (empty file)
@@ -1,43 +0,0 @@
-#!/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()
Deleted: /sandbox/trunk/pdb/test/tcptest.py
==============================================================================
--- /sandbox/trunk/pdb/test/tcptest.py Thu Jun 22 02:09:11 2006
+++ (empty file)
@@ -1,47 +0,0 @@
-#!/usr/bin/env python
-
-# This unit test doesn't use any of the debugger code. It is meant solely
-# to test the connection classes.
-
-import sys
-import socket
-import thread
-import threading
-import unittest
-
-__addr__ = 'localhost:8000'
-
-sys.path.append("..")
-from mconnection import MServerConnectionTCP, MClientConnectionTCP
-
-# Try to connect the client to addr either until we've tried MAXTRIES
-# times or until it succeeds.
-MAXTRIES = 100
-def repeatedConnect(client, addr):
- for i in range(MAXTRIES):
- try:
- client.connect(addr)
- # The _sock variable appears when there's a connection
- if client._sock: break
- except socket.error:
- pass
-
-class TestTCPConnections(unittest.TestCase):
- def setUp(self):
- self.server = MServerConnectionTCP()
- self.client = MClientConnectionTCP()
-
- def testClientConnectAndRead(self):
- t_id = thread.start_new_thread(repeatedConnect, (self.client,__addr__))
- self.server.connect(__addr__)
-
- self.server.write("good")
- line = self.client.readline()
- self.assertEqual("good", line, "Could not read from server")
-
- def tearDown(self):
- self.server.disconnect()
- self.client.disconnect()
-
-if __name__ == '__main__':
- unittest.main()
Copied: sandbox/trunk/pdb/test/test_mconnection.py (from r47045, sandbox/trunk/pdb/test/tcptest.py)
==============================================================================
--- sandbox/trunk/pdb/test/tcptest.py (original)
+++ sandbox/trunk/pdb/test/test_mconnection.py Thu Jun 22 02:09:11 2006
@@ -3,20 +3,27 @@
# This unit test doesn't use any of the debugger code. It is meant solely
# to test the connection classes.
+import os
import sys
import socket
import thread
-import threading
import unittest
+from test import test_support
+from socket import gaierror
+
+# Global vars
__addr__ = 'localhost:8000'
+MAXTRIES = 100
+TESTFN = 'device'
sys.path.append("..")
-from mconnection import MServerConnectionTCP, MClientConnectionTCP
+from mconnection import (MServerConnectionTCP, MClientConnectionTCP,
+ MServerConnectionSerial, MClientConnectionSerial,
+ ConnectionRefused)
# Try to connect the client to addr either until we've tried MAXTRIES
# times or until it succeeds.
-MAXTRIES = 100
def repeatedConnect(client, addr):
for i in range(MAXTRIES):
try:
@@ -30,18 +37,106 @@
def setUp(self):
self.server = MServerConnectionTCP()
self.client = MClientConnectionTCP()
-
+
+ def testClientConnectToServer(self):
+ """(tcp) Connect client to server. """
+ thread.start_new_thread(repeatedConnect, (self.client, __addr__))
+ self.server.connect(__addr__)
+
def testClientConnectAndRead(self):
- t_id = thread.start_new_thread(repeatedConnect, (self.client,__addr__))
+ """(tcp) Connect to server and read/write. """
+ thread.start_new_thread(repeatedConnect, (self.client,__addr__))
self.server.connect(__addr__)
self.server.write("good")
line = self.client.readline()
self.assertEqual("good", line, "Could not read from server")
+ self.client.write('success')
+ line = self.server.readline()
+ self.assertEqual('success\n', line, 'Could not read from client')
+
+ def testDisconnectDisconnected(self):
+ """(tcp) Disconnect a disconnected session. """
+ s = MServerConnectionTCP()
+ s.disconnect()
+ s.disconnect()
+
+ def testReadline(self):
+ """(tcp) Make sure readline method works. """
+ thread.start_new_thread(repeatedConnect, (self.client,__addr__))
+ self.server.connect(__addr__)
+
+ self.client.write('good')
+ line = self.server.readline()
+ self.assertEquals('good\n', line, 'Could not read first line.')
+
+ def testConnectionRefused(self):
+ """(tcp) Test refused connection. """
+ thread.start_new_thread(repeatedConnect, (self.client, __addr__))
+ self.server.connect(__addr__)
+
+ # Set up second server on same port
+ s = MServerConnectionTCP()
+ self.assertRaises(ConnectionRefused, s.connect, __addr__)
+
+ def tearDown(self):
+ self.server.disconnect()
+ self.client.disconnect()
+
+class TestSerialConnections(unittest.TestCase):
+ """ This test just uses a file instead of a serial device, which
+ on *nix systems is just files anyway.
+ """
+ def setUp(self):
+ self.server = MServerConnectionSerial()
+ self.client = MClientConnectionSerial()
+ fd = open(TESTFN, "wr+")
+ fd.close()
+ self.server.connect(TESTFN)
+ self.client.connect(TESTFN)
+
+ def testClientToServerConnect(self):
+ """(serial) Connect client to server. """
+ self.client.disconnect()
+ self.server.disconnect()
+
+ def testClientWriteRead(self):
+ """(serial) Connect client to server and read/write. """
+ self.client.write('success!')
+ line = self.server.readline()
+ self.assertEquals('success!\n', line, 'Could not read from client.')
+
+ # Unfortunately the text file doesn't erase what we've written like a
+ # device of stream, so we have to close the the file and re-open it.
+ self.server.disconnect()
+ self.server.connect(TESTFN)
+ self.server.write('great!')
+ line = self.client.readline()
+ self.assertEquals('great!\n', line, 'Could not read from server.')
+
+ def testDisconnectDisconnected(self):
+ """(serial) Disconnect a disconnected session. """
+ self.server.disconnect()
+
+ def testReadline(self):
+ """(serial) Make sure readline method works. """
+ self.client.write('success!\nNext line.')
+ self.client.disconnect()
+ line = self.server.readline()
+ self.assertEquals('success!\n', line, 'Could not read first line')
+ line = self.server.readline()
+ self.assertEquals('Next line.\n', line, 'Could not read second line.')
+ line = self.server.readline()
+ self.assertEquals('', line, 'Could not read third line.')
def tearDown(self):
self.server.disconnect()
self.client.disconnect()
+ os.remove(TESTFN)
+
+def test_main():
+ test_support.run_unittest(TestTCPConnections, TestSerialConnections)
+
if __name__ == '__main__':
- unittest.main()
+ test_main()
Copied: sandbox/trunk/pdb/test/test_mpdb.py (from r47045, sandbox/trunk/pdb/test/mpdbtest.py)
==============================================================================
--- sandbox/trunk/pdb/test/mpdbtest.py (original)
+++ sandbox/trunk/pdb/test/test_mpdb.py Thu Jun 22 02:09:11 2006
@@ -3,41 +3,81 @@
import sys
import socket
import thread
-import threading
import unittest
+from test import test_support
+
+# Global vars
__addr__ = 'localhost:8000'
script = ""
+g_server = None
+g_client = None
+CONNECTED = False
+# Commands to execute on the server
+cmds = ['info target', 'help', 'quit']
sys.path.append("..")
from mpdb import MPdb
from mconnection import MServerConnectionTCP, MClientConnectionTCP
-def doTargetConnect():
+def doTargetConnect(cmds=None):
global g_client
while True:
try:
g_client.do_target('tcp '+__addr__)
if CONNECTED:
break
- except error:
+ except socket.error:
pass
- g_client.onecmd('help')
- g_client.onecmd('quit')
+ if cmds:
+ for c in cmds:
+ g_client.onecmd(c)
+class MPdbTest(MPdb):
+ def __init__(self):
+ MPdb.__init__(self)
+ self.lines = []
+
+ def msg_nocr(self, msg):
+ self.lines.append(msg)
+
class TestRemoteDebugging(unittest.TestCase):
+ """ Test Case to make sure debugging remotely works properly. """
+ def setUp(self):
+ self.server = MPdb()
+ global g_client
+ g_client = MPdbTest()
+
+ def tearDown(self):
+ global CONNECTED
+ self.server.connection.disconnect()
+ CONNETED = False
+
def testPdbserver(self):
- global g_server, g_client, CONNECTED
- g_server = MPdb()
- g_client = MPdb()
+ """ Test the pdbserver command. """
+ global CONNECTED
self.server_tid = thread.start_new_thread(doTargetConnect, ())
- g_server.do_pdbserver('tcp '+__addr__+' '+script)
+ self.server.do_pdbserver('tcp '+__addr__+' '+script)
CONNECTED = True
+ def testCommandsOnServer(self):
+ """ Test all supported commands on the pdbserver.
+ """
+ global CONNECTED, g_client
+
+ self.server_tid = thread.start_new_thread(doTargetConnect, (cmds,))
+ self.server.do_pdbserver('tcp '+__addr__+' '+script)
+ CONNECTED = True
+
# XXX mpdb needs a bottom frame before it exits
- g_server.botframe = None
- g_server.cmdloop()
+ self.server.botframe = None
+ self.server.cmdloop()
+ self.assertEquals('target is remote\n', g_client.lines[1])
+
+def test_main():
+ test_support.run_unittest(TestRemoteDebugging)
+
if __name__ == '__main__':
- unittest.main()
+ test_main()
More information about the Python-checkins
mailing list