def assertParser(self, _cli, parser_args, argv):
        number_of_parsing_levels = 2
        cmd = 'cmd_{0}_{1}'.format(argv[0], argv[1]).replace('-', '_')
        self.assertEqual(parser_args.func.__name__, cmd)
        self.assertTrue(argv[1] in _cli.subcommands)
        self.assertTrue(argv[0] in _cli.subparsers)
        number_of_positional_arguments = len(argv) - number_of_parsing_levels
        if number_of_positional_arguments:
            positional_args = []
            for item in parser_args.func.arguments:
                arg = item[0][0]
                if arg.startswith('--'):
                    break
                positional_args.append(arg)
            for index, arg in enumerate(positional_args,
                                        start=number_of_parsing_levels):
                args_type = (
                    parser_args.func.arguments[index - number_of_parsing_levels][1]
                    .get('type')
                )
                if args_type:
                    self.assertEqual(getattr(parser_args, arg),
                                     args_type(argv[index]))
                else:
                    self.assertEqual(getattr(parser_args, arg), argv[index])
                self.assertRaises(SystemExit, self.cli, argv[:index])
Assertion method for subparsers, subcommands and positional arguments.
dataset/ETHPy150Open ueg1990/imgur-cli/tests/test_cli.py/TestImgurCli.assertParser