def test_as_subparser(self): ''' Testing the build as a subparser ''' result = argparse.ArgumentParser() simplifiedapp.build_argparse_parser( simplifiedapp, parent_parser=result.add_subparsers( help='possible subparsers').add_parser('test-subparser')) result_pattern = '.*^\s*positional\s+arguments:\s+^\s*\{test-subparser}\s+possible\s+subparsers\s*$.*' self.assertArgparseHelpRegex(result, result_pattern)
def test_default_options_json(self): ''' Testing the addition of the json (a default option) switch to the parser ''' result = simplifiedapp.build_argparse_parser(simplifiedapp) result_pattern = '.*^\s*--json\s+.*' self.assertArgparseHelpRegex(result, result_pattern)
def test_default_options_log_to_syslog(self): ''' Testing the addition of the log-to-syslog (a default option) switch to the parser ''' result = simplifiedapp.build_argparse_parser(simplifiedapp) result_pattern = '.*^\s*--log-to-syslog\s+.*' self.assertArgparseHelpRegex(result, result_pattern)
def test_default_options_log_level(self): ''' Testing the addition of the log-level (a default option) switch to the parser ''' result = simplifiedapp.build_argparse_parser(simplifiedapp) result_pattern = '.*^\s*--log-level\s+\{notset,debug,info,warning,error,critical}\s+.*' self.assertArgparseHelpRegex(result, result_pattern)
def test_version_switch_addition(self): ''' Testing the addition of the --version switch to the parser ''' result = simplifiedapp.build_argparse_parser(simplifiedapp) result_pattern = '.*^\s*--version\s+.*' self.assertArgparseHelpRegex(result, result_pattern)
def test_epilog(self): ''' Testing the addition of the epilog to the parser ''' result = simplifiedapp.build_argparse_parser(simplifiedapp) result_pattern = '.*^\s*{epilog}\s*$.*'.format( epilog=self.metadata['long_description']) self.assertArgparseHelpRegex(result, result_pattern)
def test_description(self): ''' Testing the addition of the description to the parser ''' result = simplifiedapp.build_argparse_parser(simplifiedapp) result_pattern = '.*^\s*{description}\s*$.*'.format( description=self.metadata['description']) self.assertArgparseHelpRegex(result, result_pattern)
def test_providing_content(self): ''' Testing the build by feeding it content (not just the defaults) ''' fixture = { 'test-param': { 'help': 'positional test parameter' }, '--test-optional-param': { 'help': 'optional test parameter' }, } result = simplifiedapp.build_argparse_parser(simplifiedapp, parser_content=fixture) result_pattern = '.*^\s*positional arguments:\s*^\s*test-param\s+positional\s+test\s+parameter\s*$.*^\s*--test-optional-param\s+TEST_OPTIONAL_PARAM\s*^\s*optional\s+test\s+parameter\s+\(default:\s+None\)\s*$.*' self.assertArgparseHelpRegex(result, result_pattern)