def main(): p = argparse.ArgumentParser( prog="pyjob", formatter_class=argparse.ArgumentDefaultsHelpFormatter) mark_parser(p, Subcommand.NONE) # may be removed once Py3-only sub_p = p.add_subparsers() add_exec_subparser(sub_p) add_conf_subparser(sub_p) args = p.parse_args() if args.which == Subcommand.EXEC: kwargs = vars(args) platform = kwargs.pop("platform") executables = [os.path.abspath(f) for f in kwargs.pop("executables")] kwargs["directory"] = os.path.abspath(kwargs["directory"]) verbosity_lvl = kwargs.pop("verbose") if verbosity_lvl == 0: logging.basicConfig(level=logging.INFO) else: logging.basicConfig(level=logging.DEBUG) with TaskFactory(platform, executables, **kwargs) as task: task.run() elif args.which == Subcommand.CONF: for pair in args.arguments: k, v = pair.split(":") config.setdefault(k, value=typecast(v)) else: p.print_help()
def test_nested(self): output = typecast({ "int": ["1", "2", 3], "bool": "False", "mixed": ["3.0", "foo"], "char": "t", "str": "test", }) assert isinstance(output, dict) assert output == { "int": [1, 2, 3], "bool": False, "mixed": [3.0, "foo"], "char": "t", "str": "test", }
def test_dict(self): output = typecast({ "int": "1", "bool": "False", "float": "3.0", "char": "t", "str": "test" }) assert isinstance(output, dict) assert output == { "int": 1, "bool": False, "float": 3.0, "char": "t", "str": "test", }
def test_float(self): output = typecast("1.0") assert isinstance(output, float) assert output == 1
def test_int(self): output = typecast("1") assert isinstance(output, int) assert output == 1
def test_list(self): output = typecast(["1", "True", "3.0", "t", "test"]) assert isinstance(output, list) assert output == [1, True, 3.0, "t", "test"]
def test_bool(self): output = typecast("True") assert isinstance(output, bool) assert output is True
def test_none(self): output = typecast("None") assert output is None
def test_str(self): output = typecast("abc") assert isinstance(output, str) assert output == "abc"