Exemple #1
0
 def test_build_argparse_with_invalid_arg(self, get_metadata):
     get_metadata.return_value = {'usage': ('foo1'),
                                  'help': 'dummy', 'help_foo1': 'foo1'}
     subparser = mock.Mock()
     obj = BashModule(self.module)
     with self.assertRaises(RuntimeError):
         obj.build_argparse(subparser)
Exemple #2
0
 def test_build_argparse(self, get_metadata):
     get_metadata.return_value = {'usage': ('foo --bar --baz=bah [asd] '
                                            '[--asdf] [--lol=hehe]'),
                                  'help': 'dummy', 'help_foo': 'foo1',
                                  'help_bar': 'bar2', 'help_baz': 'baz3',
                                  'help_asd': 'asd4', 'help_asdf': 'asdf5',
                                  'help_lol': 'lol6'}
     subparser = mock.Mock()
     obj = BashModule(self.module)
     parser = obj.build_argparse(subparser)
     subparser.add_parser.assert_called_once_with('module', help='dummy')
     self.assertEquals(parser.add_argument.call_args_list,
                       [mock.call('foo', help='foo1', nargs=1),
                        mock.call('--bar', required=True,
                                  action='store_const', const='1',
                                  help='bar2'),
                        mock.call('--baz', metavar='bah', required=True,
                                  help='baz3'),
                        mock.call('asd', help='asd4', nargs='?'),
                        mock.call('--asdf', required=False,
                                  action='store_const', const='1',
                                  help='asdf5'),
                        mock.call('--lol', metavar='hehe', required=False,
                                  help='lol6')])
     parser.set_defaults.called_once_with(_module=obj)