[tor-commits] [stem/master] Help and event ControlInterpretor unit tests
atagar at torproject.org
atagar at torproject.org
Tue May 6 01:21:13 UTC 2014
commit 1ee5d21f16921e2679239839899bacc0d21ccad8
Author: Damian Johnson <atagar at torproject.org>
Date: Sun May 4 15:20:45 2014 -0700
Help and event ControlInterpretor unit tests
First couple unit tests for the ControlInterpretor class, covering '/help' and
'/events'.
---
test/settings.cfg | 1 +
test/unit/interpretor/__init__.py | 1 +
test/unit/interpretor/commands.py | 45 +++++++++++++++++++++++++++++++++++++
3 files changed, 47 insertions(+)
diff --git a/test/settings.cfg b/test/settings.cfg
index 9ecbcfc..79852b0 100644
--- a/test/settings.cfg
+++ b/test/settings.cfg
@@ -186,6 +186,7 @@ test.unit_tests
|test.unit.interpretor.arguments.TestArgumentParsing
|test.unit.interpretor.autocomplete.TestAutocompletion
|test.unit.interpretor.help.TestHelpResponses
+|test.unit.interpretor.commands.TestInterpretorCommands
|test.unit.doctest.TestDocumentation
test.integ_tests
diff --git a/test/unit/interpretor/__init__.py b/test/unit/interpretor/__init__.py
index 8063dfc..702cb92 100644
--- a/test/unit/interpretor/__init__.py
+++ b/test/unit/interpretor/__init__.py
@@ -5,6 +5,7 @@ Unit tests for the stem's interpretor prompt.
__all__ = [
"arguments",
"autocomplete",
+ "commands",
"help",
]
diff --git a/test/unit/interpretor/commands.py b/test/unit/interpretor/commands.py
new file mode 100644
index 0000000..db0a53b
--- /dev/null
+++ b/test/unit/interpretor/commands.py
@@ -0,0 +1,45 @@
+import unittest
+
+import stem.response
+
+from stem.interpretor.commands import ControlInterpretor
+
+from test import mocking
+from test.unit.interpretor import CONTROLLER
+
+EXPECTED_EVENTS_RESPONSE = """\
+\x1b[34mBW 15 25\x1b[0m
+\x1b[34mBW 758 570\x1b[0m
+\x1b[34mDEBUG connection_edge_process_relay_cell(): Got an extended cell! Yay.\x1b[0m
+"""
+
+
+class TestInterpretorCommands(unittest.TestCase):
+ def test_help(self):
+ interpretor = ControlInterpretor(CONTROLLER)
+
+ self.assertTrue('Interpretor commands include:' in interpretor.run_command('/help'))
+ self.assertTrue('Queries the tor process for information.' in interpretor.run_command('/help GETINFO'))
+ self.assertTrue('Queries the tor process for information.' in interpretor.run_command('/help GETINFO version'))
+
+ def test_events(self):
+ interpretor = ControlInterpretor(CONTROLLER)
+
+ # no received events
+
+ self.assertEqual('\n', interpretor.run_command('/events'))
+
+ # with enqueued events
+
+ event_contents = (
+ '650 BW 15 25',
+ '650 BW 758 570',
+ '650 DEBUG connection_edge_process_relay_cell(): Got an extended cell! Yay.',
+ )
+
+ for content in event_contents:
+ event = mocking.get_message(content)
+ stem.response.convert('EVENT', event)
+ interpretor.register_event(event)
+
+ self.assertEqual(EXPECTED_EVENTS_RESPONSE, interpretor.run_command('/events'))
More information about the tor-commits
mailing list