summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2014-06-17 23:22:15 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2014-06-17 23:22:15 (GMT)
commitd6f02fc649d2e248f2e7b418771371db2b6637a2 (patch)
tree1d9959fa6d6b264665bb959c7f5db5ca476cfee7 /Lib
parent8d3e02ef5a452b59fc909bf45d1d18bfd916c596 (diff)
downloadcpython-d6f02fc649d2e248f2e7b418771371db2b6637a2.zip
cpython-d6f02fc649d2e248f2e7b418771371db2b6637a2.tar.gz
cpython-d6f02fc649d2e248f2e7b418771371db2b6637a2.tar.bz2
asyncio: Refactor test__run_once_logging() to not rely on the exact number of
calls to time.monotonic(). Use a "fast select" and a "slow select" instead.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_asyncio/test_base_events.py29
1 files changed, 11 insertions, 18 deletions
diff --git a/Lib/test/test_asyncio/test_base_events.py b/Lib/test/test_asyncio/test_base_events.py
index 1611a11..fb28b87 100644
--- a/Lib/test/test_asyncio/test_base_events.py
+++ b/Lib/test/test_asyncio/test_base_events.py
@@ -240,30 +240,23 @@ class BaseEventLoopTests(unittest.TestCase):
self.loop.set_debug(False)
self.assertFalse(self.loop.get_debug())
- @mock.patch('asyncio.base_events.time')
@mock.patch('asyncio.base_events.logger')
- def test__run_once_logging(self, m_logger, m_time):
- # Log to INFO level if timeout > 1.0 sec.
- idx = -1
- data = [10.0, 10.0, 12.0, 13.0]
-
- def monotonic():
- nonlocal data, idx
- idx += 1
- return data[idx]
+ def test__run_once_logging(self, m_logger):
+ def slow_select(timeout):
+ time.sleep(1.0)
+ return []
- m_time.monotonic = monotonic
-
- self.loop._scheduled.append(
- asyncio.TimerHandle(11.0, lambda: True, (), self.loop))
+ # Log to INFO level if timeout > 1.0 sec.
+ self.loop._selector.select = slow_select
self.loop._process_events = mock.Mock()
self.loop._run_once()
self.assertEqual(logging.INFO, m_logger.log.call_args[0][0])
- idx = -1
- data = [10.0, 10.0, 10.3, 13.0]
- self.loop._scheduled = [asyncio.TimerHandle(11.0, lambda: True, (),
- self.loop)]
+ def fast_select(timeout):
+ time.sleep(0.001)
+ return []
+
+ self.loop._selector.select = fast_select
self.loop._run_once()
self.assertEqual(logging.DEBUG, m_logger.log.call_args[0][0])