2 new revisions:

Revision: 3641512e0223
Author:   Pekka Klärck
Date:     Thu Feb 16 12:18:59 2012
Log: robotenv: 1) new get_env_vars utility, 2) unit tests for all env utils
http://code.google.com/p/robotframework/source/detail?r=3641512e0223

Revision: 04c12527cd05
Author:   Pekka Klärck
Date:     Thu Feb 16 12:38:37 2012
Log: Allow `Remove Environment Variable` to remove multiple vars in one go....
http://code.google.com/p/robotframework/source/detail?r=04c12527cd05

==============================================================================
Revision: 3641512e0223
Author:   Pekka Klärck
Date:     Thu Feb 16 12:18:59 2012
Log: robotenv: 1) new get_env_vars utility, 2) unit tests for all env utils
http://code.google.com/p/robotframework/source/detail?r=3641512e0223

Added:
 /utest/utils/test_robotenv.py
Modified:
 /src/robot/utils/__init__.py
 /src/robot/utils/robotenv.py

=======================================
--- /dev/null
+++ /utest/utils/test_robotenv.py       Thu Feb 16 12:18:59 2012
@@ -0,0 +1,57 @@
+import unittest
+import os
+
+from robot.utils.asserts import assert_equals, assert_not_none, assert_none, assert_true
+from robot.utils import get_env_var, set_env_var, del_env_var, get_env_vars
+
+TEST_VAR = 'TeST_EnV_vAR'
+TEST_VAL = 'original value'
+NON_ASCII_VAR = u'\xe4iti'
+NON_ASCII_VAL = u'is\xe4'
+
+
+class TestRobotEnv(unittest.TestCase):
+
+    def setUp(self):
+        os.environ[TEST_VAR] = TEST_VAL
+
+    def tearDown(self):
+        if TEST_VAR in os.environ:
+            del os.environ[TEST_VAR]
+
+    def test_get_env_var(self):
+        assert_not_none(get_env_var('PATH'))
+        assert_equals(get_env_var(TEST_VAR), TEST_VAL)
+        assert_none(get_env_var('NoNeXiStInG'))
+        assert_equals(get_env_var('NoNeXiStInG', 'default'), 'default')
+
+    def test_set_env_var(self):
+        set_env_var(TEST_VAR, 'new value')
+        assert_equals(os.getenv(TEST_VAR), 'new value')
+
+    def test_del_env_var(self):
+        old = del_env_var(TEST_VAR)
+        assert_none(os.getenv(TEST_VAR))
+        assert_equals(old, TEST_VAL)
+        assert_none(del_env_var(TEST_VAR))
+
+    def test_get_set_del_non_ascii_vars(self):
+        set_env_var(NON_ASCII_VAR, NON_ASCII_VAL)
+        for k, v in os.environ.items():
+            assert_true(isinstance(k, str) and isinstance(v, str))
+        assert_equals(get_env_var(NON_ASCII_VAR), NON_ASCII_VAL)
+        assert_equals(del_env_var(NON_ASCII_VAR), NON_ASCII_VAL)
+        assert_none(get_env_var(NON_ASCII_VAR))
+
+    def test_get_env_vars(self):
+        set_env_var(NON_ASCII_VAR, NON_ASCII_VAL)
+        vars = get_env_vars()
+        assert_true('PATH' in vars)
+        assert_equals(vars[TEST_VAR], TEST_VAL)
+        assert_equals(vars[NON_ASCII_VAR], NON_ASCII_VAL)
+        for k, v in vars.items():
+            assert_true(isinstance(k, unicode) and isinstance(v, unicode))
+
+
+if __name__ == '__main__':
+    unittest.main()
=======================================
--- /src/robot/utils/__init__.py        Wed Feb 15 00:21:02 2012
+++ /src/robot/utils/__init__.py        Thu Feb 16 12:18:59 2012
@@ -28,7 +28,7 @@
 from .match import eq, matches, matches_any, Matcher
 from .misc import plural_or_not, printable_name, seq2str, seq2str2, getdoc
 from .normalizing import normalize, normalize_tags, NormalizedDict
