Revision: bc46b20d6d3f
Author:   Pekka Klärck
Date:     Fri Feb 17 14:57:39 2012
Log:      fixed overriding earlier set environment variables with jython
http://code.google.com/p/robotframework/source/detail?r=bc46b20d6d3f

Modified:
 /atest/robot/standard_libraries/operating_system/env_vars.txt
 /atest/testdata/standard_libraries/operating_system/env_vars.txt
 /src/robot/utils/robotenv.py

=======================================
--- /atest/robot/standard_libraries/operating_system/env_vars.txt Thu Feb 16 12:50:55 2012 +++ /atest/robot/standard_libraries/operating_system/env_vars.txt Fri Feb 17 14:57:39 2012
@@ -32,6 +32,11 @@
     Check test case    ${TEST NAME}, Part 1
     Check test case    ${TEST NAME}, Part 2

+Get And Log Environment Variables
+    ${tc}=    Check test case    ${TEST NAME}
+    Check log message     ${tc.kws[8].msgs[0]}    0 = value
+    Check log message     ${tc.kws[8].msgs[1]}    1 = äiti
+
 Non-string names and values are converted to strings automatically
     Check test case    ${TEST NAME}

@@ -43,11 +48,6 @@

 Use NON-ASCII variable in child process
     Check test case    ${TEST NAME}
-
-Get And Log Environment Variables
-    ${tc}=    Check test case    ${TEST NAME}
-    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:50:55 2012 +++ /atest/testdata/standard_libraries/operating_system/env_vars.txt Fri Feb 17 14:57:39 2012
@@ -74,6 +74,19 @@
     Should Be Equal    ${value}      Hello another test case!
     Should Be Equal    %{${NAME}}    Hello another test case!

+Get And Log Environment Variables
+    Set Environment Variable     0   value
+    Set Environment Variable     1   äiti
+    Set Environment Variable     isä   äiti
+    ${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ä
+
 Non-string names and values are converted to strings automatically
     Set Environment Variable    ${NON STRING}    ${NON STRING}
     ${value} =    Get Environment Variable    ${NON STRING}
@@ -95,21 +108,11 @@
 Non-ASCII variable set before execution
     ${value} =    Get Environment Variable    NON_ASCII_BY_RUNNER
     Should Be Equal    ${value}    I can häs åäö?!??!¿¿¡¡
+ Set Environment Variable NON_ASCII_BY_RUNNER I cän överwrite?!?!?!
+    ${value} =    Get Environment Variable    NON_ASCII_BY_RUNNER
+    Should Be Equal    ${value}    I cän överwrite?!?!?!

 Use NON-ASCII variable in child process
     Set Environment Variable    ${NAME}    ${NON ASCII}
     Test Env Var In Child Process    ${NAME}

-Get And Log Environment Variables
-    Set Environment Variable     0   value
-    Set Environment Variable     1   äiti
-    Set Environment Variable     isä   äiti
-    ${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/utils/robotenv.py        Thu Feb 16 12:18:59 2012
+++ /src/robot/utils/robotenv.py        Fri Feb 17 14:57:39 2012
@@ -48,14 +48,6 @@
     return ret


-if sys.platform.startswith('java'):
-    from java.lang import System
-    def _get_env_var_from_java(name):
-        return System.getenv(unic(name))
-else:
-    def _get_env_var_from_java(name):
-        return None
-
 def _encode(var):
     if isinstance(var, str):
         return var
@@ -65,3 +57,21 @@

 def _decode(var):
     return decode_from_system(var, can_be_from_java=False)
+
+# Jython hack below needed due to http://bugs.jython.org/issue1841
+if not sys.platform.startswith('java'):
+    def _get_env_var_from_java(name):
+        return None
+
+else:
+    from java.lang import String, System
+
+    def _get_env_var_from_java(name):
+        name = name if isinstance(name, basestring) else unic(name)
+        value_set_before_execution = System.getenv(name)
+        if value_set_before_execution is None:
+            return None
+        current_value = String(os.environ[name]).toString()
+        if value_set_before_execution != current_value:
+            return None
+        return value_set_before_execution

Reply via email to