Skip to content

Commit

Permalink
Test VAR a bit more thoroughly with listeners.
Browse files Browse the repository at this point in the history
Data changes required changes also in unrelated tests.
  • Loading branch information
pekkaklarck committed Nov 2, 2023
1 parent 624d6bf commit 42ffe99
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 24 deletions.
2 changes: 1 addition & 1 deletion atest/robot/cli/model_modifiers/ModelModifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def start_for_iteration(self, iteration):
iteration.assign['${x}'] = 'new'

def start_if_branch(self, branch):
if branch.condition == "'IF' == 'WRONG'":
if branch.condition == "'${x}' == 'wrong'":
branch.condition = 'True'
# With Robot
if not hasattr(branch, 'status'):
Expand Down
8 changes: 4 additions & 4 deletions atest/robot/cli/model_modifiers/pre_rebot.robot
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@ Modify FOR
Modify IF
[Setup] Should Be Equal ${PREV TEST NAME} Modify FOR
${tc} = Check Test Case If structure
Should Be Equal ${tc.body[0].body[0].condition} modified
Should Be Equal ${tc.body[0].body[0].status} PASS
Should Be Equal ${tc.body[0].body[0].body[0].args[0]} got here!
Should Be Equal ${tc.body[0].body[1].status} PASS
Should Be Equal ${tc.body[1].body[0].condition} modified
Should Be Equal ${tc.body[1].body[0].status} PASS
Should Be Equal ${tc.body[1].body[0].body[0].args[0]} got here!
Should Be Equal ${tc.body[1].body[1].status} PASS

*** Keywords ***
Modify FOR and IF
Expand Down
2 changes: 1 addition & 1 deletion atest/robot/cli/model_modifiers/pre_run.robot
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,4 @@ Modify FOR and IF
Check Log Message ${tc.body[0].body[1].body[0].msgs[0]} is
Check Log Message ${tc.body[0].body[2].body[0].msgs[0]} modified!
${tc} = Check Test Case If structure
Check Log Message ${tc.body[0].body[0].body[0].msgs[0]} going here!
Check Log Message ${tc.body[1].body[0].body[0].msgs[0]} going here!
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ Errors Are Removed In All Mode
IF/ELSE in All mode
[Setup] Previous test should have passed Errors Are Removed In All Mode
${tc} = Check Test Case IF structure
Length Should Be ${tc.body} 1
Length Should Be ${tc.body[0].body} 3
IF Branch Should Be Empty ${tc.body[0].body[0]} IF 'IF' == 'WRONG'
IF Branch Should Be Empty ${tc.body[0].body[1]} ELSE IF 'ELSE IF' == 'ELSE IF'
IF Branch Should Be Empty ${tc.body[0].body[2]} ELSE
Length Should Be ${tc.body} 2
Length Should Be ${tc.body[1].body} 3
IF Branch Should Be Empty ${tc.body[1].body[0]} IF '\${x}' == 'wrong'
IF Branch Should Be Empty ${tc.body[1].body[1]} ELSE IF '\${x}' == 'value'
IF Branch Should Be Empty ${tc.body[1].body[2]} ELSE

FOR in All mode
[Setup] Previous test should have passed IF/ELSE in All mode
Expand Down
11 changes: 6 additions & 5 deletions atest/robot/output/listener_interface/using_run_keyword.robot
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,12 @@ In start_keyword and end_keyword with WHILE

In start_keyword and end_keyword with IF/ELSE
${tc} = Check Test Case IF structure
Should Be Equal ${tc.body[1].type} IF/ELSE ROOT
Length Should Be ${tc.body[1].body} 3 # Listener is not called with root
Validate IF branch ${tc.body[1].body[0]} IF NOT RUN # but is called with unexecuted branches.
Validate IF branch ${tc.body[1].body[1]} ELSE IF PASS
Validate IF branch ${tc.body[1].body[2]} ELSE NOT RUN
Should Be Equal ${tc.body[1].type} VAR
Should Be Equal ${tc.body[2].type} IF/ELSE ROOT
Length Should Be ${tc.body[2].body} 3 # Listener is not called with root
Validate IF branch ${tc.body[2].body[0]} IF NOT RUN # but is called with unexecuted branches.
Validate IF branch ${tc.body[2].body[1]} ELSE IF PASS
Validate IF branch ${tc.body[2].body[2]} ELSE NOT RUN

In start_keyword and end_keyword with TRY/EXCEPT
${tc} = Check Test Case Everything
Expand Down
4 changes: 2 additions & 2 deletions atest/testdata/misc/for_loops.robot
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
*** Variables ***
@{ANIMALS} cat dog horse
@{FINNISH} kissa koira hevonen

*** Test Cases ***
FOR
Expand All @@ -22,6 +21,7 @@ FOR IN ENUMERATE
END

FOR IN ZIP
FOR ${en} ${fi} IN ZIP ${ANIMALS} ${FINNISH} mode=LONGEST fill=-
VAR @{finnish} kissa koira hevonen
FOR ${en} ${fi} IN ZIP ${ANIMALS} ${finnish} mode=LONGEST fill=-
Log ${en} is ${fi} in Finnish
END
5 changes: 3 additions & 2 deletions atest/testdata/misc/if_else.robot
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
*** Test Cases ***
IF structure
IF 'IF' == 'WRONG'
VAR ${x} value
IF '${x}' == 'wrong'
Fail not going here
ELSE IF 'ELSE IF' == 'ELSE IF'
ELSE IF '${x}' == 'value'
Log else if branch
ELSE
Fail not going here
Expand Down
3 changes: 2 additions & 1 deletion atest/testresources/listeners/VerifyAttributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
TEST = 'id longname tags template originalname source lineno '
KW = 'kwname libname args assign tags type lineno source status '
KW_TYPES = {'FOR': 'variables flavor values',
'WHILE': 'condition limit on_limit_message',
'WHILE': 'condition limit on_limit on_limit_message',
'IF': 'condition',
'ELSE IF': 'condition',
'EXCEPT': 'patterns pattern_type variable',
Expand All @@ -29,6 +29,7 @@
'values': (list, dict),
'condition': str,
'limit': (str, type(None)),
'on_limit': (str, type(None)),
'on_limit_message': (str, type(None)),
'patterns': (str, list),
'pattern_type': (str, type(None)),
Expand Down
8 changes: 5 additions & 3 deletions atest/testresources/listeners/listeners.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,19 +73,21 @@ def start_keyword(self, name, attrs):
% (attrs['type'], expected))

def _get_expected_type(self, kwname, libname, args, source, lineno, **ignore):
if kwname.startswith(('${x} ', '@{finnish} ')):
return 'VAR'
if ' IN ' in kwname:
return 'FOR'
if ' = ' in kwname:
return 'ITERATION'
if not args:
if "'IF' == 'WRONG'" in kwname or '${i} == 9' in kwname:
if "'${x}' == 'wrong'" in kwname or '${i} == 9' in kwname:
return 'IF'
if "'ELSE IF' == 'ELSE IF'" in kwname:
if "'${x}' == 'value'" in kwname:
return 'ELSE IF'
if kwname == '':
source = os.path.basename(source)
if source == 'for_loops.robot':
return 'BREAK' if lineno == 14 else 'CONTINUE'
return 'BREAK' if lineno == 13 else 'CONTINUE'
return 'ELSE'
expected = args[0] if libname == 'BuiltIn' else kwname
return {'Suite Setup': 'SETUP', 'Suite Teardown': 'TEARDOWN',
Expand Down

0 comments on commit 42ffe99

Please sign in to comment.