Beispiel #1
0
def test_keys_handling_opt_specs_properly(value, conformed):
    """
    When a key entry is an opt-value with a default, that default should be used.

    When a key entry is an opt-value without a default, the entry will be None.

    """
    spec = s.keys({1: s.opt(s.str), 2: s.opt(s.str, "<default>")})
    assert conformed == s.conform(spec, value)
Beispiel #2
0
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)
Beispiel #3
0
 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']
Beispiel #4
0
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)
Beispiel #5
0
def test_bool_conform(value, exp):
    assert s.conform(s.bool, value) == exp, "unexpected"
Beispiel #6
0
def test_float_conform(value, exp):
    assert s.conform(s.float, value) == exp, "unexpected"
Beispiel #7
0
def test_predicate_int_conform(value, result):
    ps = s.predicate(lambda x: int(x), "intify")
    assert s.conform(
        ps, value) == result, f"conform({value}) failed - expected {result}"
Beispiel #8
0
def test_any_explain(msg, value, spec, result):
    assert s.conform(s.keys(spec), value) == result, msg
Beispiel #9
0
def test_any_conform(value):
    assert s.conform(s.any(),
                     value) == value, "should always yield the value itself"
Beispiel #10
0
def test_opt_explain(msg, value, spec, result):
    assert s.conform(spec, value) == result, msg
Beispiel #11
0
def test_mapof_conform(value, exp):
    spec = s.mapof(StrSpec(), IntSpec())
    assert s.conform(spec, value) == exp, "unexpected"
Beispiel #12
0
def test_inst_conform(value, element_spec, exp):
    spec = s.seqof(element_spec)
    assert s.conform(spec, value) == exp, "unexpected"
Beispiel #13
0
def test_inst_explain(value, exp):
    spec = s.seqof(s.predicate(lambda v: int(v)))
    assert s.conform(spec, value) == exp, "unexpected"
Beispiel #14
0
def test_str_conform(value, exp):
    assert s.conform(s.str, value) == exp, "unexpected"
Beispiel #15
0
def test_inseq_conform(msg, value, seq, result):
    assert s.conform(s.inseq(seq), value) == result, msg
Beispiel #16
0
def test_inst_valid(value, element_spec, exp):
    spec = s.seqof(element_spec)
    assert s.conform(spec,
                     value) == exp, "call from C-code to resolve correctly"
Beispiel #17
0
def test_int_conform(value, exp):
    assert s.conform(s.int, value) == exp, "unexpected"
Beispiel #18
0
def test_typ_explain(msg, value, typ, result):
    assert s.conform(s.type(typ), value) == result, msg