def test_argparse_env_ini(): """ --number from enviorment --bool from ini --str-arg from cmdline """ parser = __argparser() env = { "NUMBER": 4, } for key, value in env.items(): os.environ[key] = str(value) commandline = "--config {} --str-arg cmdline".format(INI_TEST_FILE).split() args = caep.handle_args(parser, "actworkers", "actworkers.ini", "test", opts=commandline) assert args.number == 4 assert args.str_arg == "cmdline" assert args.bool is True # Remove from environment variables for key in env: del os.environ[key]
def handle_args(parser: argparse.ArgumentParser, section: Text) -> argparse.Namespace: """ Verify default arguments """ args = caep.handle_args(parser, CONFIG_ID, CONFIG_NAME, section) setup_logging(args.loglevel, args.logfile) debug(args) args.chat_prefix = args.chat_prefix.strip() if not args.server: fatal("--server not specified") if not args.user: fatal("--user not specified") if args.no_verify: requests.packages.urllib3.disable_warnings( category=InsecureRequestWarning) if args.password_pass_entry: args.password = gettpassentry(args.password_pass_entry) if not args.password: fatal("Must specify either --password or --password-pass-entry") return args
def test_argparse_env(): """all arguments from env""" parser = __argparser() env = { "STR_ARG": "from env", "NUMBER": 4, "BOOL": "yes", # accepts both yes and true } for key, value in env.items(): os.environ[key] = str(value) args = caep.handle_args(parser, "actworkers", "actworkers.ini", "test", opts=[]) assert args.number == 4 assert args.str_arg == "from env" assert args.bool is True # Remove from environment variables for key in env: del os.environ[key]
def test_argparse_ini(): """ all arguments from ini file """ parser = __argparser() commandline = "--config {}".format(INI_TEST_FILE).split() args = caep.handle_args(parser, "actworkers", "actworkers.ini", "test", opts=commandline) assert args.number == 3 assert args.str_arg == "from ini" assert args.bool is True
def test_argparse_only(): """ all arguments from command line, using default for number and bool """ parser = __argparser() commandline = "--str-arg test".split() args = caep.handle_args(parser, "actworkers", "actworkers.ini", "test", opts=commandline) assert args.number == 1 assert args.str_arg == "test" assert not args.bool
def handle_args(parser: argparse.ArgumentParser) -> argparse.Namespace: """Wrapper for caep.handle_args where we set config_id and config_name""" args = caep.handle_args(parser, CONFIG_ID, CONFIG_NAME, worker_name()) if args.http_header: # Convert comma separated list of http headers to dictionary headers = {} # Split on comma, unless they are escaped for header in re.split(r"(?<!\\),", args.http_header): if ":" not in header: raise act.api.base.ArgumentError( f"No ':' in header, http header: {header}") header_key, header_val = header.split(":", 1) header_key = header_key.strip().replace("\\,", ",") header_val = header_val.strip().replace("\\,", ",") headers[header_key] = header_val args.http_header = headers return cast(argparse.Namespace, args)
def handle_args(parser: argparse.ArgumentParser) -> argparse.Namespace: """ Wrapper for caep.handle_args where we set config_id and config_name """ return caep.handle_args(parser, CONFIG_ID, CONFIG_NAME, worker_name())