def test_natint(input, exp_valid, exp_conform, exp_explain): def _natint(value): value = int(value) return value if value > 0 else False spec = s.predicate(_natint, 'natural integer') assert s.valid(spec, input) == exp_valid, "validation failed" assert s.conform(spec, input) == exp_conform, "conform value is incorrect" assert s.explain(spec, input) == ("predicate 'natural integer' failed" if exp_explain else None)
def __init__(self, conf): conf_c = s.conform(GW_CONF_PARSER_SPEC, conf) if conf_c == s.Invalid: raise RuntimeError("LOLCAEK") if not s.valid(GW_CONF_PARSER_SPEC, conf): raise SpecError(GW_CONF_PARSER_SPEC, conf) self.open = conf['open'] self.close = conf['close'] self.processes = conf['processes'] self.temp_file_suffix = conf['temp_file_suffix'] self.include_patterns = conf['include_patterns'] self.ignore_patterns = conf['ignore_patterns'] self.ignore_dir_patterns = conf['ignore_dir_patterns'] self.search_paths = conf['search_paths'] self.post_process_fn = conf['post_process_fn']
def load(project: Path): conf_path = project.joinpath(CONF_NAME) try: with open(str(conf_path), 'r') as f: config = yaml.safe_load(f) if not s.valid(GW_CONF_SPEC, config): raise ConfigurationFileInvalidError(GW_CONF_SPEC, config) except FileNotFoundError as e: raise ConfigurationNotFoundError(project) from e # except PermissionError config_c = s.conform(GW_CONF_SPEC, config) if config_c == s.Invalid: # Should never happen here - we already validated the spec ConfigurationFileInvalidError(GW_CONF_SPEC, config) pp_log_conf(config_c) return Configuration(project, config_c)
def __init__(self, project: Path, conf: dict): if not s.valid(GW_CONF_SPEC, conf): raise SpecError(GW_CONF_SPEC, conf) self.project: Path = project self.logging = ConfLogging(conf['logging']) self.parser = ConfParser(conf['parser'])
def __init__(self, conf): if not s.valid(GW_CONF_LOGGING_SPEC, conf): raise SpecError(GW_CONF_LOGGING_SPEC, conf) self.level: str = conf['level'] self.format: str = conf['format'] self.datefmt: str = conf['datefmt']
def test_anyof_valid(value, preds, exp): spec = s.anyof(preds) assert s.valid(spec, value) == exp, "unexpected"
def test_float_valid(value, exp): assert s.valid(s.float, value) == exp, "unexpected"
def test_any_valid(msg, value, spec, result): assert s.valid(s.keys(spec), value) == result, msg
def test_inst_valid(value, element_spec, exp): spec = s.seqof(element_spec) assert s.valid(spec, value) == exp, "expected direct call to work"
def test_any_valid(value): assert s.valid(s.any(), value) == True, "should always be true"
def test_opt_valid(msg, value, spec, result): assert s.valid(spec, value) == result, msg
def test_mapof_valid(value, exp): spec = s.mapof(StrSpec(), IntSpec()) assert s.valid(spec, value) == exp, "unexpected"
def test_inst_valid(value, element_spec, exp): spec = s.seqof(element_spec) assert s.valid(spec, value) == exp, "unexpected"
def test_str_valid(value, exp): assert s.valid(s.str, value) == exp, "unexpected"
def test_inseq_valid(msg, value, seq, result): assert s.valid(s.inseq(seq), value) == result, msg
def test_bool_valid(value, exp): assert s.valid(s.bool, value) == exp, "unexpected"
def test_predicate_int_valid(value, result, txt): ps = s.predicate(lambda x: isinstance(x, int), "isint") assert s.valid(ps, value) == result, f"valid({value}): {txt}"
def test_int_valid(value, exp): assert s.valid(s.int, value) == exp, "unexpected"
def test_typ_valid(msg, value, typ, result): assert s.valid(s.type(typ), value) == result, msg