[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [stem/master] Integ tests for stem.version



commit a08c09a21743225181569a9ba08b3b15a7c584e2
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date:   Mon Jan 2 16:27:48 2012 -0800

    Integ tests for stem.version
    
    I didn't have any integ tests for versions? Seriously? *sigh*
    
    Adding some basic verification tests that we can handle the version of our
    system and test instances. Earlier boerni was running into a bug where another
    integ tests inadvertantly failed due to an uncaught exception from
    get_system_tor_version(). It was inappropriate for that test to fail (it wasn't
    testing versions) but we should have some test for the function so this is it.
---
 run_tests.py                          |   31 ++++++++++-------
 test/integ/connection/protocolinfo.py |    1 +
 test/integ/version.py                 |   59 +++++++++++++++++++++++++++++++++
 3 files changed, 79 insertions(+), 12 deletions(-)

diff --git a/run_tests.py b/run_tests.py
index 9bd0735..280b05e 100755
--- a/run_tests.py
+++ b/run_tests.py
@@ -14,19 +14,20 @@ import StringIO
 
 import test.output
 import test.runner
-import test.unit.version
-import test.unit.socket.control_message
-import test.unit.socket.control_line
 import test.unit.connection.authentication
 import test.unit.connection.protocolinfo
+import test.unit.socket.control_line
+import test.unit.socket.control_message
 import test.unit.util.enum
 import test.unit.util.system
-import test.integ.socket.control_message
-import test.integ.util.conf
-import test.integ.util.system
+import test.unit.version
 import test.integ.connection.authentication
 import test.integ.connection.connect
 import test.integ.connection.protocolinfo
+import test.integ.socket.control_message
+import test.integ.util.conf
+import test.integ.util.system
+import test.integ.version
 
 import stem.util.enum
 import stem.util.log as log
@@ -36,23 +37,29 @@ OPT = "uic:t:l:h"
 OPT_EXPANDED = ["unit", "integ", "config=", "targets=", "log=", "help"]
 DIVIDER = "=" * 70
 
+# Tests are ordered by the dependencies so the lowest level tests come first.
+# This is because a problem in say, controller message parsing, will cause all
+# higher level tests to fail too. Hence we want the test that most narrowly
+# exhibits problems to come first.
+
 UNIT_TESTS = (
+  test.unit.util.enum.TestEnum,
+  test.unit.util.system.TestSystem,
+  test.unit.version.TestVersion,
   test.unit.socket.control_message.TestControlMessage,
   test.unit.socket.control_line.TestControlLine,
-  test.unit.version.TestVersion,
   test.unit.connection.authentication.TestAuthenticate,
   test.unit.connection.protocolinfo.TestProtocolInfoResponse,
-  test.unit.util.enum.TestEnum,
-  test.unit.util.system.TestSystem,
 )
 
 INTEG_TESTS = (
+  test.integ.util.conf.TestConf,
+  test.integ.util.system.TestSystem,
+  test.integ.version.TestVersion,
   test.integ.socket.control_message.TestControlMessage,
+  test.integ.connection.protocolinfo.TestProtocolInfo,
   test.integ.connection.authentication.TestAuthenticate,
   test.integ.connection.connect.TestConnect,
-  test.integ.connection.protocolinfo.TestProtocolInfo,
-  test.integ.util.conf.TestConf,
-  test.integ.util.system.TestSystem,
 )
 
 # Integration tests above the basic suite.
diff --git a/test/integ/connection/protocolinfo.py b/test/integ/connection/protocolinfo.py
index e37f63b..6f036c8 100644
--- a/test/integ/connection/protocolinfo.py
+++ b/test/integ/connection/protocolinfo.py
@@ -37,6 +37,7 @@ class TestProtocolInfo(unittest.TestCase):
     control_socket.send("PROTOCOLINFO 1")
     protocolinfo_response = control_socket.recv()
     stem.connection.ProtocolInfoResponse.convert(protocolinfo_response)
+    control_socket.close()
     
     # according to the control spec the following _could_ differ or be
     # undefined but if that actually happens then it's gonna make people sad
diff --git a/test/integ/version.py b/test/integ/version.py
new file mode 100644
index 0000000..9bd7ee7
--- /dev/null
+++ b/test/integ/version.py
@@ -0,0 +1,59 @@
+"""
+Integration tests for tor version parsing.
+"""
+
+import unittest
+
+import test.runner
+import stem.version
+
+class TestVersion(unittest.TestCase):
+  """
+  Tests that the stem.version functions can handle the tor instance we're
+  running with.
+  """
+  
+  def test_get_system_tor_version(self):
+    """
+    Basic verification checks for the get_system_tor_version() function.
+    """
+    
+    if not stem.util.system.is_available("tor"):
+      self.skipTest("(tor isn't in our path)")
+    
+    # Since tor is in our path we should expect to be able to get the version
+    # that way, though this might not belong to our test instance (if we're
+    # running against a specific tor binary).
+    
+    stem.version.get_system_tor_version()
+    
+    # try running against a command that exists, but isn't tor
+    self.assertRaises(IOError, stem.version.get_system_tor_version, "ls")
+    
+    # try running against a command that doesn't exist
+    self.assertRaises(IOError, stem.version.get_system_tor_version, "blarg")
+  
+  def test_getinfo_version_parsing(self):
+    """
+    Issues a 'GETINFO version' query to our test instance and makes sure that
+    we can parse it.
+    """
+    
+    runner = test.runner.get_runner()
+    connection_type = runner.get_connection_type()
+    
+    if connection_type == test.runner.TorConnection.NONE:
+      self.skipTest("(no connection)")
+    
+    control_socket = runner.get_tor_socket()
+    control_socket.send("GETINFO version")
+    version_response = control_socket.recv()
+    control_socket.close()
+    
+    # the getinfo response looks like...
+    # 250-version=0.2.1.30
+    # 250 OK
+    
+    tor_version = list(version_response)[0][8:]
+    stem.version.Version(tor_version)
+

_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits