2 new revisions:
Revision: cb728d2bfa83
Author: Pekka Klärck
Date: Thu Feb 16 12:40:54 2012
Log: Oooops....
http://code.google.com/p/robotframework/source/detail?r=cb728d2bfa83
Revision: ce81a7910fa7
Author: Pekka Klärck
Date: Thu Feb 16 12:50:55 2012
Log: OSLib: Added new Get Environment Variables keyword and fixed
minor enc...
http://code.google.com/p/robotframework/source/detail?r=ce81a7910fa7
==============================================================================
Revision: cb728d2bfa83
Author: Pekka Klärck
Date: Thu Feb 16 12:40:54 2012
Log: Oooops.
Update issue 1058
Ooops, actual implementation to allow Remove Environment Variable to remove
multiple vars was missing from the previous commit.
http://code.google.com/p/robotframework/source/detail?r=cb728d2bfa83
Modified:
/src/robot/libraries/OperatingSystem.py
=======================================
--- /src/robot/libraries/OperatingSystem.py Thu Feb 16 12:38:37 2012
+++ /src/robot/libraries/OperatingSystem.py Thu Feb 16 12:40:54 2012
@@ -808,11 +808,12 @@
Starting from Robot Framework 2.7, it is possible to remove
multiple
variables by passing them to this keyword as separate arguments.
"""
- value = del_env_var(name)
- if value:
- self._info("Environment variable '%s' deleted" % name)
- else:
- self._info("Environment variable '%s' does not exist" % name)
+ for name in names:
+ value = del_env_var(name)
+ if value:
+ self._info("Environment variable '%s' deleted" % name)
+ else:
+ self._info("Environment variable '%s' does not exist" %
name)
def environment_variable_should_be_set(self, name, msg=None):
"""Fails if the specified environment variable is not set.
==============================================================================
Revision: ce81a7910fa7
Author: Pekka Klärck
Date: Thu Feb 16 12:50:55 2012
Log: OSLib: Added new Get Environment Variables keyword and fixed
minor encoding issues with Log Environment Variables.
Also enhanced documentation of env var related keywords.
Update issue 1056
Summary: New keywords `Get Environment Variables` and `Log Environment
Variables` to `OperatingSystem` library.
Status: Review
Cc: pekka.klarck
I fixed minor encoding problem with Log Environment Variables by using new
get_env_vars utility function. To make testing the fix easier I changed the
keyword to also return the variables. Also added separate Get Environment
Variables keyword for just getting the variables.
I also updated the documentation of various env var keywords. Janne, could
you review the doc changes and the diff in general?
http://code.google.com/p/robotframework/source/detail?r=ce81a7910fa7
Modified:
/atest/robot/standard_libraries/operating_system/env_vars.txt
/atest/testdata/standard_libraries/operating_system/env_vars.txt
/src/robot/libraries/OperatingSystem.py
=======================================
--- /atest/robot/standard_libraries/operating_system/env_vars.txt Thu Feb
16 12:38:37 2012
+++ /atest/robot/standard_libraries/operating_system/env_vars.txt Thu Feb
16 12:50:55 2012
@@ -44,10 +44,10 @@
Use NON-ASCII variable in child process
Check test case ${TEST NAME}
-Log Environment Variables
+Get And Log Environment Variables
${tc}= Check test case ${TEST NAME}
- Check log message ${tc.kws[3].msgs[0]} 0 = value
- Check log message ${tc.kws[3].msgs[1]} 1 = äiti
+ Check log message ${tc.kws[8].msgs[0]} 0 = value
+ Check log message ${tc.kws[8].msgs[1]} 1 = äiti
*** Keywords ***
Run Tests With Environment Variables
=======================================
--- /atest/testdata/standard_libraries/operating_system/env_vars.txt Thu
Feb 16 12:38:37 2012
+++ /atest/testdata/standard_libraries/operating_system/env_vars.txt Thu
Feb 16 12:50:55 2012
@@ -100,13 +100,16 @@
Set Environment Variable ${NAME} ${NON ASCII}
Test Env Var In Child Process ${NAME}
-Log Environment Variables
+Get And Log Environment Variables
Set Environment Variable 0 value
Set Environment Variable 1 äiti
Set Environment Variable isä äiti
- Log Environment Variables
- Remove Environment Variable 0
- Remove Environment Variable 1
- Remove Environment Variable isä
- Log Environment Variables
-
+ ${vars} = Get Environment Variables
+ Should Contain ${vars} PATH
+ Should Be Equal ${vars['0']} value
+ Should Be Equal ${vars[u'is\xe4']} äiti
+ Should Be Equal ${vars['NON_ASCII_BY_RUNNER']} I can häs
åäö?!??!¿¿¡¡
+ ${v2} = Log Environment Variables
+ Should Be Equal ${vars} ${v2}
+ [Teardown] Remove Environment Variable 0 1 isä
+
=======================================
--- /src/robot/libraries/OperatingSystem.py Thu Feb 16 12:40:54 2012
+++ /src/robot/libraries/OperatingSystem.py Thu Feb 16 12:50:55 2012
@@ -25,7 +25,7 @@
from robot.utils import (ConnectionCache, seq2str, timestr_to_secs,
secs_to_timestr, plural_or_not, get_time,
abspath,
secs_to_timestamp, parse_time, unic,
decode_output,
- get_env_var, set_env_var, del_env_var,
+ get_env_var, set_env_var, del_env_var,
get_env_vars,
decode_from_system)
__version__ = get_version()
PROCESSES = ConnectionCache('No active processes')
@@ -34,7 +34,9 @@
# Support for using this library without installed Robot Framework
except ImportError:
from os.path import abspath
- from os import getenv as get_env_var, putenv as set_env_var, unsetenv
as del_env_var
+ from os import (getenv as get_env_var, putenv as set_env_var,
+ unsetenv as del_env_var, environ)
+ get_env_vars = lambda: environ.copy()
__version__ = '<unknown>'
logger = None
seq2str = lambda items: ', '.join("'%s'" % item for item in items)
@@ -783,6 +785,9 @@
If no such environment variable is set, returns the default value,
if
given. Otherwise fails the test case.
+ Starting from Robot Framework 2.7, returned variables are
automatically
+ decoded to Unicode using the system encoding.
+
Note that you can also access environment variables directly using
the variable syntax `%{ENV_VAR_NAME}`.
"""
@@ -794,8 +799,9 @@
def set_environment_variable(self, name, value):
"""Sets an environment variable to a specified value.
- Starting from Robot Framework 2.1.1, values are converted to
strings
- automatically.
+ Values are converted to strings automatically. Starting from Robot
+ Framework 2.7, set variables are automatically encoded using the
system
+ encoding.
"""
set_env_var(name, value)
self._info("Environment variable '%s' set to value '%s'" % (name,
value))
@@ -835,11 +841,29 @@
self._fail(msg, "Environment variable '%s' is set to '%s'" %
(name, value))
self._info("Environment variable '%s' is not set" % name)
+ def get_environment_variables(self):
+ """Returns currently available environment variables as a
dictionary.
+
+ Both keys and values are decoded to Unicode using the system
encoding.
+ Altering the returned dictionary has no effect on the actual
environment
+ variables.
+
+ New in Robot Framework 2.7.
+ """
+ return get_env_vars()
+
def log_environment_variables(self, level='INFO'):
- """Logs all environment variables with given log level."""
- for name in sorted(os.environ, key=lambda s: s.lower()):
- name = decode_from_system(name)
- self._log('%s = %s' % (name, get_env_var(name)), level)
+ """Logs all environment variables using the given log level.
+
+ Environment variables are also returned the same way as with
+ `Get Environment Variables` keyword.
+
+ New in Robot Framework 2.7.
+ """
+ vars = get_env_vars()
+ for name, value in sorted(vars.items(), key=lambda item:
item[0].lower()):
+ self._log('%s = %s' % (name, value), level)
+ return vars
# Path