2 new revisions:

Revision: 373925533e69
Branch:   default
Author:   Pekka Klärck
Date:     Thu May 30 08:53:25 2013
Log: fixed handling errors in variable table. also added tests for errors i...
http://code.google.com/p/robotframework/source/detail?r=373925533e69

Revision: b174ef6e9b7f
Branch:   default
Author:   Pekka Klärck
Date:     Thu May 30 08:53:30 2013
Log:      Automated merge with https://code.google.com/p/robotframework/
http://code.google.com/p/robotframework/source/detail?r=b174ef6e9b7f

==============================================================================
Revision: 373925533e69
Branch:   default
Author:   Pekka Klärck
Date:     Thu May 30 08:53:25 2013
Log: fixed handling errors in variable table. also added tests for errors in variable table in resource file.
http://code.google.com/p/robotframework/source/detail?r=373925533e69

Added:
 /atest/robot/variables/variable_table_in_resource_file.txt
 /atest/testdata/variables/resource_for_variable_table_in_resource_file.txt
 /atest/testdata/variables/variable_table_in_resource_file.txt
Modified:
 /src/robot/new_running/builder.py
 /src/robot/new_running/model.py
 /src/robot/parsing/model.py
 /src/robot/variables/variables.py
 /utest/new_running/test_builder.py

