Revision: 0ba993a2658c
Author: Janne Härkönen <j...@reaktor.fi>
Date: Wed May 4 04:39:15 2011
Log: variables: Allow using Java system properties like %{os.name}
Update issue 680
Status: Started
http://code.google.com/p/robotframework/source/detail?r=0ba993a2658c
Modified:
/atest/robot/variables/environment_variables.txt
/atest/testdata/variables/environment_variables.txt
/src/robot/variables/variables.py
=======================================
--- /atest/robot/variables/environment_variables.txt Tue Apr 27 04:30:40
2010
+++ /atest/robot/variables/environment_variables.txt Wed May 4 04:39:15
2011
@@ -1,11 +1,16 @@
*** Settings ***
Suite Setup Run Tests ${EMPTY} variables/environment_variables.txt
-Force Tags pybot jybot regression
+Force Tags regression
+Default Tags pybot jybot
Resource atest_resource.txt
*** Test Cases ***
Environment Variables In Keyword Argument
Check Test Case Environment Variables In Keyword Argument
+
+Java System Properties Can Be Used
+ [Tags] jybot
+ Check Test Case ${TESTNAME}
Environment Variable With Backslashes
Check Test Case Environment Variable With Backslashes
=======================================
--- /atest/testdata/variables/environment_variables.txt Tue Apr 27 04:30:40
2010
+++ /atest/testdata/variables/environment_variables.txt Wed May 4 04:39:15
2011
@@ -13,6 +13,10 @@
Environment Variables In Keyword Argument
Should Be Equal %{THIS_ENV_VAR_IS_SET} Env var value
Should Be Equal %{THIS_ENV_VAR_IS_SET} can be catenated.
PATH: %{PATH} Env var value can be catenated. PATH: %{PATH}
+
+Java System Properties Can Be Used
+ Should Be Equal %{file.separator} ${/}
+ Should Not Be Empty %{os.name}
Environment Variable With Backslashes
Set Environment Variable ENV_VAR_WITH_BACKSLASHES c:\\temp\\backslash
=======================================
--- /src/robot/variables/variables.py Sun Feb 6 01:24:10 2011
+++ /src/robot/variables/variables.py Wed May 4 04:39:15 2011
@@ -16,9 +16,11 @@
import os
from UserDict import UserDict
if os.name == 'java':
+ from java.lang.System import getProperty as getJavaSystemProperty
from java.util import Map
else:
class Map: pass
+ getJavaSystemProperty = lambda name: None
from robot import utils
from robot.errors import DataError
@@ -190,17 +192,18 @@
"escape it like '\\%s'." % (value, value))
return value
- # 2) Handle environment variables
+ # 2) Handle environment variables and Java system properties
elif var.identifier == '%':
+ name = var.get_replaced_base(self).strip()
+ if name == '':
+ return '%%{%s}' % var.base
try:
- name = var.get_replaced_base(self).strip()
- if name != '':
- return os.environ[name]
- else:
- return '%%{%s}' % var.base
+ return os.environ[name]
except KeyError:
- raise DataError("Environment variable '%s' does not exist"
- % name)
+ property = getJavaSystemProperty(name)
+ if property:
+ return property
+ raise DataError("Environment variable '%s' does not
exist" % name)
# 3) Handle ${scalar} variables and @{list} variables without index
elif var.index is None: