[tor-commits] [stem/master] Refactoring connection integ tests

atagar at torproject.org atagar at torproject.org
Sun Jan 29 08:54:42 UTC 2012


commit 39d93f75533243948d3222f800707dcb320b1a76
Author: Damian Johnson <atagar at torproject.org>
Date:   Sat Jan 28 23:42:14 2012 -0800

    Refactoring connection integ tests
    
    More tidying up of the integ tests. The connection integ used a common
    port/socket tester function but the common code was tiny enough that it's
    clearer without it.
---
 test/integ/connection/connect.py |   57 +++++++++++++++++--------------------
 1 files changed, 26 insertions(+), 31 deletions(-)

diff --git a/test/integ/connection/connect.py b/test/integ/connection/connect.py
index 00b0e04..ca3cf41 100644
--- a/test/integ/connection/connect.py
+++ b/test/integ/connection/connect.py
@@ -14,48 +14,43 @@ class TestConnect(unittest.TestCase):
     # none of these tests apply if there's no control connection
     if not test.runner.get_runner().is_accessible():
       self.skipTest("(no connection)")
+    
+    # prevents the function from printing to the real stdout
+    self.original_stdout = sys.stdout
+    sys.stdout = StringIO.StringIO()
+  
+  def tearDown(self):
+    sys.stdout = self.original_stdout
   
   def test_connect_port(self):
     """
     Basic sanity checks for the connect_port function.
     """
     
-    self._test_connect(True)
+    control_socket = stem.connection.connect_port(
+      control_port = test.runner.CONTROL_PORT,
+      password = test.runner.CONTROL_PASSWORD,
+      controller = stem.connection.Controller.NONE)
+    
+    if test.runner.Torrc.PORT in test.runner.get_runner().get_options():
+      test.runner.exercise_socket(self, control_socket)
+      control_socket.close()
+    else:
+      self.assertEquals(control_socket, None)
   
   def test_connect_socket_file(self):
     """
     Basic sanity checks for the connect_socket_file function.
     """
     
-    self._test_connect(False)
-  
-  def _test_connect(self, is_port):
-    """
-    Common implementations for the test_connect_* functions.
-    """
-    
-    # prevents the function from printing to the real stdout
-    original_stdout = sys.stdout
-    sys.stdout = StringIO.StringIO()
+    control_socket = stem.connection.connect_socket_file(
+      socket_path = test.runner.CONTROL_SOCKET_PATH,
+      password = test.runner.CONTROL_PASSWORD,
+      controller = stem.connection.Controller.NONE)
     
-    try:
-      ctl_pw = test.runner.CONTROL_PASSWORD
-      controller = stem.connection.Controller.NONE
-      
-      if is_port:
-        opt_type = test.runner.Torrc.PORT
-        ctl_port = test.runner.CONTROL_PORT
-        control_socket = stem.connection.connect_port(control_port = ctl_port, password = ctl_pw, controller = controller)
-      else:
-        opt_type = test.runner.Torrc.SOCKET
-        ctl_socket = test.runner.CONTROL_SOCKET_PATH
-        control_socket = stem.connection.connect_socket_file(socket_path = ctl_socket, password = ctl_pw, controller = controller)
-      
-      if opt_type in test.runner.get_runner().get_options():
-        test.runner.exercise_socket(self, control_socket)
-        control_socket.close()
-      else:
-        self.assertEquals(control_socket, None)
-    finally:
-      sys.stdout = original_stdout
+    if test.runner.Torrc.SOCKET in test.runner.get_runner().get_options():
+      test.runner.exercise_socket(self, control_socket)
+      control_socket.close()
+    else:
+      self.assertEquals(control_socket, None)
 





More information about the tor-commits mailing list