def test_configure_from_options(self): parser = OptionParser() opts, _ = parser.parse_known_args(['update', '-y', '--allowerasing']) conf = dnf.util.Bunch() conf.color = 'auto' demands = dnf.util.Bunch() parser.configure_from_options(opts, conf, demands, None) self.assertTrue(demands.allow_erasing) self.assertTrue(conf.assumeyes)
class OptionParserAddCmdTest(support.TestCase): def setUp(self): self.cli_commands = {} self.parser = OptionParser() self.parser._ = dnf.pycomp.NullTranslations().ugettext self.cli = mock.Mock() def _register_command(self, command_cls): """ helper for simulate dnf.cli.cli.Cli.register_Command()""" for name in command_cls.aliases: self.cli_commands[name] = command_cls def test_add_commands(self): cmd = MyTestCommand(self.cli) self._register_command(cmd) self.parser.add_commands(self.cli_commands, "main") name = cmd.aliases[0] self.assertTrue(name in self.parser._cmd_usage) group, summary = self.parser._cmd_usage[name] self.assertEqual(group, 'main') self.assertEqual(summary, cmd.summary) self.assertEqual(self.parser._cmd_groups, set(['main'])) def test_add_commands_only_once(self): cmd = MyTestCommand(self.cli) self._register_command(cmd) self.parser.add_commands(self.cli_commands, "main") cmd = MyTestCommand(self.cli) self._register_command(cmd) self.parser.add_commands(self.cli_commands, "plugin") self.assertEqual(len(self.parser._cmd_usage.keys()), 1) self.assertEqual(self.parser._cmd_groups, set(['main'])) def test_cmd_groups(self): cmd = MyTestCommand(self.cli) self._register_command(cmd) self.parser.add_commands(self.cli_commands, "main") cmd = MyTestCommand2(self.cli) self._register_command(cmd) self.parser.add_commands(self.cli_commands, "plugin") self.assertEqual(len(self.parser._cmd_groups), 2) self.assertEqual(self.parser._cmd_groups, set(['main', 'plugin'])) def test_help_option_set(self): opts, cmds = self.parser.parse_known_args(['-h']) self.assertTrue(opts.help) def test_help_option_notset(self): opts, cmds = self.parser.parse_known_args(['foo', 'bar']) self.assertFalse(opts.help) def test_get_usage(self): output = [ u'dnf [options] COMMAND', u'', u'List of Main Commands', u'', u'test-cmd summary', u'', u'List of Plugin Commands', u'', u'test-cmd2 summary2', u'' ] cmd = MyTestCommand(self.cli) self._register_command(cmd) self.parser.add_commands(self.cli_commands, "main") cmd2 = MyTestCommand2(self.cli) self._register_command(cmd2) self.parser.add_commands(self.cli_commands, "plugin") self.assertEqual(len(self.parser._cmd_usage.keys()), 2) usage = self.parser.get_usage().split('\n') self.assertEqual(usage, output)
def test_parse(self): parser = OptionParser() opts, cmds = parser.parse_known_args(['update', '--nogpgcheck']) self.assertEqual(cmds, ['update']) self.assertTrue(opts.nogpgcheck) self.assertIsNone(opts.color)
class OptionParserAddCmdTest(support.TestCase): def setUp(self): self.cli_commands = {} self.parser = OptionParser() self.parser._ = dnf.pycomp.NullTranslations().ugettext self.cli = mock.Mock() def _register_command(self, command_cls): """ helper for simulate dnf.cli.cli.Cli.register_Command()""" for name in command_cls.aliases: self.cli_commands[name] = command_cls def test_add_commands(self): cmd = MyTestCommand(self.cli) self._register_command(cmd) self.parser.add_commands(self.cli_commands, "main") name = cmd.aliases[0] self.assertTrue(name in self.parser._cmd_usage) group, summary = self.parser._cmd_usage[name] self.assertEqual(group, 'main') self.assertEqual(summary, cmd.summary) self.assertEqual(self.parser._cmd_groups, set(['main'])) def test_add_commands_only_once(self): cmd = MyTestCommand(self.cli) self._register_command(cmd) self.parser.add_commands(self.cli_commands, "main") cmd = MyTestCommand(self.cli) self._register_command(cmd) self.parser.add_commands(self.cli_commands, "plugin") self.assertEqual(len(self.parser._cmd_usage.keys()), 1) self.assertEqual(self.parser._cmd_groups, set(['main'])) def test_cmd_groups(self): cmd = MyTestCommand(self.cli) self._register_command(cmd) self.parser.add_commands(self.cli_commands, "main") cmd = MyTestCommand2(self.cli) self._register_command(cmd) self.parser.add_commands(self.cli_commands, "plugin") self.assertEqual(len(self.parser._cmd_groups), 2) self.assertEqual(self.parser._cmd_groups, set(['main', 'plugin'])) def test_help_option_set(self): opts, cmds = self.parser.parse_known_args(['-h']) self.assertTrue(opts.help) def test_help_option_notset(self): opts, cmds = self.parser.parse_known_args(['foo', 'bar']) self.assertFalse(opts.help) def test_get_usage(self): output = [ u'dnf [options] COMMAND', u'', u'List of Main Commands', u'', u'test-cmd summary', u'', u'List of Plugin Commands', u'', u'test-cmd2 summary2', u''] cmd = MyTestCommand(self.cli) self._register_command(cmd) self.parser.add_commands(self.cli_commands, "main") cmd2 = MyTestCommand2(self.cli) self._register_command(cmd2) self.parser.add_commands(self.cli_commands, "plugin") self.assertEqual(len(self.parser._cmd_usage.keys()), 2) usage = self.parser.get_usage().split('\n') self.assertEqual(usage, output)