예제 #1
0
def test_typesec_to_str():
    assert (typecheck.typespec_to_str(str)) == "str"
    assert (typecheck.typespec_to_str(
        typing.Sequence[str])) == "sequence of str"
    assert (typecheck.typespec_to_str(typing.Optional[str])) == "optional str"
    with pytest.raises(NotImplementedError):
        typecheck.typespec_to_str(dict)
예제 #2
0
def dump_dicts(opts, keys: typing.List[str]=None):
    """
        Dumps the options into a list of dict object.

        Return: A list like: { "anticache": { type: "bool", default: false, value: true, help: "help text"} }
    """
    options_dict = {}
    keys = keys if keys else opts.keys()
    for k in sorted(keys):
        o = opts._options[k]
        t = typecheck.typespec_to_str(o.typespec)
        option = {
            'type': t,
            'default': o.default,
            'value': o.current(),
            'help': o.help,
            'choices': o.choices
        }
        options_dict[k] = option
    return options_dict
예제 #3
0
def dump_defaults(opts):
    """
        Dumps an annotated file with all options.
    """
    # Sort data
    s = ruamel.yaml.comments.CommentedMap()
    for k in sorted(opts.keys()):
        o = opts._options[k]
        s[k] = o.default
        txt = o.help.strip()

        if o.choices:
            txt += " Valid values are %s." % ", ".join(repr(c) for c in o.choices)
        else:
            t = typecheck.typespec_to_str(o.typespec)
            txt += " Type %s." % t

        txt = "\n".join(textwrap.wrap(txt))
        s.yaml_set_comment_before_after_key(k, before="\n" + txt)
    return ruamel.yaml.round_trip_dump(s)
예제 #4
0
def dump_dicts(opts, keys: typing.List[str]=None):
    """
        Dumps the options into a list of dict object.

        Return: A list like: { "anticache": { type: "bool", default: false, value: true, help: "help text"} }
    """
    options_dict = {}
    keys = keys if keys else opts.keys()
    for k in sorted(keys):
        o = opts._options[k]
        t = typecheck.typespec_to_str(o.typespec)
        option = {
            'type': t,
            'default': o.default,
            'value': o.current(),
            'help': o.help,
            'choices': o.choices
        }
        options_dict[k] = option
    return options_dict
예제 #5
0
def dump_defaults(opts):
    """
        Dumps an annotated file with all options.
    """
    # Sort data
    s = ruamel.yaml.comments.CommentedMap()
    for k in sorted(opts.keys()):
        o = opts._options[k]
        s[k] = o.default
        txt = o.help.strip()

        if o.choices:
            txt += " Valid values are %s." % ", ".join(repr(c) for c in o.choices)
        else:
            t = typecheck.typespec_to_str(o.typespec)
            txt += " Type %s." % t

        txt = "\n".join(textwrap.wrap(txt))
        s.yaml_set_comment_before_after_key(k, before="\n" + txt)
    return ruamel.yaml.round_trip_dump(s)
예제 #6
0
def dump_dicts(opts):
    """
        Dumps the options into a list of dict object.

        Return: A list like: [ { name: "anticache", type: "bool", default: false, value: true, help: "help text"} ]
    """
    options_list = []
    for k in sorted(opts.keys()):
        o = opts._options[k]
        t = typecheck.typespec_to_str(o.typespec)
        option = {
            'name': k,
            'type': t,
            'default': o.default,
            'value': o.current(),
            'help': o.help,
            'choices': o.choices
        }
        options_list.append(option)
    return options_list
예제 #7
0
def test_typesec_to_str():
    assert(typecheck.typespec_to_str(str)) == "str"
    assert(typecheck.typespec_to_str(typing.Sequence[str])) == "sequence of str"
    assert(typecheck.typespec_to_str(typing.Optional[str])) == "optional str"
    with pytest.raises(NotImplementedError):
        typecheck.typespec_to_str(dict)