=======================================
--- /dev/null
+++ /atest/robot/variables/variable_table_in_resource_file.txt Thu May 30 08:53:25 2013
@@ -0,0 +1,93 @@
+*** Settings ***
+Suite Setup Run tests ${EMPTY} variables/variable_table_in_resource_file.txt
+Force Tags      pybot  jybot  regression
+Resource        atest_resource.txt
+
+*** Test Cases ***
+Scalar String
+    Check Test Case    ${TEST NAME}
+
+Scalar Non-Strings
+    Check Test Case    ${TEST NAME}
+
+Scalar String With Escapes
+    Check Test Case    ${TEST NAME}
+
+Empty Scalar String
+    Check Test Case    ${TEST NAME}
+
+List With One Item
+    Check Test Case    ${TEST NAME}
+
+List With Multiple Items
+    Check Test Case    ${TEST NAME}
+
+List With Escapes
+    Check Test Case    ${TEST NAME}
+
+List Created From List With Escapes
+    Check Test Case    ${TEST NAME}
+
+List With No Items
+    Check Test Case    ${TEST NAME}
+
+Variable Names Are Case Insensitive
+    Check Test Case    ${TEST NAME}
+
+Variable Names Are Space Insensitive
+    Check Test Case    ${TEST NAME}
+
+Variable Names Are Underscore Insensitive
+    Check Test Case    ${TEST NAME}
+
+Assign Mark With Scalar Variable
+    Check Test Case    ${TEST NAME}
+
+Assign Mark With List Variable
+    Check Test Case    ${TEST NAME}
+
+Three dots on the same line should be interpreted as string
+    Check Test Case     ${TEST NAME}
+
+Using Scalar List Should Fail
+    Check Test Case     ${TEST NAME}
+    Creating Variable Should Have Failed    ${ERRORS[0]}    \${SCALAR LIST}
+ ... Creating a scalar variable with a list value in the Variable table
+    ...    is no longer possible. Create a list variable '\@{SCALAR LIST}'
+    ...    and use it as a scalar variable '\${SCALAR LIST}' instead.
+
+Creating variable using non-existing variable fails
+    Check Test Case    ${TEST NAME}
+    Creating Variable Should Have Failed    ${ERRORS[4]}    \${NONEX 1}
+    ...    Non-existing variable '\${NON EXISTING}'.
+    Creating Variable Should Have Failed    ${ERRORS[5]}    \${NONEX 2A}
+    ...    Non-existing variable '\${NON EX}'.
+    Creating Variable Should Have Failed    ${ERRORS[6]}    \${NONEX 2B}
+    ...    Non-existing variable '\${NONEX 2A}'.
+
+Using variable created from non-existing variable in imports fails
+    Creating Variable Should Have Failed    ${ERRORS[1]}    \${NONEX 3}
+    ...    Non-existing variable '\${NON EXISTING VARIABLE}'.
+    Import Should Have Failed    ${ERRORS[2]}    Resource
+    ...    Non-existing variable '\${NONEX 3}'.
+    Import Should Have Failed    ${ERRORS[3]}    Library
+    ...    Non-existing variable '\${NONEX 3}'.
+
+*** Keywords ***
+Creating Variable Should Have Failed
+    [Arguments]    ${error}    ${name}    @{message}
+ ${path} = Normalize Path ${DATADIR}/variables/resource_for_variable_table_in_resource_file.txt
+    ${msg} =    Catenate
+    ...    Error in file '${path}' in table 'Variables':
+    ...    Setting variable '${name}' failed:
+    ...    @{message}
+    Check Log Message    ${error}    ${msg}    ERROR
+
+Import Should Have Failed
+    [Arguments]    ${error}    ${name}    @{message}
+ ${path} = Normalize Path ${DATADIR}/variables/resource_for_variable_table_in_resource_file.txt
+    ${msg} =    Catenate
+    ...    Error in file '${path}' in table 'Settings':
+    ...    Replacing variables from setting '${name}' failed:
+    ...    @{message}
+    Check Log Message    ${error}    ${msg}    ERROR
=======================================
--- /dev/null
+++ /atest/testdata/variables/resource_for_variable_table_in_resource_file.txt Thu May 30 08:53:25 2013
@@ -0,0 +1,32 @@
+*** Variables ***
+${STRING}         Hello world!
+${INTEGER}        ${42}
+${FLOAT}          ${-1.2}
+${BOOLEAN}        ${True}
+${NONE VALUE}     ${None}
+${ESCAPES}        one \\ two \\\\ \${non_existing}
+${NO VALUE}       ${EMPTY}
+@{ONE ITEM}       Hello again?
+@{LIST}           Hello    again    ?
+@{LIST WITH ESCAPES} one \\ two \\\\ three \\\\\\ \${non_existing}
+@{LIST CREATED FROM LIST WITH ESCAPES}    @{LIST WITH ESCAPES}
+@{EMPTY LIST}
+${lowercase}      Variable name in lower case
+@{lowercase}      Variable name in lower case
+${S P a c e s }    Variable name with spaces
+@{s P a c es }    Variable name with spaces
+${UNDER_scores}    Variable name with under scores
+@{_u_n_d_e_r___s_c_o_r_e_s_}    Variable name with under scores
+${ASSING MARK}    This syntax works starting from 1.8
+@{ASSIGN MARK}    This syntax works    starting    from    ${1.8}
+${THREE DOTS}     ...
+@{3DOTS LIST}     ...   ...
+${SCALAR LIST} I am a scalar list with many items +${NONEX 1} Creating variable based on ${NON EXISTING} variable fails.
+${NONEX 2A}       This ${NON EX} is used for creating another variable.
+${NONEX 2B}       ${NONEX 2A}
+${NONEX 3}        This ${NON EXISTING VARIABLE} is used in imports.
+
+*** Settings ***
+Resource          ${NONEX 3}
+Library           ${NONEX 3}
=======================================
--- /dev/null
+++ /atest/testdata/variables/variable_table_in_resource_file.txt Thu May 30 08:53:25 2013
@@ -0,0 +1,94 @@
+*** Settings ***
+Resource          resource_for_variable_table_in_resource_file.txt
+
+*** Test Case ***
+Scalar String
+    Should Be Equal    ${STRING}    Hello world!
+    Should Be Equal    I said: "${STRING}"    I said: "Hello world!"
+
+Scalar Non-Strings
+    Should Be True    ${INTEGER} == 42
+    Should Be True    ${FLOAT} == -1.2
+    Should Be True    ${BOOLEAN} == True
+    Should Be True    ${NONE VALUE} == None
+
+Scalar String With Escapes
+    Should Be Equal    ${ESCAPES}    one \\ two \\\\ \${non_existing}
+
+Empty Scalar String
+    Should Be Equal    ${NO VALUE}    ${EMPTY}
+    Should Be Equal    "${NO VALUE}${NO VALUE}"    ""
+
+List with One Item
+    Should Be True    @{ONE ITEM} == ['Hello again?']
+    Should Be Equal    @{ONE ITEM}[0]    Hello again?
+
+List With Multiple Items
+    Should Be Equal    @{LIST}[0]    Hello
+    Should Be Equal    @{LIST}[1]    again
+    Should Be Equal    @{LIST}[2]    ?
+    Should Be True    @{LIST} == ['Hello', 'again', '?']
+
+List With Escapes
+    Should Be Equal    @{LIST WITH ESCAPES}[0]    one \\
+    Should Be Equal    @{LIST WITH ESCAPES}[1]    two \\\\
+    Should Be Equal    @{LIST WITH ESCAPES}[2]    three \\\\\\
+    Should Be Equal    @{LIST WITH ESCAPES}[3]    \${non_existing}
+
+List Created From List With Escapes
+    Should Be Equal    @{LIST CREATED FROM LIST WITH ESCAPES}[0]    one \\
+ Should Be Equal @{LIST CREATED FROM LIST WITH ESCAPES}[1] two \\\\ + Should Be Equal @{LIST CREATED FROM LIST WITH ESCAPES}[2] three \\\\\\ + Should Be Equal @{LIST CREATED FROM LIST WITH ESCAPES}[3] \${non_existing} + Should Be True @{LIST WITH ESCAPES} == @{LIST CREATED FROM LIST WITH ESCAPES} + Should Be Equal ${LIST WITH ESCAPES} ${LIST CREATED FROM LIST WITH ESCAPES}
+
+List With No Items
+    [Documentation]    FAIL Non-existing variable '\@{EMPTY LIST}[0]'
+    Should Be True    @{EMPTY LIST} == []
+ ${ret} = Catenate @{EMPTY LIST} @{EMPTY LIST} only value @{EMPTY LIST}
+    Should Be Equal    ${ret}    only value
+    Log    @{EMPTY LIST}[0]
+
+Variable Names Are Case Insensitive
+    Should Be Equal    ${lowercase}    Variable name in lower case
+    Should Be Equal    ${LOWERCASE}    Variable name in lower case
+    Should Be Equal    ${LoWerCAse}    Variable name in lower case
+    Should Be Equal    @{lowercase}[0]    Variable name in lower case
+    Should Be Equal    @{LOWERCASE}[0]    Variable name in lower case
+    Should Be Equal    @{lOWErcasE}[0]    Variable name in lower case
+
+Variable Names Are Space Insensitive
+    Should Be Equal    ${SPACES}    Variable name with spaces
+    Should Be Equal    ${ s P a C e s }    Variable name with spaces
+    Should Be Equal    @{spaces}[0]    Variable name with spaces
+    Should Be Equal    @{SP a c es }[0]    Variable name with spaces
+
+Variable Names Are Underscore Insensitive
+    Should Be Equal    ${underscores}    Variable name with under scores
+ Should Be Equal ${_U N D_er_Scores__} Variable name with under scores
+    Should Be Equal    @{underscores}[0]    Variable name with under scores
+ Should Be Equal @{ _u_N_de__r _S C ores__ }[0] Variable name with under scores
+
+Assign Mark With Scalar variable
+ Should Be Equal ${ASSING MARK} This syntax works starting from 1.8
+
+Assign Mark With List variable
+    Should Be Equal    @{ASSIGN MARK}[0]    This syntax works
+    Should Be Equal    @{ASSIGN MARK}[1]    starting
+    Should Be Equal    @{ASSIGN MARK}[2]    from
+    Should Be Equal    @{ASSIGN MARK}[3]    ${1.8}
+
+Three dots on the same line should be interpreted as string
+    Should Be Equal    ${THREE DOTS}    ...
+    ${sos} =    Catenate    SEPARATOR=---    @{3DOTS LIST}
+    Should Be Equal    ${sos}    ...---...
+
+Using Scalar List Should Fail
+    Variable Should Not Exist    ${SCALAR LIST}
+
+Creating variable using non-existing variable fails
+    Variable Should Not Exist    ${NONEX 1}
+    Variable Should Not Exist    ${NONEX 2A}
+    Variable Should Not Exist    ${NONEX 2B}
+    Variable Should Not Exist    ${NONEX 3}
=======================================
--- /src/robot/new_running/builder.py   Thu May 30 07:24:17 2013
+++ /src/robot/new_running/builder.py   Thu May 30 08:53:25 2013
@@ -116,13 +116,8 @@
             self._create_step(uk, step_data)

     def _create_variable(self, suite, data):
