Esempio n. 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)
Esempio n. 2
0
import typing as t
from re import compile as re_compile
from multiprocessing import cpu_count
from os.path import expanduser
import io
import logging
from ghostwriter.utils import spec as s

log = logging.getLogger(__file__)

CONF_NAME = "ghostwriter.conf.yml"

GW_CONF_LOGGING_SPEC = s.keys({
    'level':
    s.opt(s.inseq(['debug', 'info', 'warning', 'error', 'critical']), 'info'),
    'format':
    s.opt(s.str, '%(asctime)s - %(message)s'),
    'datefmt':
    s.opt(s.str, '%Y-%m-%d %H:%M:%S')
})


class GhostwriterConfigurationError(Exception):
    pass


def _natint(value):
    value = int(value)
    return value if value > 0 else False


def _nonempty(value):
Esempio n. 3
0
def test_any_valid(msg, value, spec, result):
    assert s.valid(s.keys(spec), value) == result, msg
Esempio n. 4
0
def test_any_explain(msg, value, spec, result):
    assert s.conform(s.keys(spec), value) == result, msg