[tor-commits] [stem/master] Fixing interpreter unit test
atagar at torproject.org
atagar at torproject.org
Mon May 26 22:30:09 UTC 2014
commit aa0622d13be3e274200eb3fecfcd470528d1695a
Author: Damian Johnson <atagar at torproject.org>
Date: Mon May 26 14:18:26 2014 -0700
Fixing interpreter unit test
Revising our test for /info to account for the recent changes.
---
docs/tutorials/down_the_rabbit_hole.rst | 2 +-
stem/interpreter/__init__.py | 2 +-
test/unit/interpreter/commands.py | 15 +++++++--------
3 files changed, 9 insertions(+), 10 deletions(-)
diff --git a/docs/tutorials/down_the_rabbit_hole.rst b/docs/tutorials/down_the_rabbit_hole.rst
index a2193e3..0649197 100644
--- a/docs/tutorials/down_the_rabbit_hole.rst
+++ b/docs/tutorials/down_the_rabbit_hole.rst
@@ -101,7 +101,7 @@ provides a quick dump of the events we've received thus far...
.. image:: /_static/prompt/events_command.png
You can list events of just a certain type by saying which (for instance
-**/events BW**). More useful though is your **events()** function, which
+**/events BW**). More useful though is the **events()** function, which
provides a list of :class:`~stem.response.events.Event` instances we've
received...
diff --git a/stem/interpreter/__init__.py b/stem/interpreter/__init__.py
index 6d6fea1..31b119f 100644
--- a/stem/interpreter/__init__.py
+++ b/stem/interpreter/__init__.py
@@ -18,7 +18,7 @@ import stem.util.conf
import stem.util.system
import stem.util.term
-from stem.util.term import RESET, Attr, Color, format
+from stem.util.term import Attr, Color, format
PROMPT = format('>>> ', Color.GREEN, Attr.BOLD, Attr.READLINE_ESCAPE)
diff --git a/test/unit/interpreter/commands.py b/test/unit/interpreter/commands.py
index 9afab59..2728deb 100644
--- a/test/unit/interpreter/commands.py
+++ b/test/unit/interpreter/commands.py
@@ -12,9 +12,9 @@ from test.unit.interpreter import CONTROLLER
try:
# added in python 3.3
- from unittest.mock import Mock
+ from unittest.mock import Mock, patch
except ImportError:
- from mock import Mock
+ from mock import Mock, patch
EXPECTED_EVENTS_RESPONSE = """\
\x1b[34mBW 15 25\x1b[0m
@@ -24,12 +24,10 @@ EXPECTED_EVENTS_RESPONSE = """\
EXPECTED_INFO_RESPONSE = """\
moria1 (9695DFC35FFEB861329B9F1AB04C46397020CE31)
-\x1b[34;1maddress: \x1b[0m128.31.0.34:9101 (us)
-\x1b[34;1mpublished: \x1b[0m05:52:05 05/05/2014
-\x1b[34;1mos: \x1b[0mLinux
-\x1b[34;1mversion: \x1b[0m0.2.5.3-alpha-dev
+\x1b[34;1maddress: \x1b[0m128.31.0.34:9101 (moria.csail.mit.edu)
+\x1b[34;1mtor version: \x1b[0m0.2.5.4-alpha-dev
\x1b[34;1mflags: \x1b[0mAuthority, Fast, Guard, HSDir, Named, Running, Stable, V2Dir, Valid
-\x1b[34;1mexit policy: \x1b[0mreject 1-65535
+\x1b[34;1mexit policy: \x1b[0mreject *:*
\x1b[34;1mcontact: \x1b[0m1024D/28988BF5 arma mit edu
"""
@@ -133,6 +131,7 @@ class TestInterpretorCommands(unittest.TestCase):
self.assertEqual(EXPECTED_EVENTS_RESPONSE, interpreter.run_command('/events'))
+ @patch('socket.gethostbyaddr', Mock(return_value = ['moria.csail.mit.edu']))
def test_info(self):
controller, server_desc, ns_desc = Mock(), Mock(), Mock()
@@ -156,7 +155,7 @@ class TestInterpretorCommands(unittest.TestCase):
server_desc.contact = '1024D/28988BF5 arma mit edu'
interpreter = ControlInterpretor(controller)
- self.assertEqual(EXPECTED_INFO_RESPONSE, interpreter.run_command('/info ' + FINGERPRINT))
+ self.assertTrue(interpreter.run_command('/info ' + FINGERPRINT).startswith(EXPECTED_INFO_RESPONSE))
def test_unrecognized_interpreter_command(self):
interpreter = ControlInterpretor(CONTROLLER)
More information about the tor-commits
mailing list