-        if not data:
-            return
-        if data.name.startswith('$'):
-            value = data.value[0]
-        else:
-            value = data.value
-        suite.variables.create(name=data.name, value=value)
+        if data:
+            suite.variables.create(name=data.name, value=data.value)

     def _create_setup(self, parent, data):
         if data.is_active():
=======================================
--- /src/robot/new_running/model.py     Thu May 30 07:00:23 2013
+++ /src/robot/new_running/model.py     Thu May 30 08:53:25 2013
@@ -106,7 +106,7 @@

     @setter
     def variables(self, variables):
-        return model.ItemList(Variable, items=variables)
+ return model.ItemList(Variable, {'source': self.source}, items=variables)

     def configure(self, randomize_suites=False, randomize_tests=False,
                   **options):
@@ -141,10 +141,17 @@

 class Variable(object):

-    def __init__(self, name, value):
+    def __init__(self, name, value, source=None):
         # TODO: check name and value
         self.name = name
         self.value = value
+        self.source = source
+
+    def report_invalid_syntax(self, message, level='ERROR'):
+        # TODO: Remove table information here and elsewhere
+        LOGGER.write("Error in file '%s' in table 'Variables': "
+                     "Setting variable '%s' failed: %s"
+ % (self.source or '<unknown>', self.name, message), level)


 class Timeout(object):
