2 new revisions:
Revision: 6201903f88d8
Branch: default
Author: Pekka Klärck
Date: Wed Nov 6 11:50:23 2013 UTC
Log: argumentparser: Support reading default values from environ...
http://code.google.com/p/robotframework/source/detail?r=6201903f88d8
Revision: bf5d4626486b
Branch: default
Author: Pekka Klärck
Date: Wed Nov 6 12:38:04 2013 UTC
Log: Support ROBOT_OPTIONS and REBOT_OPTIONS...
http://code.google.com/p/robotframework/source/detail?r=bf5d4626486b
==============================================================================
Revision: 6201903f88d8
Branch: default
Author: Pekka Klärck
Date: Wed Nov 6 11:50:23 2013 UTC
Log: argumentparser: Support reading default values from environ
Update issue 1566
Status: Started
Owner: pekka.klarck
ArgumentParser now supports reading default values from environment
variables.
Next up: Take this support into use w/ Robot and Rebot.
http://code.google.com/p/robotframework/source/detail?r=6201903f88d8
Modified:
/src/robot/utils/argumentparser.py
/utest/utils/test_argumentparser.py
=======================================
--- /src/robot/utils/argumentparser.py Fri Sep 6 10:10:29 2013 UTC
+++ /src/robot/utils/argumentparser.py Wed Nov 6 11:50:23 2013 UTC
@@ -49,7 +49,8 @@
def __init__(self, usage, name=None, version=None, arg_limits=None,
validator=None, auto_help=True, auto_version=True,
- auto_escape=True, auto_pythonpath=True,
auto_argumentfile=True):
+ auto_escape=True, auto_pythonpath=True,
auto_argumentfile=True,
+ from_environ=None):
"""Available options and tool name are read from the usage.
Tool name is got from the first row of the usage. It is either the
@@ -67,6 +68,7 @@
self._auto_escape = auto_escape
self._auto_pythonpath = auto_pythonpath
self._auto_argumentfile = auto_argumentfile
+ self._from_environ = from_environ
self._short_opts = ''
self._long_opts = []
self._multi_opts = []
@@ -121,6 +123,8 @@
amount of horizontal space as <---ESCAPES--->. Both help and
version
are wrapped to Information exception.
"""
+ if self._from_environ:
+ args_list = os.getenv(self._from_environ, '').split() +
args_list
args_list = [decode_from_system(a) for a in args_list]
if self._auto_argumentfile:
args_list = self._process_possible_argfile(args_list)
=======================================
--- /utest/utils/test_argumentparser.py Wed Feb 8 08:34:53 2012 UTC
+++ /utest/utils/test_argumentparser.py Wed Nov 6 11:50:23 2013 UTC
@@ -2,7 +2,8 @@
import os
from robot.utils.argumentparser import ArgumentParser
-from robot.utils.asserts import *
+from robot.utils.asserts import (assert_equals, assert_raises,
+ assert_raises_with_msg, assert_true)
from robot.errors import Information, DataError, FrameworkError
from robot.version import get_full_version
@@ -218,6 +219,52 @@
'escape': 'xxx', 'argumentfile': None})
+class TestDefaultsFromEnvironmentVariables(unittest.TestCase):
+
+ def setUp(self):
+ os.environ['ROBOT_TEST_OPTIONS'] = '-t --value default -m1
--multi=2'
+ self.ap = ArgumentParser('''Options:
+ -t --toggle
+ -v --value value
+ -m --multi multi *
+''', from_environ='ROBOT_TEST_OPTIONS')
+
+ def tearDown(self):
+ os.environ.pop('ROBOT_TEST_OPTIONS')
+
+ def test_toggle(self):
+ opts, args = self.ap.parse_args([])
+ assert_equals(opts['toggle'], True)
+ opts, args = self.ap.parse_args(['--toggle'])
+ assert_equals(opts['toggle'], False)
+
+ def test_value(self):
+ opts, args = self.ap.parse_args([])
+ assert_equals(opts['value'], 'default')
+ opts, args = self.ap.parse_args(['--value', 'given'])
+ assert_equals(opts['value'], 'given')
+
+ def test_multi_value(self):
+ opts, args = self.ap.parse_args([])
+ assert_equals(opts['multi'], ['1', '2'])
+ opts, args = self.ap.parse_args(['-m3', '--multi', '4'])
+ assert_equals(opts['multi'], ['1', '2', '3', '4'])
+
+ def test_arguments(self):
+ os.environ['ROBOT_TEST_OPTIONS'] = '-o opt arg1 arg2'
+ ap = ArgumentParser('Usage:\n -o --opt value',
+ from_environ='ROBOT_TEST_OPTIONS')
+ opts, args = ap.parse_args([])
+ assert_equals(opts['opt'], 'opt')
+ assert_equals(args, ['arg1', 'arg2'])
+
+ def test_environment_variable_not_set(self):
+ ap = ArgumentParser('Usage:\n -o --opt value',
from_environ='NOT_SET')
+ opts, args = ap.parse_args(['arg'])
+ assert_equals(opts['opt'], None)
+ assert_equals(args, ['arg'])
+
+
class TestArgumentValidation(unittest.TestCase):
def test_check_args_with_correct_args(self):
==============================================================================
Revision: bf5d4626486b
Branch: default
Author: Pekka Klärck
Date: Wed Nov 6 12:38:04 2013 UTC
Log: Support ROBOT_OPTIONS and REBOT_OPTIONS
Update issue 1566
Implemented and tested. Documentation in --help and UG missing.
http://code.google.com/p/robotframework/source/detail?r=bf5d4626486b
Added:
/atest/robot/cli/rebot/REBOT_OPTIONS.txt
/atest/robot/cli/runner/ROBOT_OPTIONS.txt
Modified:
/atest/robot/cli/rebot/rebot_cli_resource.txt
/src/robot/rebot.py
/src/robot/run.py
/src/robot/utils/application.py
/src/robot/utils/argumentparser.py
/utest/utils/test_argumentparser.py
=======================================
--- /dev/null
+++ /atest/robot/cli/rebot/REBOT_OPTIONS.txt Wed Nov 6 12:38:04 2013 UTC
@@ -0,0 +1,22 @@
+*** Settings ***
+Force Tags regression pybot jybot
+Resource rebot_cli_resource.txt
+Suite Setup Run Keywords
+... Run tests to create input file for Rebot ${TESTS}
${INPUT} AND
+... Set Environment Variable REBOT_OPTIONS --name
Default --settag default
+Suite Teardown Delete Environment Variable REBOT_OPTIONS
+
+*** Variables ***
+${TESTS} misc/pass_and_fail.txt
+${INPUT} %{TEMPDIR}${/}rebot_options.xml
+
+*** Test Cases ***
+Use defaults
+ Run Rebot ${EMPTY} ${INPUT}
+ Should Be Equal ${SUITE.name} Default
+ Check Test Tags Pass force pass default
+
+Override defaults
+ Run Rebot -N Given -G given ${INPUT}
+ Should Be Equal ${SUITE.name} Given
+ Check Test Tags Pass force pass default given
=======================================
--- /dev/null
+++ /atest/robot/cli/runner/ROBOT_OPTIONS.txt Wed Nov 6 12:38:04 2013 UTC
@@ -0,0 +1,19 @@
+*** Settings ***
+Force Tags regression pybot jybot
+Resource cli_resource.txt
+Suite Setup Set Environment Variable ROBOT_OPTIONS --name
Default --settag default --dryrun
+Suite Teardown Delete Environment Variable ROBOT_OPTIONS
+
+*** Test Cases ***
+Use defaults
+ Run Tests ${EMPTY} misc/pass_and_fail.txt
+ Should Be Equal ${SUITE.name} Default
+ ${tc} = Check Test Tags Pass force pass default
+ Should Be Equal ${tc.kws[0].kws[0].status} NOT_RUN
+
+
+Override defaults
+ Run Tests -N Given -G given --dryrun misc/pass_and_fail.txt
+ Should Be Equal ${SUITE.name} Given
+ ${tc} = Check Test Tags Pass force pass default given
+ Should Be Equal ${tc.kws[0].kws[0].status} PASS
=======================================
--- /atest/robot/cli/rebot/rebot_cli_resource.txt Wed Sep 12 22:17:39 2012
UTC
+++ /atest/robot/cli/rebot/rebot_cli_resource.txt Wed Nov 6 12:38:04 2013
UTC
@@ -14,8 +14,9 @@
*** Keywords ***
Run tests to create input file for Rebot
- Run Tests Without Processing Output --loglevel TRACE ${TESTFILE}
- Move File ${OUTFILE} ${MYINPUT}
+ [Arguments] ${tests}=${TESTFILE} ${input}=${MYINPUT}
+ Run Tests Without Processing Output --loglevel TRACE ${tests}
+ Move File ${OUTFILE} ${input}
Create Directory ${MYOUTDIR}
Remove temporary files
=======================================
--- /src/robot/rebot.py Tue Nov 5 15:29:59 2013 UTC
+++ /src/robot/rebot.py Wed Nov 6 12:38:04 2013 UTC
@@ -307,7 +307,8 @@
class Rebot(RobotFramework):
def __init__(self):
- Application.__init__(self, USAGE, arg_limits=(1,), logger=LOGGER)
+ Application.__init__(self, USAGE, arg_limits=(1,),
+ env_options='REBOT_OPTIONS', logger=LOGGER)
def main(self, datasources, **options):
settings = RebotSettings(options)
=======================================
--- /src/robot/run.py Tue Nov 5 15:29:59 2013 UTC
+++ /src/robot/run.py Wed Nov 6 12:38:04 2013 UTC
@@ -381,7 +381,8 @@
class RobotFramework(Application):
def __init__(self):
- Application.__init__(self, USAGE, arg_limits=(1,), logger=LOGGER)
+ Application.__init__(self, USAGE, arg_limits=(1,),
+ env_options='ROBOT_OPTIONS', logger=LOGGER)
def main(self, datasources, **options):
settings = RobotSettings(options)
=======================================
--- /src/robot/utils/application.py Fri Jun 7 10:53:03 2013 UTC
+++ /src/robot/utils/application.py Wed Nov 6 12:38:04 2013 UTC
@@ -27,9 +27,9 @@
class Application(object):
def __init__(self, usage, name=None, version=None, arg_limits=None,
- logger=None, **auto_options):
+ env_options=None, logger=None, **auto_options):
self._ap = ArgumentParser(usage, name, version, arg_limits,
- self.validate, **auto_options)
+ self.validate, env_options,
**auto_options)
self._logger = logger or DefaultLogger()
def main(self, arguments, **options):
=======================================
--- /src/robot/utils/argumentparser.py Wed Nov 6 11:50:23 2013 UTC
+++ /src/robot/utils/argumentparser.py Wed Nov 6 12:38:04 2013 UTC
@@ -48,9 +48,9 @@
''', re.VERBOSE)
def __init__(self, usage, name=None, version=None, arg_limits=None,
- validator=None, auto_help=True, auto_version=True,
- auto_escape=True, auto_pythonpath=True,
auto_argumentfile=True,
- from_environ=None):
+ validator=None, env_options=None, auto_help=True,
+ auto_version=True, auto_escape=True, auto_pythonpath=True,
+ auto_argumentfile=True):
"""Available options and tool name are read from the usage.
Tool name is got from the first row of the usage. It is either the
@@ -68,7 +68,7 @@
self._auto_escape = auto_escape
self._auto_pythonpath = auto_pythonpath
self._auto_argumentfile = auto_argumentfile
- self._from_environ = from_environ
+ self._env_options = env_options
self._short_opts = ''
self._long_opts = []
self._multi_opts = []
@@ -123,8 +123,8 @@
amount of horizontal space as <---ESCAPES--->. Both help and
version
are wrapped to Information exception.
"""
- if self._from_environ:
- args_list = os.getenv(self._from_environ, '').split() +
args_list
+ if self._env_options:
+ args_list = os.getenv(self._env_options, '').split() +
args_list
args_list = [decode_from_system(a) for a in args_list]
if self._auto_argumentfile:
args_list = self._process_possible_argfile(args_list)
=======================================
--- /utest/utils/test_argumentparser.py Wed Nov 6 11:50:23 2013 UTC
+++ /utest/utils/test_argumentparser.py Wed Nov 6 12:38:04 2013 UTC
@@ -227,7 +227,7 @@
-t --toggle
-v --value value
-m --multi multi *
-''', from_environ='ROBOT_TEST_OPTIONS')
+''', env_options='ROBOT_TEST_OPTIONS')
def tearDown(self):
os.environ.pop('ROBOT_TEST_OPTIONS')
@@ -253,13 +253,13 @@
def test_arguments(self):
os.environ['ROBOT_TEST_OPTIONS'] = '-o opt arg1 arg2'
ap = ArgumentParser('Usage:\n -o --opt value',
- from_environ='ROBOT_TEST_OPTIONS')
+ env_options='ROBOT_TEST_OPTIONS')
opts, args = ap.parse_args([])
assert_equals(opts['opt'], 'opt')
assert_equals(args, ['arg1', 'arg2'])
def test_environment_variable_not_set(self):
- ap = ArgumentParser('Usage:\n -o --opt value',
from_environ='NOT_SET')
+ ap = ArgumentParser('Usage:\n -o --opt value',
env_options='NOT_SET')
opts, args = ap.parse_args(['arg'])
assert_equals(opts['opt'], None)
assert_equals(args, ['arg'])
--
---
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.