[tor-commits] [stem/master] Drop get_protocolinfo_response() helper

atagar at torproject.org atagar at torproject.org
Mon May 22 18:30:29 UTC 2017


commit 7087dad486dc5d3cfb2eb75da83750d61ce40ef6
Author: Damian Johnson <atagar at torproject.org>
Date:   Sun May 21 18:27:04 2017 -0700

    Drop get_protocolinfo_response() helper
    
    Replace the little usage of get_protocolinfo_response() we had.
---
 test/unit/connection/authentication.py | 11 ++++++-----
 test/unit/control/controller.py        |  8 ++++----
 test/util.py                           | 21 ---------------------
 3 files changed, 10 insertions(+), 30 deletions(-)

diff --git a/test/unit/connection/authentication.py b/test/unit/connection/authentication.py
index 044f163..b50f97b 100644
--- a/test/unit/connection/authentication.py
+++ b/test/unit/connection/authentication.py
@@ -12,9 +12,9 @@ various error conditions, and make sure that the right exception is raised.
 import unittest
 
 import stem.connection
-
 import test.util
 
+from stem.response import ControlMessage
 from stem.util import log
 
 try:
@@ -34,9 +34,9 @@ class TestAuthenticate(unittest.TestCase):
 
     # tests where get_protocolinfo succeeds
 
-    get_protocolinfo_mock.return_value = test.util.get_protocolinfo_response(
-      auth_methods = (stem.connection.AuthMethod.NONE, ),
-    )
+    protocolinfo_message = ControlMessage.from_str('250-PROTOCOLINFO 1\r\n250 OK\r\n', 'PROTOCOLINFO')
+    protocolinfo_message.auth_methods = (stem.connection.AuthMethod.NONE, )
+    get_protocolinfo_mock.return_value = protocolinfo_message
 
     stem.connection.authenticate(None)
 
@@ -94,7 +94,8 @@ class TestAuthenticate(unittest.TestCase):
       stem.connection.AuthMethod.UNKNOWN,
     ], include_empty = True)
 
-    protocolinfo = test.util.get_protocolinfo_response(cookie_path = '/tmp/blah')
+    protocolinfo = ControlMessage.from_str('250-PROTOCOLINFO 1\r\n250 OK\r\n', 'PROTOCOLINFO')
+    protocolinfo.cookie_path = '/tmp/blah'
 
     for auth_methods in auth_method_combinations:
       for auth_none_exc in all_auth_none_exc:
diff --git a/test/unit/control/controller.py b/test/unit/control/controller.py
index 2cf8b7e..124c115 100644
--- a/test/unit/control/controller.py
+++ b/test/unit/control/controller.py
@@ -13,10 +13,9 @@ import stem.socket
 import stem.util.system
 import stem.version
 
-import test.util
-
 from stem import ControllerError, DescriptorUnavailable, InvalidArguments, InvalidRequest, ProtocolError, UnsatisfiableRequest
 from stem.control import _parse_circ_path, Listener, Controller, EventType
+from stem.response import ControlMessage
 from stem.exit_policy import ExitPolicy
 
 try:
@@ -339,13 +338,14 @@ class TestControl(unittest.TestCase):
 
     # use the handy mocked protocolinfo response
 
-    get_protocolinfo_mock.return_value = test.util.get_protocolinfo_response()
+    protocolinfo_msg = ControlMessage.from_str('250-PROTOCOLINFO 1\r\n250 OK\r\n', 'PROTOCOLINFO')
+    get_protocolinfo_mock.return_value = protocolinfo_msg
 
     # compare the str representation of these object, because the class
     # does not have, nor need, a direct comparison operator
 
     self.assertEqual(
-      str(test.util.get_protocolinfo_response()),
+      str(protocolinfo_msg),
       str(self.controller.get_protocolinfo())
     )
 
diff --git a/test/util.py b/test/util.py
index 7ad309d..adadfe4 100644
--- a/test/util.py
+++ b/test/util.py
@@ -12,7 +12,6 @@ Helper functions for our test framework.
   get_prereq - provides the tor version required to run the given target
   get_torrc_entries - provides the torrc entries for a given target
 
-  get_protocolinfo_response - provides a ProtocolInfoResponse instance
   get_all_combinations - provides all combinations of attributes
   random_fingerprint - provides a random relay fingerprint
   tor_version - provides the version of tor we're testing against
@@ -248,26 +247,6 @@ def random_fingerprint():
   return hashlib.sha1(os.urandom(20)).hexdigest().upper()
 
 
-def get_protocolinfo_response(**attributes):
-  """
-  Provides a ProtocolInfoResponse, customized with the given attributes. The
-  base instance is minimal, with its version set to one and everything else
-  left with the default.
-
-  :param dict attributes: attributes to customize the response with
-
-  :returns: stem.response.protocolinfo.ProtocolInfoResponse instance
-  """
-
-  protocolinfo_response = stem.response.ControlMessage.from_str('250-PROTOCOLINFO 1\r\n250 OK\r\n', 'PROTOCOLINFO')
-  stem.response.convert('PROTOCOLINFO', protocolinfo_response)
-
-  for attr in attributes:
-    setattr(protocolinfo_response, attr, attributes[attr])
-
-  return protocolinfo_response
-
-
 def tor_version(tor_path = None):
   """
   Provides the version of tor we're testing against.





More information about the tor-commits mailing list