def test_read_namespace_prefix(simple_schema, pfx): parser = create_argparser(simple_schema, prefix=pfx) namespace = parser.parse_args(["--pfx-alpha", "456", "--pfx-gamma", "abf"]) print(namespace) config, validation = read_namespace(simple_schema, namespace, prefix=pfx) assert config['alpha'] == 456 assert config['gamma'] == "abf"
def test_tdata_config(tdata): schema = Schema.from_string( """\ {} = {} """.format(tdata.name, tdata.validator_source), fmt="zirkon") parser = create_argparser(schema) for args, value, parsing_error, validation_error in tdata.checks: try: namespace = parser.parse_args(args) except SystemExit: assert parsing_error continue else: assert not parsing_error config, validation_result = read_namespace(schema, namespace) if validation_error: assert validation_result else: assert not validation_result assert config.get(tdata.name) == value
def test_read_namespace_invalid_schema(): with pytest.raises(TypeError): read_namespace([], None)