diff options
author | Yury Selivanov <yselivanov@sprymix.com> | 2014-02-18 23:02:19 (GMT) |
---|---|---|
committer | Yury Selivanov <yselivanov@sprymix.com> | 2014-02-18 23:02:19 (GMT) |
commit | ff827f08ac9201f56b14cb19ccb9d511434c858b (patch) | |
tree | 75a1b4b19c5eb74fa2fbf43d8df438b7c42b6e4d /Lib/asyncio/test_utils.py | |
parent | 065efc3072c244ba34ce521ba0edaa4168fa8953 (diff) | |
download | cpython-ff827f08ac9201f56b14cb19ccb9d511434c858b.zip cpython-ff827f08ac9201f56b14cb19ccb9d511434c858b.tar.gz cpython-ff827f08ac9201f56b14cb19ccb9d511434c858b.tar.bz2 |
asyncio: New error handling API. Issue #20681.
Diffstat (limited to 'Lib/asyncio/test_utils.py')
-rw-r--r-- | Lib/asyncio/test_utils.py | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/Lib/asyncio/test_utils.py b/Lib/asyncio/test_utils.py index de2916b..28e5243 100644 --- a/Lib/asyncio/test_utils.py +++ b/Lib/asyncio/test_utils.py @@ -4,6 +4,7 @@ import collections import contextlib import io import os +import re import socket import socketserver import sys @@ -301,7 +302,7 @@ class TestLoop(base_events.BaseEventLoop): raise AssertionError("Time generator is not finished") def add_reader(self, fd, callback, *args): - self.readers[fd] = events.Handle(callback, args) + self.readers[fd] = events.Handle(callback, args, self) def remove_reader(self, fd): self.remove_reader_count[fd] += 1 @@ -320,7 +321,7 @@ class TestLoop(base_events.BaseEventLoop): handle._args, args) def add_writer(self, fd, callback, *args): - self.writers[fd] = events.Handle(callback, args) + self.writers[fd] = events.Handle(callback, args, self) def remove_writer(self, fd): self.remove_writer_count[fd] += 1 @@ -362,3 +363,16 @@ class TestLoop(base_events.BaseEventLoop): def MockCallback(**kwargs): return unittest.mock.Mock(spec=['__call__'], **kwargs) + + +class MockPattern(str): + """A regex based str with a fuzzy __eq__. + + Use this helper with 'mock.assert_called_with', or anywhere + where a regexp comparison between strings is needed. + + For instance: + mock_call.assert_called_with(MockPattern('spam.*ham')) + """ + def __eq__(self, other): + return bool(re.search(str(self), other, re.S)) |