Exemplo n.º 1
0
 def test_multiflag(self):
     # test multi-flag
     options = core.Options(
         arguments.Flag('flagone', true_values=['on'], default=False),
         arguments.Flag('flagtwo', false_values=['off'], default=True),
     )
     dummy_tokens = DummyTokens('On', 'On')
     dummy_context = {}
     kwargs, blocks = options.parse(dummy_parser, dummy_tokens)
     self.assertEqual(blocks, {})
     self.assertEqual(kwargs['flagone'].resolve(dummy_context), True)
     self.assertEqual(kwargs['flagtwo'].resolve(dummy_context), True)
Exemplo n.º 2
0
 def test_flag_wrong_value(self):
     options = core.Options(
         arguments.Flag('myflag', true_values=['on'], false_values=['off']))
     # test exceptions
     dummy_tokens = DummyTokens('myval')
     self.assertRaises(exceptions.InvalidFlag, options.parse, dummy_parser,
                       dummy_tokens)
Exemplo n.º 3
0
 def test_flag_false_value(self):
     options = core.Options(
         arguments.Flag('myflag', true_values=['on'], false_values=['off']))
     dummy_tokens = DummyTokens('off')
     dummy_context = {}
     kwargs, blocks = options.parse(dummy_parser, dummy_tokens)
     self.assertEqual(blocks, {})
     self.assertEqual(kwargs['myflag'].resolve(dummy_context), False)
Exemplo n.º 4
0
 def test_case_sensitive_flag_okay(self):
     options = core.Options(
         arguments.Flag('myflag',
                        true_values=['on'],
                        default=False,
                        case_sensitive=True))
     dummy_tokens = DummyTokens('on')
     dummy_context = {}
     kwargs, blocks = options.parse(dummy_parser, dummy_tokens)
     self.assertEqual(blocks, {})
     self.assertEqual(kwargs['myflag'].resolve(dummy_context), True)
Exemplo n.º 5
0
 def test_complext_first_and_last_argument(self):
     options = core.Options(
         arguments.Argument('singlearg'),
         arguments.MultiValueArgument('multiarg', required=False), 'as',
         arguments.Argument('varname', required=False), 'safe',
         arguments.Flag('safe', true_values=['on', 'true'], default=False))
     # test first argument and last argument given
     dummy_tokens = DummyTokens(2, 'safe', 'false')
     dummy_context = {}
     kwargs, blocks = options.parse(dummy_parser, dummy_tokens)
     self.assertEqual(blocks, {})
     self.assertEqual(len(kwargs), 4)
     expected = [('singlearg', 2), ('multiarg', []), ('varname', None),
                 ('safe', False)]
     for key, value in expected:
         self.assertEqual(kwargs[key].resolve(dummy_context), value)
Exemplo n.º 6
0
 def test_complex_all_arguments(self):
     """
     test a complex tag option parser
     """
     options = core.Options(
         arguments.Argument('singlearg'),
         arguments.MultiValueArgument('multiarg', required=False), 'as',
         arguments.Argument('varname', required=False), 'safe',
         arguments.Flag('safe', true_values=['on', 'true'], default=False))
     # test simple 'all arguments given'
     dummy_tokens = DummyTokens(1, 2, 3, 'as', 4, 'safe', 'true')
     dummy_context = {}
     kwargs, blocks = options.parse(dummy_parser, dummy_tokens)
     self.assertEqual(blocks, {})
     self.assertEqual(len(kwargs), 4)
     expected = [('singlearg', 1), ('multiarg', [2, 3]), ('varname', 4),
                 ('safe', True)]
     for key, value in expected:
         self.assertEqual(kwargs[key].resolve(dummy_context), value)
Exemplo n.º 7
0
 def test_flag_wrong_value_no_true(self):
     options = core.Options(arguments.Flag('myflag', false_values=['off']))
     dummy_tokens = DummyTokens('myval')
     self.assertRaises(exceptions.InvalidFlag, options.parse, dummy_parser,
                       dummy_tokens)
     self.assertRaises(ImproperlyConfigured, arguments.Flag, 'myflag')