-from .robotenv import get_env_var, set_env_var, del_env_var
+from .robotenv import get_env_var, set_env_var, del_env_var, get_env_vars
 from .robotpath import normpath, abspath, get_link_path
 from .robottime import (get_timestamp, get_start_timestamp, format_time,
                         get_time, get_elapsed_time, elapsed_time_to_string,
=======================================
--- /src/robot/utils/robotenv.py        Wed Feb 15 04:37:12 2012
+++ /src/robot/utils/robotenv.py        Thu Feb 16 12:18:59 2012
@@ -40,6 +40,13 @@
         del os.environ[_encode(name)]
     return value

+def get_env_vars():
+    ret = {}
+    for var in os.environ:
+        var = _decode(var)
+        ret[var] = get_env_var(var)
+    return ret
+

 if sys.platform.startswith('java'):
     from java.lang import System

==============================================================================
Revision: 04c12527cd05
Author:   Pekka Klärck
Date:     Thu Feb 16 12:38:37 2012
Log: Allow `Remove Environment Variable` to remove multiple vars in one go.

Update issue 1058
Status: Done
Owner: pekka.klarck
http://code.google.com/p/robotframework/source/detail?r=04c12527cd05

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 Wed Feb 15 03:44:44 2012 +++ /atest/robot/standard_libraries/operating_system/env_vars.txt Thu Feb 16 12:38:37 2012
@@ -12,6 +12,9 @@

 Remove Environment Variable
     Check test case    ${TEST NAME}
+
+Remove Multiple Environment Variables
+    Check test case    ${TEST NAME}

 Environment Variable Should Be Set
     Check test case    ${TEST NAME}
=======================================
--- /atest/testdata/standard_libraries/operating_system/env_vars.txt Wed Feb 15 03:44:44 2012 +++ /atest/testdata/standard_libraries/operating_system/env_vars.txt Thu Feb 16 12:38:37 2012
@@ -30,6 +30,16 @@
     Environment Variable Should Not Be Set    ${NAME}
     Remove Environment Variable    ${NAME}
     Environment Variable Should Not Be Set    ${NAME}
+
+Remove Multiple Environment Variables
+    Remove Environment Variable
+    Set Environment Variable    ${NAME}_1    a
+    Set Environment Variable    ${NAME}_2    b
+    Set Environment Variable    ${NAME}_3    c
+    Remove Environment Variable    ${NAME}_1    ${NAME}_2    ${NAME}_3
+    Environment Variable Should Not Be Set    ${NAME}_1
+    Environment Variable Should Not Be Set    ${NAME}_2
+    Environment Variable Should Not Be Set    ${NAME}_3

 Environment Variable Should Be Set
     [Documentation]    FAIL Environment variable 'not_set_var' is not set
=======================================
--- /src/robot/libraries/OperatingSystem.py     Wed Feb 15 04:42:59 2012
+++ /src/robot/libraries/OperatingSystem.py     Thu Feb 16 12:38:37 2012
@@ -326,8 +326,7 @@
         A line matches if it contains the `pattern` anywhere in it and
         it *does not need to match the pattern fully*. The pattern
         matching syntax is explained in `introduction`, and in this
- case matching is case-sensitive. Support for different pattern types
-        were removed in Robot Framework 2.5.
+        case matching is case-sensitive.

         Examples:
         | ${errors} = | Grep File | /var/log/myapp.log | ERROR |
@@ -801,10 +800,13 @@
         set_env_var(name, value)
self._info("Environment variable '%s' set to value '%s'" % (name, value))

-    def remove_environment_variable(self, name):
+    def remove_environment_variable(self, *names):
         """Deletes the specified environment variable.

         Does nothing if the environment variable is not set.
+
+ 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:

Reply via email to