示例#1
0
 class Config(config.Config):
     a = config.option(int,
                       default=1,
                       example=2,
                       help="default and example values")
     b = config.option(int,
                       default=lambda: 3,
                       example=lambda: 4,
                       help="default and example callables")
     c = config.option(int, default=5, help="only default")
     d = config.option(int, example=lambda: 6, help="only example")
     e = config.option_list(int,
                            default=[1, 2, 3],
                            example=[4, 5, 6],
                            help="list: default and example values")
     f = config.option_list(int,
                            default=[1, 2, 3],
                            help="list: only default")
     g = config.option_list(int,
                            example=[4, 5, 6],
                            help="list: only example")
     h = config.option_map(int,
                           default={"x": 1},
                           example={"x": 2},
                           help="map: default and example values")
     i = config.option_map(int, default={"x": 1}, help="map: only default")
     j = config.option_map(int, example={"x": 2}, help="map: only example")
示例#2
0
 class Config(config.Config):
     a = config.option_map(Inner, help="no default")
     b = config.option_map(Inner,
                           default={
                               "i": Inner(dict(x=10)),
                               "j": Inner(dict(x=20))
                           },
                           help="default value")
示例#3
0
 class Config(config.Config):
     a = config.option_map(int,
                           default={
                               "x": 1,
                               "y": 2
                           },
                           help="map of ints with default value")
     b = config.option_map(int, help="map of ints with no default value")
示例#4
0
 class Config(config.Config):
     a = config.option_map(Inner,
                           default={
                               "?": Inner(),
                               "#": Inner(),
                               "[": Inner()
                           },
                           help="")
     b = config.option_map(int, default={"?": 1, "#": 2, "[": 3}, help="")
示例#5
0
 class Config(config.Config):
     a = config.option(config.WordList, help="")
     b = config.option(config.WordList, help="")
     c = config.option(config.WordList, default="foo bar baz", help="")
     d = config.option(config.WordList, default=["ab", "cd", "ef"], help="")
     e = config.option_list(config.WordList, help="")
     f = config.option_map(config.WordList, help="")
示例#6
0
 class Config(config.Config):
     a = config.option_list(InnerA, default=[InnerA(), InnerA()], help="")
     b = config.option_map(InnerA,
                           default={
                               "x": InnerA(),
                               "y": InnerA()
                           },
                           help="")
示例#7
0
def test_config_option_types():
    """Check that only whitelisted types are allowed for options."""
    class A(config.Config):
        a = config.option(int, default=1, help="")

    class B:
        pass

    # Check that all types that should be valid for options are allowed
    for t in (A, str, int, float, bool):
        config.option(t, help="")
        config.option_list(t, help="")
        config.option_map(t, help="")

    # Check that types that shouldn't be valid for options raise exceptions
    for t in (B, None, object):
        with pytest.raises(TypeError):
            config.option(t, help="")
        with pytest.raises(TypeError):
            config.option_list(t, help="")
        with pytest.raises(TypeError):
            config.option_map(t, help="")
示例#8
0
 class Inner(config.Config):
     a = config.option(int, default=1, help="")
     b = config.option_map(int, default={"?": 1, "#": 2, "[": 3}, help="")
示例#9
0
 class Config(config.Config):
     a = config.option_map(Inner, help="")
示例#10
0
 class Config(config.Config):
     a = config.option_map(int, help="")
     b = config.option_map(int, default=default_map, help="")
     c = config.option_map(int, default=lambda: {"y": 3, "z": 4}, help="")