[tor-commits] [stem/master] Add version requirement tests for Controller.add_event_listener
atagar at torproject.org
atagar at torproject.org
Sun Dec 9 21:57:54 UTC 2012
commit f5e2d127581a487f9cba7edf86943c0f78445180
Author: Sean Robinson <seankrobinson at gmail.com>
Date: Sat Dec 8 18:29:54 2012 -0700
Add version requirement tests for Controller.add_event_listener
Signed-off-by: Sean Robinson <seankrobinson at gmail.com>
---
test/unit/control/controller.py | 30 ++++++++++++++++++++++++++++--
1 files changed, 28 insertions(+), 2 deletions(-)
diff --git a/test/unit/control/controller.py b/test/unit/control/controller.py
index e25fbe0..a9d31d1 100644
--- a/test/unit/control/controller.py
+++ b/test/unit/control/controller.py
@@ -5,10 +5,20 @@ integ tests, but a few bits lend themselves to unit testing.
import unittest
-from stem import ProtocolError
-from stem.control import _parse_circ_path
+from stem import InvalidRequest, ProtocolError
+from stem.control import _parse_circ_path, Controller, EventType
+import stem.socket
+import stem.version
+import test.mocking as mocking
class TestControl(unittest.TestCase):
+ def setUp(self):
+ socket = stem.socket.ControlSocket()
+ self.controller = Controller(socket)
+
+ def tearDown(self):
+ mocking.revert_mocking()
+
def test_parse_circ_path(self):
"""
Exercises the _parse_circ_path() helper function.
@@ -47,4 +57,20 @@ class TestControl(unittest.TestCase):
for test_input in malformed_inputs:
self.assertRaises(ProtocolError, _parse_circ_path, test_input)
+
+ def test_event_listening(self):
+ """
+ Exercises the add_event_listener and remove_event_listener methods.
+ """
+
+ # set up for failure to create any events
+ mocking.mock_method(Controller, "get_version", mocking.return_value(stem.version.Version('0.1.0.14')))
+ self.assertRaises(InvalidRequest, self.controller.add_event_listener, lambda x: x, EventType.BW)
+
+ # set up to only fail newer events
+ mocking.mock_method(Controller, "get_version", mocking.return_value(stem.version.Version('0.2.0.35')))
+ # EventType.BW is one of the earliest events
+ self.assertIsNone(self.controller.add_event_listener(lambda x: x, EventType.BW))
+ # EventType.SIGNAL was added in tor version 0.2.3.1-alpha
+ self.assertRaises(InvalidRequest, self.controller.add_event_listener, lambda x: x, EventType.SIGNAL)
More information about the tor-commits
mailing list