def do_test(args, kwargs, expected_default): # Defaults are computed in the parser and added into the kwargs, so we # must jump through this hoop in this test. parser = Parser(env={}, config=Config.load([]), scope_info=GlobalOptionsRegistrar.get_scope_info(), parent_parser=None, option_tracker=OptionTracker()) parser.register(*args, **kwargs) oshi = HelpInfoExtracter.get_option_scope_help_info_from_parser(parser).basic self.assertEquals(1, len(oshi)) ohi = oshi[0] self.assertEqual(expected_default, ohi.default)
def do_test(args, kwargs, expected_default): # Defaults are computed in the parser and added into the kwargs, so we # must jump through this hoop in this test. parser = Parser(env={}, config=Config.load([]), scope_info=GlobalOptionsRegistrar.get_scope_info(), parent_parser=None, option_tracker=OptionTracker()) parser.register(*args, **kwargs) oshi = HelpInfoExtracter.get_option_scope_help_info_from_parser(parser).basic self.assertEquals(1, len(oshi)) ohi = oshi[0] self.assertEqual(expected_default, ohi.default)
def _format_for_global_scope(show_advanced, show_deprecated, args, kwargs): parser = Parser( env={}, config=Config.load([]), scope_info=GlobalOptions.get_scope_info(), parent_parser=None, ) parser.register(*args, **kwargs) # Force a parse to generate the derivation history. parser.parse_args(Parser.ParseArgsRequest((), OptionValueContainerBuilder(), [], False)) oshi = HelpInfoExtracter("").get_option_scope_help_info("", parser, False) return HelpFormatter( show_advanced=show_advanced, show_deprecated=show_deprecated, color=False ).format_options(oshi)
def do_test(kwargs, expected_basic=False, expected_advanced=False): def exp_to_len(exp): return int(exp) # True -> 1, False -> 0. parser = Parser( env={}, config=Config.load([]), scope_info=GlobalOptions.get_scope_info(), ) parser.register("--foo", **kwargs) oshi = HelpInfoExtracter("").get_option_scope_help_info( "", parser, False) assert exp_to_len(expected_basic) == len(oshi.basic) assert exp_to_len(expected_advanced) == len(oshi.advanced)
def do_test(args, kwargs, expected_default_str): # Defaults are computed in the parser and added into the kwargs, so we # must jump through this hoop in this test. parser = Parser( env={}, config=Config.load([]), scope_info=GlobalOptions.get_scope_info(), ) parser.register(*args, **kwargs) oshi = HelpInfoExtracter(parser.scope).get_option_scope_help_info( "description", parser, False) assert oshi.description == "description" assert len(oshi.basic) == 1 ohi = oshi.basic[0] assert to_help_str(ohi.default) == expected_default_str