Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_setting_input_definition_overwrites_default_values(self):
application = Application()
application.set_auto_exit(False)
application.set_catch_exceptions(False)
application.set_definition(InputDefinition([
InputOption('--custom', '-c',
InputOption.VALUE_NONE,
'Set the custom input definition.')
]))
definition = application.get_definition()
self.assertFalse(definition.has_argument('command'))
self.assertFalse(definition.has_option('help'))
self.assertFalse(definition.has_option('quiet'))
self.assertFalse(definition.has_option('verbose'))
self.assertFalse(definition.has_option('version'))
self.assertFalse(definition.has_option('ansi'))
self.assertFalse(definition.has_option('no-ansi'))
self.assertFalse(definition.has_option('no-interaction'))
def get_input_definitions(cls):
return {
"input_definition_1": InputDefinition(),
"input_definition_2": InputDefinition(
[InputArgument("argument_name", InputArgument.REQUIRED)]
),
"input_definition_3": InputDefinition(
[InputOption("option_name", "o", InputOption.VALUE_NONE)]
),
"input_definition_4": InputDefinition(
[
InputArgument("argument_name", InputArgument.REQUIRED),
InputOption("option_name", "o", InputOption.VALUE_NONE),
]
def initialize_options(self):
self.foo = InputOption('foo', 'f')
self.bar = InputOption('bar', 'b')
self.foo1 = InputOption('fooBis', 'f')
self.foo2 = InputOption('foo', 'p')
self.multi = InputOption('multi', 'm|mm|mmm')
class NoConfigureCommand(Command):
name = 'no:configure'
description = 'description'
help = 'help'
arguments = [
InputArgument('foo'),
InputArgument('bar')
]
options = [
InputOption('baz', 'z'),
InputOption('bazz', 'Z')
]
def execute(self, input_, output_):
output_.writeln('execute called')
def interact(self, input_, output_):
output_.writeln('interact called')
InputDefinition([
InputOption('foo', 'f', InputOption.VALUE_REQUIRED)
]),
'The "--foo" option requires a value.'
),
(
['cli.py', '-f'],
InputDefinition([
InputOption('foo', 'f', InputOption.VALUE_REQUIRED)
]),
'The "--foo" option requires a value.'
),
(
['cli.py', '-ffoo'],
InputDefinition([
InputOption('foo', 'f', InputOption.VALUE_NONE)
]),
'The "-o" option does not exist.'
),
(
['cli.py', '--foo=bar'],
InputDefinition([
InputOption('foo', 'f', InputOption.VALUE_NONE)
]),
'The "--foo" option does not accept a value.'
),
(
['cli.py', 'foo', 'bar'],
InputDefinition(),
'Too many arguments.'
),
(
def provider_invalid_input(self):
return [
(
[('foo', 'bar')],
InputDefinition([
InputArgument('name')
]),
'The "foo" argument does not exist.'
),
(
['--foo'],
InputDefinition([
InputOption('foo', 'f', InputOption.VALUE_REQUIRED)
]),
'The "--foo" option requires a value.'
),
(
[('--foo', 'foo')],
InputDefinition(),
'The "--foo" option does not exist.'
),
(
[('-f', 'foo')],
InputDefinition(),
'The "-f" option does not exist.'
),
def get_input_definitions(cls):
return {
"input_definition_1": InputDefinition(),
"input_definition_2": InputDefinition(
[InputArgument("argument_name", InputArgument.REQUIRED)]
),
"input_definition_3": InputDefinition(
[InputOption("option_name", "o", InputOption.VALUE_NONE)]
),
"input_definition_4": InputDefinition(
[
InputArgument("argument_name", InputArgument.REQUIRED),
InputOption("option_name", "o", InputOption.VALUE_NONE),
]
['cli.py', '-f', 'bar'],
[InputOption('foo', 'f', InputOption.VALUE_REQUIRED)],
{'foo': 'bar'},
'.parse() parses short options with a required value (with a space separator)'
),
(
['cli.py', '-f', ''],
[InputOption('foo', 'f', InputOption.VALUE_OPTIONAL)],
{'foo': None},
'.parse() parses short options with an optional empty value'
),
(
['cli.py', '-f', '', 'foo'],
[
InputArgument('name'),
InputOption('foo', 'f', InputOption.VALUE_OPTIONAL)
],
{'foo': None},
'.parse() parses short options with an optional empty value followed by an argument'
),
(
['cli.py', '-f', '', '-b'],
[
InputOption('foo', 'f', InputOption.VALUE_OPTIONAL),
InputOption('bar', 'b')
],
{'foo': None, 'bar': True},
'.parse() parses short options with an optional empty value followed by an option'
),
(
['cli.py', '-f', '-b', 'foo'],
[
def test_parse_list_option(self):
input_ = ArgvInput(['cli.py', '--name=foo', '--name=bar', '--name=baz'])
input_.bind(
InputDefinition([
InputOption('name', None, InputOption.VALUE_OPTIONAL | InputOption.VALUE_IS_LIST)
])
)
self.assertEqual(
{'name': ['foo', 'bar', 'baz']},
input_.get_options()
)
input_ = ArgvInput(['cli.py', '--name', 'foo', '--name', 'bar', '--name', 'baz'])
input_.bind(
InputDefinition([
InputOption('name', None, InputOption.VALUE_OPTIONAL | InputOption.VALUE_IS_LIST)
])
)
self.assertEqual(
{'name': ['foo', 'bar', 'baz']},
input_.get_options()
)
input_ = ArgvInput(['cli.py', '--name=foo', '--name=bar', '--name='])
input_.bind(
InputDefinition([
InputOption('name', None, InputOption.VALUE_OPTIONAL | InputOption.VALUE_IS_LIST)
])
)
self.assertEqual(
{'name': ['foo', 'bar', None]},
input_.get_options()
{'foo': None, 'bar': True},
'.parse() parses long options with an optional value which is not present'
),
(
['cli.py', '-fb'],
[
InputOption('foo', 'f'),
InputOption('bar', 'b')
],
{'foo': True, 'bar': True},
'.parse() parses short options when they are aggregated as a single one'
),
(
['cli.py', '-fb', 'bar'],
[
InputOption('foo', 'f'),
InputOption('bar', 'b', InputOption.VALUE_REQUIRED)
],
{'foo': True, 'bar': 'bar'},
'.parse() parses short options when they are aggregated as a single one '
'and the last one has a required value'
),
(
['cli.py', '-fb', 'bar'],
[
InputOption('foo', 'f'),
InputOption('bar', 'b', InputOption.VALUE_OPTIONAL)
],
{'foo': True, 'bar': 'bar'},
'.parse() parses short options when they are aggregated as a single one '
'and the last one has an optional value'
),