[tor-commits] [stem/master] Test queue_listener example
atagar at torproject.org
atagar at torproject.org
Fri Oct 2 23:16:05 UTC 2020
commit 437ea486834ae9e320675ec0c80aa4ecf293fcc6
Author: Damian Johnson <atagar at torproject.org>
Date: Tue Sep 29 18:39:46 2020 -0700
Test queue_listener example
---
test/unit/examples.py | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)
diff --git a/test/unit/examples.py b/test/unit/examples.py
index 0b4d7082..6e32a0f2 100644
--- a/test/unit/examples.py
+++ b/test/unit/examples.py
@@ -772,8 +772,18 @@ class TestExamples(unittest.TestCase):
self.assertEqual(EXPECTED_PERSISTING_A_CONSENSUS, stdout_mock.getvalue())
- def test_queue_listener(self):
- pass
+ @patch('stem.control.Controller.from_port', spec = Controller)
+ @patch('sys.stdout', new_callable = io.StringIO)
+ def test_queue_listener(self, stdout_mock, from_port_mock):
+ bw_event = ControlMessage.from_str('650 BW 15 25', 'EVENT', normalize = True)
+
+ controller = from_port_mock().__enter__()
+ controller.add_event_listener.side_effect = lambda handler, event_type: handler(bw_event)
+
+ with patch('time.time', Mock(side_effect = [1, 1, 10])):
+ import queue_listener
+
+ self.assertEqual('I got a BW event for 15 bytes downloaded and 25 bytes uploaded\n', stdout_mock.getvalue())
def test_read_with_parse_file(self):
pass
More information about the tor-commits
mailing list