
commit 51025794e68b1607e6a15741ebdab45650df0c25 Author: Ravi Chandra Padmala <neenaoffline@gmail.com> Date: Thu Jun 21 20:30:04 2012 +0530 Add unit tests for SingleLineResponse and add missing imports --- run_tests.py | 2 ++ stem/control.py | 16 ++++++++-------- stem/response/__init__.py | 6 ++++-- test/unit/response/__init__.py | 10 +++++++++- 4 files changed, 23 insertions(+), 11 deletions(-) diff --git a/run_tests.py b/run_tests.py index ea12531..cff77f8 100755 --- a/run_tests.py +++ b/run_tests.py @@ -25,6 +25,7 @@ import test.unit.response.getinfo import test.unit.response.getconf import test.unit.response.protocolinfo import test.unit.response.authchallenge +import test.unit.response.singleline import test.unit.util.conf import test.unit.util.connection import test.unit.util.enum @@ -112,6 +113,7 @@ UNIT_TESTS = ( test.unit.response.control_line.TestControlLine, test.unit.response.getinfo.TestGetInfoResponse, test.unit.response.getconf.TestGetConfResponse, + test.unit.response.singleline.TestSingleLineResponse, test.unit.response.protocolinfo.TestProtocolInfoResponse, test.unit.response.authchallenge.TestAuthChallengeResponse, test.unit.connection.authentication.TestAuthenticate, diff --git a/stem/control.py b/stem/control.py index e5ed132..290f178 100644 --- a/stem/control.py +++ b/stem/control.py @@ -666,34 +666,34 @@ class Controller(BaseController): """ Changes the configuration of one or more configuration variables using the control socket. - + :param dict options: a dictionary containing a mapping of configuration keys (string) to the corresponding values (string or list of strings) - + Or - + :param str key: configuration key :param str value: configuration value - + :returns: True on successfully setting the values - + :raises: :class:`stem.socket.ControllerError` if the call fails :class:`stem.socket.InvalidArguments` if configuration options requested was invalid :class:`stem.socket.InvalidRequest` if the configuration setting is impossible or if there's a syntax error in the configuration values """ - + if len(args) == 2: options = {args[0]: args[1]} elif len(args) == 1: options = args[0] else: raise TypeError("set_conf expected 1 or 2 arguments, got %d", len(args)) - + response = self.msg("SETCONF %s" % " ".join(["=".join(opts) for opts in args.items()])) stem.response.convert("SINGLELINE", response) - + if response.is_ok(): return True elif response.code in ("513", "552", "553"): diff --git a/stem/response/__init__.py b/stem/response/__init__.py index e9b1c96..2ae0b82 100644 --- a/stem/response/__init__.py +++ b/stem/response/__init__.py @@ -30,6 +30,8 @@ __all__ = ["getinfo", "getconf", "protocolinfo", "authchallenge", "convert", "Co import re import threading +import stem.socket + KEY_ARG = re.compile("^(\S+)=") # Escape sequences from the 'esc_for_log' function of tor's 'common/util.c'. @@ -446,9 +448,9 @@ class SingleLineResponse(ControlMessage): content = self.content() if len(content) > 1: - raise ProtocolError("Received multiline response") + raise stem.socket.ProtocolError("Received multiline response") elif len(content) == 0: - raise ProtocolError("Received empty response") + raise stem.socket.ProtocolError("Received empty response") else: self.code, self.delimiter, self.message = content[0] diff --git a/test/unit/response/__init__.py b/test/unit/response/__init__.py index 069ecba..530a5d3 100644 --- a/test/unit/response/__init__.py +++ b/test/unit/response/__init__.py @@ -2,5 +2,13 @@ Unit tests for stem.response. """ -__all__ = ["control_message", "control_line", "getinfo", "getconf", "protocolinfo", "authchallenge"] +__all__ = [ + "control_message", + "control_line", + "getinfo", + "getconf", + "protocolinfo", + "authchallenge", + "singleline" +]