summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_asyncore.py
diff options
context:
space:
mode:
authorR. David Murray <rdmurray@bitdance.com>2009-04-12 15:35:44 (GMT)
committerR. David Murray <rdmurray@bitdance.com>2009-04-12 15:35:44 (GMT)
commit78532baeabc4234e3894c775f2bb7e0a21c12e0e (patch)
tree338d668a07b6ffc4f09abeac709b47881cc157ee /Lib/test/test_asyncore.py
parent12f6a997e86a8dddefa3d9d0399aee73db4a8672 (diff)
downloadcpython-78532baeabc4234e3894c775f2bb7e0a21c12e0e.zip
cpython-78532baeabc4234e3894c775f2bb7e0a21c12e0e.tar.gz
cpython-78532baeabc4234e3894c775f2bb7e0a21c12e0e.tar.bz2
Merged revisions 70873,70904,70934,71490 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r70873 | josiah.carlson | 2009-03-31 15:32:34 -0400 (Tue, 31 Mar 2009) | 2 lines This resolves issue 1161031. Tests pass. ........ r70904 | josiah.carlson | 2009-03-31 17:49:36 -0400 (Tue, 31 Mar 2009) | 3 lines Made handle_expt_event() be called last, so that we don't accidentally read after closing the socket. ........ r70934 | josiah.carlson | 2009-03-31 21:28:11 -0400 (Tue, 31 Mar 2009) | 2 lines Fix for failing asyncore tests. ........ r71490 | r.david.murray | 2009-04-11 13:52:56 -0400 (Sat, 11 Apr 2009) | 4 lines Make test_asyncore tests match code changes introduced by the fix to Issue1161031, refactoring the test to simplify it in the process. ........
Diffstat (limited to 'Lib/test/test_asyncore.py')
-rw-r--r--Lib/test/test_asyncore.py60
1 files changed, 22 insertions, 38 deletions
diff --git a/Lib/test/test_asyncore.py b/Lib/test/test_asyncore.py
index 940b45e..6837602 100644
--- a/Lib/test/test_asyncore.py
+++ b/Lib/test/test_asyncore.py
@@ -116,12 +116,24 @@ class HelperFunctionTests(unittest.TestCase):
def test_readwrite(self):
# Check that correct methods are called by readwrite()
+ attributes = ('read', 'expt', 'write', 'closed', 'error_handled')
+
+ expected = (
+ (select.POLLIN, 'read'),
+ (select.POLLPRI, 'expt'),
+ (select.POLLOUT, 'write'),
+ (select.POLLERR, 'closed'),
+ (select.POLLHUP, 'closed'),
+ (select.POLLNVAL, 'closed'),
+ )
+
class testobj:
def __init__(self):
self.read = False
self.write = False
self.closed = False
self.expt = False
+ self.error_handled = False
def handle_read_event(self):
self.read = True
@@ -138,54 +150,25 @@ class HelperFunctionTests(unittest.TestCase):
def handle_error(self):
self.error_handled = True
- for flag in (select.POLLIN, select.POLLPRI):
+ for flag, expectedattr in expected:
tobj = testobj()
- self.assertEqual(tobj.read, False)
+ self.assertEqual(getattr(tobj, expectedattr), False)
asyncore.readwrite(tobj, flag)
- self.assertEqual(tobj.read, True)
- # check that ExitNow exceptions in the object handler method
- # bubbles all the way up through asyncore readwrite call
- tr1 = exitingdummy()
- self.assertRaises(asyncore.ExitNow, asyncore.readwrite, tr1, flag)
-
- # check that an exception other than ExitNow in the object handler
- # method causes the handle_error method to get called
- tr2 = crashingdummy()
- asyncore.readwrite(tr2, flag)
- self.assertEqual(tr2.error_handled, True)
-
- tobj = testobj()
- self.assertEqual(tobj.write, False)
- asyncore.readwrite(tobj, select.POLLOUT)
- self.assertEqual(tobj.write, True)
-
- # check that ExitNow exceptions in the object handler method
- # bubbles all the way up through asyncore readwrite call
- tr1 = exitingdummy()
- self.assertRaises(asyncore.ExitNow, asyncore.readwrite, tr1,
- select.POLLOUT)
-
- # check that an exception other than ExitNow in the object handler
- # method causes the handle_error method to get called
- tr2 = crashingdummy()
- asyncore.readwrite(tr2, select.POLLOUT)
- self.assertEqual(tr2.error_handled, True)
-
- for flag in (select.POLLERR, select.POLLHUP, select.POLLNVAL):
- tobj = testobj()
- self.assertEqual((tobj.expt, tobj.closed)[flag == select.POLLHUP], False)
- asyncore.readwrite(tobj, flag)
- self.assertEqual((tobj.expt, tobj.closed)[flag == select.POLLHUP], True)
+ # Only the attribute modified by the routine we expect to be
+ # called should be True.
+ for attr in attributes:
+ self.assertEqual(getattr(tobj, attr), attr==expectedattr)
# check that ExitNow exceptions in the object handler method
- # bubbles all the way up through asyncore readwrite calls
+ # bubbles all the way up through asyncore readwrite call
tr1 = exitingdummy()
self.assertRaises(asyncore.ExitNow, asyncore.readwrite, tr1, flag)
# check that an exception other than ExitNow in the object handler
# method causes the handle_error method to get called
tr2 = crashingdummy()
+ self.assertEqual(tr2.error_handled, False)
asyncore.readwrite(tr2, flag)
self.assertEqual(tr2.error_handled, True)
@@ -299,6 +282,7 @@ class DispatcherTests(unittest.TestCase):
def test_unhandled(self):
d = asyncore.dispatcher()
+ d.ignore_log_types = ()
# capture output of dispatcher.log_info() (to stdout via print)
fp = StringIO()
@@ -314,7 +298,7 @@ class DispatcherTests(unittest.TestCase):
sys.stdout = stdout
lines = fp.getvalue().splitlines()
- expected = ['warning: unhandled exception',
+ expected = ['warning: unhandled incoming priority event',
'warning: unhandled read event',
'warning: unhandled write event',
'warning: unhandled connect event',