=======================================
--- /src/robot/parsing/model.py Wed May 29 13:42:55 2013
+++ /src/robot/parsing/model.py Thu May 30 08:53:25 2013
@@ -402,7 +402,7 @@
         return OldStyleSettingAndVariableTableHeaderMatcher()

     def add(self, name, value, comment=None):
-        self.variables.append(Variable(name, value, comment))
+        self.variables.append(Variable(self, name, value, comment))

     def __iter__(self):
         return iter(self.variables)
@@ -454,7 +454,8 @@

 class Variable(object):

-    def __init__(self, name, value, comment=None):
+    def __init__(self, parent, name, value, comment=None):
+        self.parent = parent
         self.name = name.rstrip('= ')
         if name.startswith('$') and value == []:
             value = ''
@@ -480,6 +481,10 @@
     def __nonzero__(self):
         return self.has_data()

+    def report_invalid_syntax(self, message, level='ERROR'):
+ self.parent.report_invalid_syntax("Setting variable '%s' failed: %s"
+                                          % (self.name, message), level)
+

 class _WithSteps(object):

=======================================
--- /src/robot/variables/variables.py   Fri May 24 02:51:16 2013
+++ /src/robot/variables/variables.py   Thu May 30 08:53:25 2013
@@ -333,26 +333,19 @@
                 self.set(name, value)

     def set_from_variable_table(self, variables, overwrite=False):
-        def report_invalid_syntax(name, error):
-            # TODO: Error reporting is disabled with new model
-            if not hasattr(variables, 'report_invalid_syntax'):
-                return
- variables.report_invalid_syntax("Setting variable '%s' failed: %s"
-                                            % (name, unicode(error)))
         for var in variables:
             if not var:
                 continue  # TODO: Remove compatibility with old run model.
             try:
                 name, value = self._get_var_table_name_and_value(
-                    var.name, var.value, report_invalid_syntax)
+                    var.name, var.value, var.report_invalid_syntax)
                 if overwrite or not self.contains(name):
                     self.set(name, value)
             except DataError, err:
-                report_invalid_syntax(var.name, err)
+                var.report_invalid_syntax(err)

     def _get_var_table_name_and_value(self, name, value, error_reporter):
         self._validate_var_name(name)
-        # TODO: Old run gives as scalars as list, new as strings. Clean up!
         if is_scalar_var(name) and isinstance(value, basestring):
             value = [value]
         else:
@@ -433,7 +426,7 @@
         try:
             value = self._resolve(name, variables)
         except DataError, err:
-            self._error_reporter(name, err)
+            self._error_reporter(unicode(err))
             variables.pop(name)
             raise DataError("Non-existing variable '%s'." % name)
         variables[name] = value
=======================================
--- /utest/new_running/test_builder.py  Thu May 30 07:00:23 2013
+++ /utest/new_running/test_builder.py  Thu May 30 08:53:25 2013
@@ -41,9 +41,9 @@
     def test_variables(self):
         variables = build('pass_and_fail.txt').variables
         assert_equals(variables[0].name, '${LEVEL1}')
-        assert_equals(variables[0].value, 'INFO')
+        assert_equals(variables[0].value, ['INFO'])
         assert_equals(variables[1].name, '${LEVEL2}')
-        assert_equals(variables[1].value, 'DEBUG')
+        assert_equals(variables[1].value, ['DEBUG'])

     def test_user_keywords(self):
         uk = build('pass_and_fail.txt').user_keywords[0]

==============================================================================
Revision: b174ef6e9b7f
Branch:   default
Author:   Pekka Klärck
Date:     Thu May 30 08:53:30 2013
Log:      Automated merge with https://code.google.com/p/robotframework/
http://code.google.com/p/robotframework/source/detail?r=b174ef6e9b7f


--

--- You received this message because you are subscribed to the Google Groups "robotframework-commit" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to