Revision: 153
Author: janne.t.harkonen
Date: Fri Aug 24 04:21:30 2012
Log: Set (Default/Client) Configuration now work with lsit of strings
http://code.google.com/p/robotframework-sshlibrary/source/detail?r=153
Modified:
/trunk/src/SSHLibrary/__init__.py
/trunk/src/SSHLibrary/config.py
/trunk/utest/test_library.py
=======================================
--- /trunk/src/SSHLibrary/__init__.py Fri Aug 24 04:21:13 2012
+++ /trunk/src/SSHLibrary/__init__.py Fri Aug 24 04:21:30 2012
@@ -90,7 +90,7 @@
def ssh_client(self):
return self._cache.current
- def set_default_configuration(self, **entries):
+ def set_default_configuration(self, *entries):
"""Update the default configuration values.
This keyword can only be used using named argument syntax. The
names
@@ -100,9 +100,9 @@
Example:
| Set Default Configuration | newline=CRLF | prompt=$ |
"""
- self._config.update(**entries)
+ self._config.update_with_strings(*entries)
- def set_client_configuration(self, **entries):
+ def set_client_configuration(self, *entries):
"""Update the client configuration values.
Works on the currently selected connection. At least one connection
@@ -115,7 +115,7 @@
Example:
| Set Client Configuration | term_type=ansi | timeout=2 hours |
"""
- self.ssh_client.config.update(**entries)
+ self.ssh_client.config.update_with_strings(*entries)
def open_connection(self, host, alias=None, port=22, timeout=None,
newline=None, prompt=None, term_type='vt100',
=======================================
--- /trunk/src/SSHLibrary/config.py Wed Aug 22 21:55:24 2012
+++ /trunk/src/SSHLibrary/config.py Fri Aug 24 04:21:30 2012
@@ -23,13 +23,36 @@
assert cfg.name == 'John Doe'
"""
- def __init__(self, **config):
- self._config = config
+ def __init__(self, **entries):
+ self._config = entries
- def update(self, **config):
- """Update configuration entries. See `__init__` for an example."""
- for name in config:
- self._config[name].set(config[name])
+ def update(self, **entries):
+ """Update configuration entries.
+
+ :param entries: entries to be updated, keyword argument names must
+ match existing entry names.
+
+ See `__init__` for an example.
+ """
+ for name in entries:
+ self._config[name].set(entries[name])
+
+ def update_with_strings(self, *entries):
+ """Update configuration entries.
+
+ :param entries: entries to be updated as strings in format
name=value.
+
+ Example:
+ cfg = Configuration(name=StringEntry('initial'))
+ assert cfg.name == initial
+ cfg.update('name=John Doe')
+ assert cfg.name == 'John Doe'
+ """
+ updated = {}
+ for e in entries:
+ name, value = e.split('=', 1)
+ updated[name] = value
+ self.update(**updated)
def __getattr__(self, name):
if name in self._config:
=======================================
--- /trunk/utest/test_library.py Wed Aug 22 21:55:51 2012
+++ /trunk/utest/test_library.py Fri Aug 24 04:21:30 2012
@@ -18,8 +18,10 @@
def test_set_default_confguarition(self):
timeout, newline, prompt, level = 1, '\r\n', '>', 'DEBUG'
lib = SSHLibrary()
- lib.set_default_configuration(timeout=timeout, newline=newline,
- prompt=prompt, log_level=level)
+ lib.set_default_configuration('timeout=%s' % timeout,
+ 'newline=%s' % newline,
+ 'prompt=%s' % prompt,
+ 'log_level=%s' % level)
self._assert_config(lib._config, timeout, newline, prompt, level)
def _assert_config(self, cfg, timeout=3, newline='\n', prompt=None,
@@ -46,7 +48,8 @@
port, term_type = 23, 'ansi'
lib = SSHLibrary()
lib.open_connection(HOSTNAME)
- lib.set_client_configuration(port=port, term_type=term_type)
+ lib.set_client_configuration('port=%d' % port,
+ 'term_type=%s' % term_type)
self._assert_config(lib.ssh_client.config, port=port,
term_type=term_type)