[tor-commits] [stem/master] Integration test for general PROTOCOLINFO parsing
atagar at torproject.org
atagar at torproject.org
Sun Nov 20 23:57:22 UTC 2011
commit 7b302e2eac72d9c3b4f09b705fd6c3adcb755f84
Author: Damian Johnson <atagar at torproject.org>
Date: Sat Nov 19 23:58:26 2011 -0800
Integration test for general PROTOCOLINFO parsing
Integ test for parsing a PROTOCOLINFO reply from our general integraion test
instance. We'll need a separate target for testing multiple connection methods
(password auth, cookie auth, and control socket).
This also includes a fix for the Version class (equality checks with
non-Version instaces would raise an exception - didn't expect __cmp__ to be
used for that...).
---
run_tests.py | 2 +
stem/types.py | 2 +-
test/integ/connection/__init__.py | 6 +++
test/integ/connection/protocolinfo_response.py | 50 ++++++++++++++++++++++++
4 files changed, 59 insertions(+), 1 deletions(-)
diff --git a/run_tests.py b/run_tests.py
index 6f67d03..05aa848 100755
--- a/run_tests.py
+++ b/run_tests.py
@@ -21,6 +21,7 @@ import test.unit.util.system
import test.integ.types.control_message
import test.integ.util.conf
import test.integ.util.system
+import test.integ.connection.protocolinfo_response
import stem.util.enum
import stem.util.term as term
@@ -39,6 +40,7 @@ UNIT_TESTS = (("stem.types.ControlMessage", test.unit.types.control_message.Test
)
INTEG_TESTS = (("stem.types.ControlMessage", test.integ.types.control_message.TestControlMessage),
+ ("stem.connection.ProtocolInfoResponse", test.integ.connection.protocolinfo_response.TestProtocolInfoResponse),
("stem.util.conf", test.integ.util.conf.TestConf),
("stem.util.system", test.integ.util.system.TestSystem),
)
diff --git a/stem/types.py b/stem/types.py
index 78e2fd9..45b040f 100644
--- a/stem/types.py
+++ b/stem/types.py
@@ -521,7 +521,7 @@ class Version:
"""
if not isinstance(other, Version):
- raise ValueError("types.Version can only be compared with other Version instances")
+ return 1 # this is also used for equality checks
for attr in ("major", "minor", "micro", "patch"):
my_version = max(0, self.__dict__[attr])
diff --git a/test/integ/connection/__init__.py b/test/integ/connection/__init__.py
new file mode 100644
index 0000000..6a71f2a
--- /dev/null
+++ b/test/integ/connection/__init__.py
@@ -0,0 +1,6 @@
+"""
+Integration tests for stem.connection.
+"""
+
+__all__ = ["protocolinfo_response"]
+
diff --git a/test/integ/connection/protocolinfo_response.py b/test/integ/connection/protocolinfo_response.py
new file mode 100644
index 0000000..67c0582
--- /dev/null
+++ b/test/integ/connection/protocolinfo_response.py
@@ -0,0 +1,50 @@
+"""
+Integration tests for the stem.connections.ProtocolInfoResponse class.
+"""
+
+import socket
+import unittest
+
+import test.runner
+import stem.types
+import stem.connection
+
+class TestProtocolInfoResponse(unittest.TestCase):
+ """
+ Processes a ProtocolInfo query for a variety of setups.
+ """
+
+ def testProtocolInfoResponse(self):
+ """
+ Makes a PROTOCOLINFO query and processes the response for our control
+ connection.
+ """
+
+ runner = test.runner.get_runner()
+
+ control_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+ control_socket.connect(("127.0.0.1", runner.get_control_port()))
+ control_socket_file = control_socket.makefile()
+
+ control_socket_file.write("PROTOCOLINFO\r\n")
+ control_socket_file.flush()
+
+ protocolinfo_response = stem.types.read_message(control_socket_file)
+ stem.connection.ProtocolInfoResponse.convert(protocolinfo_response)
+
+ # according to the control spec the following _could_ differ or be
+ # undefined but if that actually happens then it's gonna make people sad
+
+ self.assertEqual(1, protocolinfo_response.protocol_version)
+ self.assertNotEqual(None, protocolinfo_response.tor_version)
+ self.assertNotEqual(None, protocolinfo_response.auth_methods)
+
+ # TODO: The following is for the default integ test configuration. We
+ # should run tests that exercise all of tor's startup configs
+ # (password/cookie auth and control sockets)
+
+ self.assertEqual((stem.connection.AuthMethod.NONE,), protocolinfo_response.auth_methods)
+ self.assertEqual((), protocolinfo_response.unknown_auth_methods)
+ self.assertEqual(None, protocolinfo_response.cookie_file)
+ self.assertEqual(None, protocolinfo_response.socket)
+
More information about the tor-commits
mailing list