summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_asyncore.py
diff options
context:
space:
mode:
authorR. David Murray <rdmurray@bitdance.com>2009-04-11 17:52:56 (GMT)
committerR. David Murray <rdmurray@bitdance.com>2009-04-11 17:52:56 (GMT)
commit5331d4b4de59cca76a9d61f2e66851cfa70bba00 (patch)
tree549338b131e8b9baf60628aecbd232a6e4fc3379 /Lib/test/test_asyncore.py
parentb2faddb6106c3b53f509ac1d7775abc337c5209b (diff)
downloadcpython-5331d4b4de59cca76a9d61f2e66851cfa70bba00.zip
cpython-5331d4b4de59cca76a9d61f2e66851cfa70bba00.tar.gz
cpython-5331d4b4de59cca76a9d61f2e66851cfa70bba00.tar.bz2
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.py57
1 files changed, 20 insertions, 37 deletions
diff --git a/Lib/test/test_asyncore.py b/Lib/test/test_asyncore.py
index 13b39e1..e1ccb5a 100644
--- a/Lib/test/test_asyncore.py
+++ b/Lib/test/test_asyncore.py
@@ -115,12 +115,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
@@ -137,54 +149,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)