2 new revisions:
Revision: b7c6fca8759d
Author: Pekka Klärck
Date: Thu Dec 22 04:36:26 2011
Log: cleanup (this whole module should be rewritten...)
http://code.google.com/p/robotframework/source/detail?r=b7c6fca8759d
Revision: 5c45a446b010
Author: Pekka Klärck
Date: Thu Dec 22 04:39:04 2011
Log: 1) Added test for always re-imporing variable file modules....
http://code.google.com/p/robotframework/source/detail?r=5c45a446b010
==============================================================================
Revision: b7c6fca8759d
Author: Pekka Klärck
Date: Thu Dec 22 04:36:26 2011
Log: cleanup (this whole module should be rewritten...)
http://code.google.com/p/robotframework/source/detail?r=b7c6fca8759d
Modified:
/src/robot/variables/variables.py
=======================================
--- /src/robot/variables/variables.py Thu Dec 22 02:31:46 2011
+++ /src/robot/variables/variables.py Thu Dec 22 04:36:26 2011
@@ -19,8 +19,8 @@
from java.lang.System import getProperty as getJavaSystemProperty
from java.util import Map
else:
- class Map: pass
getJavaSystemProperty = lambda name: None
+ class Map: pass
from robot import utils
from robot.errors import DataError
@@ -45,12 +45,12 @@
}$ # "}" and end of the string
''', re.VERBOSE)
- def __init__(self, identifiers=['$','@','%','&','*']):
+ def __init__(self, identifiers=('$','@','%','&','*')):
utils.NormalizedDict.__init__(self, ignore=['_'])
self._identifiers = identifiers
self._importer = utils.Importer('variable file')
- def __setitem__(self, name, value, path=None):
+ def __setitem__(self, name, value):
self._validate_var_name(name)
utils.NormalizedDict.__setitem__(self, name, value)
@@ -139,8 +139,8 @@
return results
def _replace_variables_inside_possible_list_var(self, item):
- if not (isinstance(item, basestring)
- and item.startswith('@{') and item.endswith('}')):
+ if not (isinstance(item, basestring) and
+ item.startswith('@{') and item.endswith('}')):
return None
var = VariableSplitter(item, self._identifiers)
if var.start != 0 or var.end != len(item):
@@ -157,8 +157,7 @@
if self._cannot_have_variables(item):
return utils.unescape(item)
var = VariableSplitter(item, self._identifiers)
- if var.identifier and var.base and \
- var.start == 0 and var.end == len(item):
+ if var.identifier and var.base and var.start == 0 and var.end ==
len(item):
return self._get_variable(var)
return self.replace_string(item, var)
@@ -236,7 +235,7 @@
variables = self._get_variables_from_module(module, args)
self._set_from_file(variables, overwrite, path)
except:
- amsg = args and 'with arguments %s ' % utils.seq2str2(args)
or ''
+ amsg = 'with arguments %s ' % utils.seq2str2(args) if args
else ''
raise DataError("Processing variable file '%s' %sfailed: %s"
% (path, amsg, utils.get_error_message()))
return variables
@@ -258,24 +257,23 @@
else:
name = '${%s}' % name
if overwrite or not utils.NormalizedDict.has_key(self, name):
- self.__setitem__(name, value, path)
+ self.set(name, value)
def set_from_variable_table(self, variable_table, overwrite=False):
for variable in variable_table:
try:
- name, value =
self._get_var_table_name_and_value(variable.name,
-
variable.value,
-
variable_table.source)
+ name, value = self._get_var_table_name_and_value(
+ variable.name, variable.value, variable_table.source)
# self.has_key would also match if name matches extended
syntax
if overwrite or not utils.NormalizedDict.has_key(self,
name):
- self.__setitem__(name, value, variable_table.source)
+ self.set(name, value)
except DataError, err:
variable_table.report_invalid_syntax("Setting
variable '%s' failed: %s"
% (variable.name,
unicode(err)))
def _get_var_table_name_and_value(self, name, value, path=None):
self._validate_var_name(name)
- value = [ self._unescape_leading_trailing_spaces(cell) for cell in
value ]
+ value = [self._unescape_leading_trailing_spaces(cell) for cell in
value]
if name[0] == '@':
return name, self.replace_list(value)
return name, self._get_var_table_scalar_value(name, value, path)
@@ -303,20 +301,16 @@
variables = self._get_dynamical_variables(module, args)
if variables is not None:
return variables
- names = [ attr for attr in dir(module) if not attr.startswith('_')
]
- try:
- names = [ name for name in names if name in module.__all__ ]
- except AttributeError:
- pass
- return [ (name, getattr(module, name)) for name in names ]
+ names = [attr for attr in dir(module) if not attr.startswith('_')]
+ if hasattr(module, '__all__'):
+ names = [name for name in names if name in module.__all__]
+ return [(name, getattr(module, name)) for name in names]
def _get_dynamical_variables(self, module, args):
- try:
- try:
- get_variables = getattr(module, 'get_variables')
- except AttributeError:
- get_variables = getattr(module, 'getVariables')
- except AttributeError:
+ get_variables = getattr(module, 'get_variables', None)
+ if not get_variables:
+ get_variables = getattr(module, 'getVariables', None)
+ if not get_variables:
return None
variables = get_variables(*args)
if isinstance(variables, (dict, UserDict)):
==============================================================================
Revision: 5c45a446b010
Author: Pekka Klärck
Date: Thu Dec 22 04:39:04 2011
Log: 1) Added test for always re-imporing variable file modules.
2) Removed tests for not re-importing variable files.
Update issue 1016
Status: Done
Owner: pekka.klarck
This functionality had already been changed as part of fixing issue 979.
Now the change is also explicitly tested.
http://code.google.com/p/robotframework/source/detail?r=5c45a446b010
Added:
/atest/testdata/variables/same_variable_file_names/same_file.txt
Deleted:
/atest/testdata/variables/same_variable_file_names/same_variable_file/__init__.txt
/atest/testdata/variables/same_variable_file_names/same_variable_file/suite1/subsuite1/testcase.txt
/atest/testdata/variables/same_variable_file_names/same_variable_file/suite1/testcase.txt
/atest/testdata/variables/same_variable_file_names/same_variable_file/suite2/testcase.txt
/atest/testdata/variables/same_variable_file_names/same_variable_file/suite3/subsuite1/testcase.txt
/atest/testdata/variables/same_variable_file_names/same_variable_file/suite3/subsuite2/testcase.txt
/atest/testdata/variables/same_variable_file_names/same_variable_file/suite3/testcase.txt
/atest/testdata/variables/same_variable_file_names/same_variable_file/variables.py
Modified:
/atest/robot/variables/same_variable_file_names.txt
=======================================
--- /dev/null
+++ /atest/testdata/variables/same_variable_file_names/same_file.txt Thu
Dec 22 04:39:04 2011
@@ -0,0 +1,21 @@
+*** Settings ***
+Library OperatingSystem
+
+*** Variables ***
+${VARFILE} ${TEMPDIR}/robot_variable_test.py
+
+*** Test Cases ***
+
+Importing Same Variable File Always Re-Imports Module
+ Test Import initial value
+ Sleep 1 second Make sure py and pyc files get different
timestamps
+ Test Import new value
+
+*** Keywords ***
+
+Test Import
+ [Arguments] ${value}
+ Create File ${VARFILE} VAR = '${value}'
+ Import Variables ${VARFILE}
+ Should Be Equal ${VAR} ${value}
+
=======================================
---
/atest/testdata/variables/same_variable_file_names/same_variable_file/__init__.txt
Tue Mar 23 15:27:48 2010
+++ /dev/null
@@ -1,3 +0,0 @@
-*** Settings ***
-Documentation These tests are used to verify that same variable file is
not imported multiple times, because this could cause performance problems
in case the import takes long time.
-
=======================================
---
/atest/testdata/variables/same_variable_file_names/same_variable_file/suite1/subsuite1/testcase.txt
Tue Mar 23 15:46:38 2010
+++ /dev/null
@@ -1,7 +0,0 @@
-*** Settings ***
-Variables ../../variables.py
-
-*** Test Cases ***
-TC
- Should Be Equal ${SUITE} suite
-
=======================================
---
/atest/testdata/variables/same_variable_file_names/same_variable_file/suite1/testcase.txt
Tue Mar 23 15:46:38 2010
+++ /dev/null
@@ -1,7 +0,0 @@
-*** Settings ***
-Variables ../variables.py
-
-*** Test Cases ***
-TC
- Should Be Equal ${SUITE} suite
-
=======================================
---
/atest/testdata/variables/same_variable_file_names/same_variable_file/suite2/testcase.txt
Tue Mar 23 15:46:38 2010
+++ /dev/null
@@ -1,7 +0,0 @@
-*** Settings ***
-Variables ../variables.py
-
-*** Test Cases ***
-TC
- Should Be Equal ${SUITE} suite
-
=======================================
---
/atest/testdata/variables/same_variable_file_names/same_variable_file/suite3/subsuite1/testcase.txt
Tue Mar 23 15:46:38 2010
+++ /dev/null
@@ -1,7 +0,0 @@
-*** Settings ***
-Variables ../../variables.py
-
-*** Test Cases ***
-TC
- Should Be Equal ${SUITE} suite
-
=======================================
---
/atest/testdata/variables/same_variable_file_names/same_variable_file/suite3/subsuite2/testcase.txt
Tue Mar 23 15:46:38 2010
+++ /dev/null
@@ -1,7 +0,0 @@
-*** Settings ***
-Variables ../../variables.py
-
-*** Test Cases ***
-TC
- Should Be Equal ${SUITE} suite
-
=======================================
---
/atest/testdata/variables/same_variable_file_names/same_variable_file/suite3/testcase.txt
Tue Mar 23 15:46:38 2010
+++ /dev/null
@@ -1,7 +0,0 @@
-*** Settings ***
-Variables ../variables.py
-
-*** Test Cases ***
-TC
- Should Be Equal ${SUITE} suite
-
=======================================
---
/atest/testdata/variables/same_variable_file_names/same_variable_file/variables.py
Tue Mar 23 15:27:48 2010
+++ /dev/null
@@ -1,4 +0,0 @@
-import time
-time.sleep(3)
-
-SUITE = "suite"
=======================================
--- /atest/robot/variables/same_variable_file_names.txt Thu Dec 22 02:31:46
2011
+++ /atest/robot/variables/same_variable_file_names.txt Thu Dec 22 04:39:04
2011
@@ -3,16 +3,19 @@
Force Tags regression jybot pybot smoke
Resource atest_resource.txt
+*** Variables ***
+${6 TESTS} 6 critical tests, 6 passed, 0 failed\n6 tests total, 6
passed, 0 failed
+
+
*** Test Cases ***
Different Variable Files
- [Documentation] Verifies that it is possible to import different
variable
- ... files even when they have the same name. Verifies that new
variables
- ... are imported, existing overridden, and old ones not visible
anymore.
- Check Test Suite Different Variable Files 6 critical tests, 6
passed, 0 failed\n 6 tests total, 6 passed, 0 failed PASS
+ [Documentation] Verifies that it is possible to import different
variable
+ ... files even when they have the same name. Verifies that new
variables
+ ... are imported, existing overridden, and old ones not visible
anymore.
+ Check Test Suite Different Variable Files ${6 TESTS}
Same Variable File
- [Documentation] Verifies that if the same variable file is
re-imported, the module itself is not reloaded. This is done for
performance reasons.
- FAIL Outdated test! Peke will fix this.
- ${suite} = Check Test Suite Same Variable File 6 critical tests, 6
passed, 0 failed\n 6 tests total, 6 passed, 0 failed
- Should Be True ${suite.elapsedtime} < 6000 The same variable file is
imported multiple times even it should be imported only once!!
-
+ [Documentation] Verifies that module is re-imported even if same
variable
+ ... file is imported multiple times.
+ Check Test Case Importing Same Variable File Always Re-Imports Module
+