summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_asynchat.py
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2014-07-24 16:49:36 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2014-07-24 16:49:36 (GMT)
commit45cff66cf63593695ff5324d3765d8a1a1125adf (patch)
tree57bd2130c942c9735e0803de92defbccff384794 /Lib/test/test_asynchat.py
parent992019c0061d62ccb5e0715675ddf3aa2d1b6478 (diff)
downloadcpython-45cff66cf63593695ff5324d3765d8a1a1125adf.zip
cpython-45cff66cf63593695ff5324d3765d8a1a1125adf.tar.gz
cpython-45cff66cf63593695ff5324d3765d8a1a1125adf.tar.bz2
Issue #16133: The asynchat.async_chat.handle_read() method now ignores
BlockingIOError exceptions. Initial patch written by Xavier de Gaye. Document also in asyncore documentation that recv() may raise BlockingIOError.
Diffstat (limited to 'Lib/test/test_asynchat.py')
-rw-r--r--Lib/test/test_asynchat.py17
1 files changed, 17 insertions, 0 deletions
diff --git a/Lib/test/test_asynchat.py b/Lib/test/test_asynchat.py
index 84867ec..2dc9d0c 100644
--- a/Lib/test/test_asynchat.py
+++ b/Lib/test/test_asynchat.py
@@ -7,10 +7,12 @@ thread = support.import_module('_thread')
import asynchat
import asyncore
+import errno
import socket
import sys
import time
import unittest
+import unittest.mock
try:
import threading
except ImportError:
@@ -273,6 +275,21 @@ class TestAsynchat_WithPoll(TestAsynchat):
usepoll = True
+class TestAsynchatMocked(unittest.TestCase):
+ def test_blockingioerror(self):
+ # Issue #16133: handle_read() must ignore BlockingIOError
+ sock = unittest.mock.Mock()
+ sock.recv.side_effect = BlockingIOError(errno.EAGAIN)
+
+ dispatcher = asynchat.async_chat()
+ dispatcher.set_socket(sock)
+ self.addCleanup(dispatcher.del_channel)
+
+ with unittest.mock.patch.object(dispatcher, 'handle_error') as error:
+ dispatcher.handle_read()
+ self.assertFalse(error.called)
+
+
class TestHelperFunctions(unittest.TestCase):
def test_find_prefix_at_end(self):
self.assertEqual(asynchat.find_prefix_at_end("qwerty\r", "\r\n"), 1)