Revision: 4c61dd1a8aa2
Branch: default
Author: Pekka Klärck
Date: Fri Nov 29 08:26:55 2013 UTC
Log: Added tests for utils.ArgumentParser.parse_args getting non-list
args.
Update issue 1591
Added unit tests for parse_args being called with non-list args. Now that
we have tests, no comments are needed.
Also renamed args_list -> args.
http://code.google.com/p/robotframework/source/detail?r=4c61dd1a8aa2
Modified:
/src/robot/utils/argumentparser.py
/utest/utils/test_argumentparser.py
=======================================
--- /src/robot/utils/argumentparser.py Thu Nov 28 12:25:23 2013 UTC
+++ /src/robot/utils/argumentparser.py Fri Nov 29 08:26:55 2013 UTC
@@ -78,12 +78,12 @@
self._expected_args = ()
self._create_options(usage)
- def parse_args(self, args_list):
+ def parse_args(self, args):
"""Parse given arguments and return options and positional
arguments.
Arguments must be given as a list and are typically sys.argv[1:].
- Options are retuned as a dictionary where long options are keys.
Value
+ Options are returned as a dictionary where long options are keys.
Value
is a string for those options that can be given only one time (if
they
are given multiple times the last value is used) or None if the
option
is not used at all. Value for options that can be given multiple
times
@@ -124,12 +124,11 @@
are wrapped to Information exception.
"""
if self._env_options:
- # args_list is java String[] when using standalone jar
- args_list = os.getenv(self._env_options, '').split() +
list(args_list)
- args_list = [decode_from_system(a) for a in args_list]
+ args = os.getenv(self._env_options, '').split() + list(args)
+ args = [decode_from_system(a) for a in args]
if self._auto_argumentfile:
- args_list = self._process_possible_argfile(args_list)
- opts, args = self._parse_args(args_list)
+ args = self._process_possible_argfile(args)
+ opts, args = self._parse_args(args)
opts, args = self._handle_special_options(opts, args)
self._arg_limit_validator(args)
if self._validator:
=======================================
--- /utest/utils/test_argumentparser.py Wed Nov 6 12:38:04 2013 UTC
+++ /utest/utils/test_argumentparser.py Fri Nov 29 08:26:55 2013 UTC
@@ -218,6 +218,23 @@
assert_equals(opts, {'help': True, 'version': True, 'pythonpath':
None,
'escape': 'xxx', 'argumentfile': None})
+ def test_non_list_args(self):
+ ap = ArgumentParser('''Options:
+ -t --toggle
+ -v --value value
+ -m --multi multi *
+''')
+ opts, args = ap.parse_args(())
+ assert_equals(opts, {'toggle': False,
+ 'value': None,
+ 'multi': []})
+ assert_equals(args, [])
+ opts, args =
ap.parse_args(('-t', '-v', 'xxx', '-m', '1', '-m2', 'arg'))
+ assert_equals(opts, {'toggle': True,
+ 'value': 'xxx',
+ 'multi': ['1', '2']})
+ assert_equals(args, ['arg'])
+
class TestDefaultsFromEnvironmentVariables(unittest.TestCase):
@@ -264,6 +281,18 @@
assert_equals(opts['opt'], None)
assert_equals(args, ['arg'])
+ def test_non_list_args(self):
+ opts, args = self.ap.parse_args(())
+ assert_equals(opts, {'toggle': True,
+ 'value': 'default',
+ 'multi': ['1', '2']})
+ assert_equals(args, [])
+ opts, args =
self.ap.parse_args(('-t', '-v', 'given', '-m3', 'a', 'b'))
+ assert_equals(opts, {'toggle': False,
+ 'value': 'given',
+ 'multi': ['1', '2', '3']})
+ assert_equals(args, ['a', 'b'])
+
class TestArgumentValidation(unittest.TestCase):
--
---
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.