Example #1
0
 def test_multi_value_no_resolve(self):
     # test no resolve
     options = core.Options(
         arguments.MultiValueArgument('myarg', resolve=False))
     argparser = parser.Parser(options)
     dummy_tokens = DummyTokens('myval', "'myval2'")
     kwargs, blocks = argparser.parse(dummy_parser, dummy_tokens)
     self.assertEqual(blocks, {})
     dummy_context = {}
     self.assertEqual(kwargs['myarg'].resolve(dummy_context),
                      ['myval', 'myval2'])
Example #2
0
 def test_multi_value_defaults(self):
     # test default
     options = core.Options(
         arguments.MultiValueArgument('myarg', default=['hello',
                                                        'world']), )
     argparser = parser.Parser(options)
     dummy_tokens = DummyTokens()
     kwargs, blocks = argparser.parse(dummy_parser, dummy_tokens)
     self.assertEqual(blocks, {})
     dummy_context = {}
     self.assertEqual(kwargs['myarg'].resolve(dummy_context),
                      ['hello', 'world'])
Example #3
0
 def test_05_multi_value(self):
     """
     Test simple multi value arguments
     """
     options = core.Options(
         arguments.MultiValueArgument('myarg')
     )
     # test single token MVA
     dummy_tokens = DummyTokens('myval')
     kwargs, blocks = options.parse(dummy_parser, dummy_tokens)
     self.assertEqual(blocks, {})
     self.assertEqual(len(kwargs), 1)
     dummy_context = {}
     # test resolving to list
     self.assertEqual(kwargs['myarg'].resolve(dummy_context), ['myval'])
     # test double token MVA
     dummy_tokens = DummyTokens('myval', 'myval2')
     kwargs, blocks = options.parse(dummy_parser, dummy_tokens)
     self.assertEqual(blocks, {})
     self.assertEqual(len(kwargs), 1)
     self.assertEqual(kwargs['myarg'].resolve(dummy_context),
                      ['myval', 'myval2'])
     # test triple token MVA
     dummy_tokens = DummyTokens('myval', 'myval2', 'myval3')
     kwargs, blocks = options.parse(dummy_parser, dummy_tokens)
     self.assertEqual(blocks, {})
     self.assertEqual(len(kwargs), 1)
     self.assertEqual(kwargs['myarg'].resolve(dummy_context),
                      ['myval', 'myval2', 'myval3'])
     # test max_values option
     options = core.Options(
         arguments.MultiValueArgument('myarg', max_values=2)
     )
     dummy_tokens = DummyTokens('myval')
     kwargs, blocks = options.parse(dummy_parser, dummy_tokens)
     self.assertEqual(blocks, {})
     self.assertEqual(len(kwargs), 1)
     dummy_context = {}
     self.assertEqual(kwargs['myarg'].resolve(dummy_context), ['myval'])
     dummy_tokens = DummyTokens('myval', 'myval2')
     kwargs, blocks = options.parse(dummy_parser, dummy_tokens)
     self.assertEqual(blocks, {})
     self.assertEqual(len(kwargs), 1)
     self.assertEqual(kwargs['myarg'].resolve(dummy_context),
                      ['myval', 'myval2'])
     dummy_tokens = DummyTokens('myval', 'myval2', 'myval3')
     self.assertRaises(exceptions.TooManyArguments,
                       options.parse, dummy_parser, dummy_tokens)
     # test no resolve
     options = core.Options(
         arguments.MultiValueArgument('myarg', resolve=False)
     )
     argparser = parser.Parser(options)
     dummy_tokens = DummyTokens('myval', "'myval2'")
     kwargs, blocks = argparser.parse(dummy_parser, dummy_tokens)
     self.assertEqual(blocks, {})
     self.assertEqual(kwargs['myarg'].resolve(dummy_context),
                      ['myval', 'myval2'])
     # test default
     options = core.Options(
         arguments.MultiValueArgument('myarg', default=['hello', 'world']),
     )
     argparser = parser.Parser(options)
     dummy_tokens = DummyTokens()
     kwargs, blocks = argparser.parse(dummy_parser, dummy_tokens)
     self.assertEqual(blocks, {})
     self.assertEqual(kwargs['myarg'].resolve(dummy_context),
                      ['hello', 'world'])