[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [stem/master] Ensure _emit_event() helper mocks time.time()
commit 94837b90d058a16e56b091a25889c03c8746c18d
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date: Wed Oct 24 13:15:28 2018 -0700
Ensure _emit_event() helper mocks time.time()
Nothing actually changed. Just moving our time.time() mocks into the
_emit_event() helper since that mock's always needed for tests that
send events.
---
test/unit/control/controller.py | 32 +++++++++++++++-----------------
1 file changed, 15 insertions(+), 17 deletions(-)
diff --git a/test/unit/control/controller.py b/test/unit/control/controller.py
index ed00385d..ed72fbe8 100644
--- a/test/unit/control/controller.py
+++ b/test/unit/control/controller.py
@@ -669,7 +669,6 @@ class TestControl(unittest.TestCase):
self.assertRaises(InvalidRequest, self.controller.add_event_listener, Mock(), EventType.SIGNAL)
- @patch('time.time', Mock(return_value = TEST_TIMESTAMP))
def test_events_get_received(self):
"""
Trigger an event, checking that our listeners get notified.
@@ -683,7 +682,6 @@ class TestControl(unittest.TestCase):
self._emit_event(BW_EVENT)
self.bw_listener.assert_called_once_with(BW_EVENT)
- @patch('time.time', Mock(return_value = TEST_TIMESTAMP))
def test_event_listing_with_error(self):
"""
Raise an exception in an event listener to confirm it doesn't break our
@@ -700,7 +698,6 @@ class TestControl(unittest.TestCase):
self._emit_event(BW_EVENT)
self.bw_listener.assert_called_once_with(BW_EVENT)
- @patch('time.time', Mock(return_value = TEST_TIMESTAMP))
def test_event_listing_with_malformed_event(self):
"""
Attempt to parse a malformed event emitted from Tor. It's important this
@@ -857,17 +854,18 @@ class TestControl(unittest.TestCase):
# processed asynchronously, so the only way to endsure it's done
# with its work is to join on the thread.
- with patch('stem.control.Controller.is_alive') as is_alive_mock:
- is_alive_mock.return_value = True
- self.controller._launch_threads()
-
- try:
- # Converting an event back into an uncast ControlMessage, then feeding it
- # into our controller's event queue.
-
- uncast_event = ControlMessage.from_str(event.raw_content())
- self.controller._event_queue.put(uncast_event)
- self.controller._event_notice.set()
- finally:
- is_alive_mock.return_value = False
- self.controller._close()
+ with patch('time.time', Mock(return_value = TEST_TIMESTAMP)):
+ with patch('stem.control.Controller.is_alive') as is_alive_mock:
+ is_alive_mock.return_value = True
+ self.controller._launch_threads()
+
+ try:
+ # Converting an event back into an uncast ControlMessage, then feeding it
+ # into our controller's event queue.
+
+ uncast_event = ControlMessage.from_str(event.raw_content())
+ self.controller._event_queue.put(uncast_event)
+ self.controller._event_notice.set()
+ finally:
+ is_alive_mock.return_value = False
+ self.controller._close()
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits