Skip to content

Commit

Permalink
Test named args and arg conversion with listeners and modifiers.
Browse files Browse the repository at this point in the history
Functionality has already been implemented, this commit just adds
acceptance tests. robotframework#3809
  • Loading branch information
pekkaklarck committed Dec 22, 2020
1 parent 4d9ad58 commit 364da4a
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 35 deletions.
6 changes: 4 additions & 2 deletions atest/robot/cli/model_modifiers/ModelModifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,17 @@

class ModelModifier(SuiteVisitor):

def __init__(self, *tags):
def __init__(self, *tags, **extra):
if extra:
tags += tuple('%s-%s' % item for item in extra.items())
self.config = tags or ('visited',)

def start_suite(self, suite):
config = self.config
if config[0] == 'FAIL':
raise RuntimeError(' '.join(self.config[1:]))
elif config[0] == 'CREATE':
suite.tests.create(**dict(conf.split('=', 1) for conf in config[1:]))
suite.tests.create(**dict(conf.split('-', 1) for conf in config[1:]))
self.config = []
elif config == ('REMOVE', 'ALL', 'TESTS'):
suite.tests = []
Expand Down
9 changes: 9 additions & 0 deletions atest/robot/cli/model_modifiers/modifier_resource.robot
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@ ${TEST DATA} misc/pass_and_fail.robot
${LOG} %{TEMPDIR}/modified_log.html

*** Keywords ***
Output and log should be modified
[Arguments] @{added tags}
Output should be modified @{added tags}
Log should be modified @{added tags}

Output and log should not be modified
Output should not be modified
Log should not be modified

Output should be modified
[Arguments] @{added tags}
Check Test Tags Pass force pass @{added tags}
Expand Down
23 changes: 8 additions & 15 deletions atest/robot/cli/model_modifiers/pre_rebot.robot
Original file line number Diff line number Diff line change
Expand Up @@ -10,41 +10,34 @@ ${MODIFIED OUTPUT} %{TEMPDIR}/pre_rebot_modified.xml
*** Test Cases ***
Modifier as path
Run Rebot --prerebotmodifier ${CURDIR}/ModelModifier.py -l ${LOG} ${MODIFIED OUTPUT}
Output should be modified visited
Log should be modified visited
Output and log should be modified visited

Modifier as name
Run Rebot --prerebotmodifier ModelModifier --pythonpath ${CURDIR} -l ${LOG} ${MODIFIED OUTPUT}
Output should be modified visited
Log should be modified visited
Output and log should be modified visited

Modifier with arguments separated with ':'
Run Rebot --PreRebotModifier ${CURDIR}/ModelModifier.py:new:tags -l ${LOG} ${MODIFIED OUTPUT}
Check Test Tags Pass force new pass tags
Output should be modified new tags
Log should be modified new tags
Run Rebot --PreRebotModifier ${CURDIR}/ModelModifier.py:new:tags:named=tag -l ${LOG} ${MODIFIED OUTPUT}
Output and log should be modified new tags named-tag

Modifier with arguments separated with ';'
Run Rebot --prerebot "ModelModifier;1;2;3" --prere "ModelModifier;4;5" -P ${CURDIR} -l ${LOG} ${MODIFIED OUTPUT}
Output should be modified 1 2 3 4 5
Log should be modified 1 2 3 4 5
Run Rebot --prerebot "ModelModifier;1;2;3" --prere "ModelModifier;4;5;n=t" -P ${CURDIR} -l ${LOG} ${MODIFIED OUTPUT}
Output and log should be modified 1 2 3 4 5 n-t

Non-existing modifier
Run Rebot --prerebotmod NobodyHere -l ${LOG} ${MODIFIED OUTPUT}
${quote} = Set Variable If ${INTERPRETER.is_py3} ' ${EMPTY}
Stderr Should Match
... ? ERROR ? Importing model modifier 'NobodyHere' failed: *Error:
... No module named ${quote}NobodyHere${quote}\nTraceback (most recent call last):\n*
Output should not be modified
Log should not be modified
Output and log should not be modified

Invalid modifier
Run Rebot --prerebotmodifier ${CURDIR}/ModelModifier.py:FAIL:Message -l ${LOG} ${MODIFIED OUTPUT}
Stderr Should Start With
... [ ERROR ] Executing model modifier 'ModelModifier' failed:
... Message\nTraceback (most recent call last):\n
Output should not be modified
Log should not be modified
Output and log should not be modified

Error if all tests removed
${result} = Run Rebot Without Processing Output
Expand Down
22 changes: 8 additions & 14 deletions atest/robot/cli/model_modifiers/pre_run.robot
Original file line number Diff line number Diff line change
Expand Up @@ -4,40 +4,34 @@ Resource modifier_resource.robot
*** Test Cases ***
Modifier as path
Run Tests --prerunmodifier ${CURDIR}/ModelModifier.py -l ${LOG} ${TEST DATA}
Output should be modified visited
Log should be modified visited
Output and log should be modified visited

Modifier as name
Run Tests --prerunmodifier ModelModifier --pythonpath ${CURDIR} -l ${LOG} ${TEST DATA}
Output should be modified visited
Log should be modified visited
Output and log should be modified visited

Modifier with arguments separated with ':'
Run Tests --PreRunModifier ${CURDIR}/ModelModifier.py:new:tags -l ${LOG} ${TEST DATA}
Output should be modified new tags
Log should be modified new tags
Run Tests --PreRunModifier ${CURDIR}/ModelModifier.py:new:tags:named=tag -l ${LOG} ${TEST DATA}
Output and log should be modified new tags named-tag

Modifier with arguments separated with ';'
Run Tests --prerun "ModelModifier;1;2;3" --preru "ModelModifier;4;5" -P ${CURDIR} -l ${LOG} ${TEST DATA}
Output should be modified 1 2 3 4 5
Log should be modified 1 2 3 4 5
Run Tests --prerun "ModelModifier;1;2;3" --preru "ModelModifier;4;5;n=t" -P ${CURDIR} -l ${LOG} ${TEST DATA}
Output and log should be modified 1 2 3 4 5 n-t

Non-existing modifier
Run Tests --prerunmodifier NobodyHere -l ${LOG} ${TEST DATA}
${quote} = Set Variable If ${INTERPRETER.is_py3} ' ${EMPTY}
Stderr Should Match
... ? ERROR ? Importing model modifier 'NobodyHere' failed: *Error:
... No module named ${quote}NobodyHere${quote}\nTraceback (most recent call last):\n*
Output should not be modified
Log should not be modified
Output and log should not be modified

Invalid modifier
Run Tests --prerunmodifier ${CURDIR}/ModelModifier.py:FAIL:Message -l ${LOG} ${TEST DATA}
Stderr Should Start With
... [ ERROR ] Executing model modifier 'ModelModifier' failed:
... Message\nTraceback (most recent call last):\n
Output should not be modified
Log should not be modified
Output and log should not be modified

Error if all tests removed
${result} = Run Tests Without Processing Output
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,15 @@ Python Module Listener
module module_listener module_listener

Listener With Arguments
class listeners.WithArgs listeners 5
class listeners.WithArgs listeners 6
[Teardown] Check Listener File ${ARGS_FILE}
... I got arguments 'value' and 'default'
... I got arguments 'a1' and 'a;2'
... I got arguments 'semi' and 'colons:here'
... I got arguments 'named' and 'args'

Listener With Argument Conversion
class listeners.WithArgConversion listeners 1

Listener With Path
class ${LISTENERS}${/}ListenAll.py ListenAll
Expand Down Expand Up @@ -59,6 +63,8 @@ Run Tests With Listeners
... --listener listeners.WithArgs:value
... --listener "listeners.WithArgs:a1:a;2"
... --listener "listeners.WithArgs;semi;colons:here"
... --listener listeners.WithArgs:arg2=args:arg1=named
... --listener listeners.WithArgConversion:42:yes
... --listener ${LISTENERS}${/}ListenAll.py:%{TEMPDIR}${/}${ALL_FILE2}
... --listener listeners.WithArgs
... --listener listeners.WithArgs:1:2:3
Expand Down
21 changes: 18 additions & 3 deletions atest/testresources/listeners/listeners.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os

from robot.libraries.BuiltIn import BuiltIn
from robot.utils import PY3


class ListenSome:
Expand All @@ -25,9 +26,23 @@ class WithArgs(object):

def __init__(self, arg1, arg2='default'):
outpath = os.path.join(os.getenv('TEMPDIR'), 'listener_with_args.txt')
outfile = open(outpath, 'a')
outfile.write("I got arguments '%s' and '%s'\n" % (arg1, arg2))
outfile.close()
with open(outpath, 'a') as outfile:
outfile.write("I got arguments '%s' and '%s'\n" % (arg1, arg2))


class WithArgConversion(object):
ROBOT_LISTENER_API_VERSION = '2'

def __init__(self, integer, boolean=False):
assert integer == '42'
assert boolean is True

if PY3:
exec('''
def __init__(self, integer: int, boolean=False):
assert integer == 42
assert boolean is True
''')


class SuiteAndTestCounts(object):
Expand Down

0 comments on commit 364da4a

Please sign in to comment.