diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2014-11-20 13:16:31 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2014-11-20 13:16:31 (GMT) |
commit | 662fd5f68ef1a3bf7f4f7bbb4e50a876216424eb (patch) | |
tree | f435bf8369e007243faa453565d226e3df643572 /Lib/test/test_asyncio/test_futures.py | |
parent | abde2c1d2511367c6199d6bb21ec63cecb7ac6b8 (diff) | |
download | cpython-662fd5f68ef1a3bf7f4f7bbb4e50a876216424eb.zip cpython-662fd5f68ef1a3bf7f4f7bbb4e50a876216424eb.tar.gz cpython-662fd5f68ef1a3bf7f4f7bbb4e50a876216424eb.tar.bz2 |
asyncio: Fix formatting of the "Future exception was never retrieved" in
release mode
Diffstat (limited to 'Lib/test/test_asyncio/test_futures.py')
-rw-r--r-- | Lib/test/test_asyncio/test_futures.py | 65 |
1 files changed, 42 insertions, 23 deletions
diff --git a/Lib/test/test_asyncio/test_futures.py b/Lib/test/test_asyncio/test_futures.py index e5002bc..371d351 100644 --- a/Lib/test/test_asyncio/test_futures.py +++ b/Lib/test/test_asyncio/test_futures.py @@ -307,8 +307,8 @@ class FutureTests(test_utils.TestCase): 'test_future_source_traceback')) @mock.patch('asyncio.base_events.logger') - def test_future_exception_never_retrieved(self, m_log): - self.loop.set_debug(True) + def check_future_exception_never_retrieved(self, debug, m_log): + self.loop.set_debug(debug) def memory_error(): try: @@ -318,40 +318,59 @@ class FutureTests(test_utils.TestCase): exc = memory_error() future = asyncio.Future(loop=self.loop) - source_traceback = future._source_traceback + if debug: + source_traceback = future._source_traceback future.set_exception(exc) future = None test_utils.run_briefly(self.loop) support.gc_collect() if sys.version_info >= (3, 4): - frame = source_traceback[-1] - regex = (r'^Future exception was never retrieved\n' - r'future: <Future finished exception=MemoryError\(\) created at {filename}:{lineno}>\n' - r'source_traceback: Object created at \(most recent call last\):\n' - r' File' - r'.*\n' - r' File "{filename}", line {lineno}, in test_future_exception_never_retrieved\n' - r' future = asyncio\.Future\(loop=self\.loop\)$' - ).format(filename=re.escape(frame[0]), lineno=frame[1]) + if debug: + frame = source_traceback[-1] + regex = (r'^Future exception was never retrieved\n' + r'future: <Future finished exception=MemoryError\(\) created at {filename}:{lineno}>\n' + r'source_traceback: Object created at \(most recent call last\):\n' + r' File' + r'.*\n' + r' File "{filename}", line {lineno}, in check_future_exception_never_retrieved\n' + r' future = asyncio\.Future\(loop=self\.loop\)$' + ).format(filename=re.escape(frame[0]), lineno=frame[1]) + else: + regex = (r'^Future exception was never retrieved\n' + r'future: <Future finished exception=MemoryError\(\)>$' + ) exc_info = (type(exc), exc, exc.__traceback__) m_log.error.assert_called_once_with(mock.ANY, exc_info=exc_info) else: - frame = source_traceback[-1] - regex = (r'^Future/Task exception was never retrieved\n' - r'Future/Task created at \(most recent call last\):\n' - r' File' - r'.*\n' - r' File "{filename}", line {lineno}, in test_future_exception_never_retrieved\n' - r' future = asyncio\.Future\(loop=self\.loop\)\n' - r'Traceback \(most recent call last\):\n' - r'.*\n' - r'MemoryError$' - ).format(filename=re.escape(frame[0]), lineno=frame[1]) + if debug: + frame = source_traceback[-1] + regex = (r'^Future/Task exception was never retrieved\n' + r'Future/Task created at \(most recent call last\):\n' + r' File' + r'.*\n' + r' File "{filename}", line {lineno}, in check_future_exception_never_retrieved\n' + r' future = asyncio\.Future\(loop=self\.loop\)\n' + r'Traceback \(most recent call last\):\n' + r'.*\n' + r'MemoryError$' + ).format(filename=re.escape(frame[0]), lineno=frame[1]) + else: + regex = (r'^Future/Task exception was never retrieved\n' + r'Traceback \(most recent call last\):\n' + r'.*\n' + r'MemoryError$' + ) m_log.error.assert_called_once_with(mock.ANY, exc_info=False) message = m_log.error.call_args[0][0] self.assertRegex(message, re.compile(regex, re.DOTALL)) + def test_future_exception_never_retrieved(self): + self.check_future_exception_never_retrieved(False) + + def test_future_exception_never_retrieved_debug(self): + self.check_future_exception_never_retrieved(True) + def test_set_result_unless_cancelled(self): fut = asyncio.Future(loop=self.loop) fut.cancel() |