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")
class Config(config.Config): a = config.option_list( str, default=["abcdefghijklmnopqrstuvwxyz" for _ in range(2)], help="") b = config.option_list( str, default=["abcdefghijklmnopqrstuvwxyz" for _ in range(5)], help="") abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz = config.option_list( str, help="")
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="")
class Config(config.Config): a = config.option_list(InnerA, default=[InnerA(), InnerA()], help="") b = config.option_map(InnerA, default={ "x": InnerA(), "y": InnerA() }, help="")
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="")
class Config(config.Config): a = config.option_list(Inner, help="no default") b = config.option_list(Inner, default=[Inner(dict(x=10)), Inner(dict(x=20))], help="default value")
class Config(config.Config): a = config.option_list(int, default=[1, 2, 3], help="list of ints with default value") b = config.option_list(int, help="list of ints with no default value")
class Config(config.Config): a = config.option_list(Inner, help="")
class Config(config.Config): a = config.option_list(int, help="") b = config.option_list(int, default=default_list, help="") c = config.option_list(int, default=lambda: [4, 5, 6], help="")