def test_nested(self, main_config): config = anyfig.init_config(default_config=main_config, cli_args={}) with pytest.raises(FrozenInstanceError): config.innerfig.inner = 'new' config.frozen(False).innerfig.inner = 'new' config.frozen().innerfig.frozen(False).inner = 'new'
def main(): # cls = MainConfig # print(cls) # print(cls.__call__) # print(callable(cls)) # qew config = anyfig.init_config(default_config=MyDatetime) print(config) print(anyfig.registered_config_classes) anyfig.unregister_configs() print(anyfig.registered_config_classes) qweqw config = MyDatetime() print(config) emp = Empty() print(emp) qwe # dtime = datetime(2020, 1, 1) param = dict(year=3) param = dict(day=1, month=2, year=3) # param = dict(asdas=3) # param = dict(day=3, month=12) # param = dict() dtime = config.build(param) # dtime = datetime(year=1, month=2, day=3) print(dtime)
def main(): config = anyfig.init_config(default_config=MainConfig) # print(config) # anyfig.save_config(config, 'save.pickle') # config = anyfig.load_config('save.pickle') # anyfig.save_json(config, 'save.json') # config = anyfig.load_json('save.json') print(config) print(type(config))
def test_refreeze(self, main_config): config = anyfig.init_config(default_config=main_config, cli_args={}) with pytest.raises(FrozenInstanceError): config.frozen(False).frozen().int_var = 2
def test_unfreeze(self, main_config): config = anyfig.init_config(default_config=main_config, cli_args={}) config.frozen(False).int_var = 2
def test_init(self, main_config): anyfig.init_config(default_config=main_config, cli_args={})
def test_types(main_config): config = anyfig.init_config(default_config=main_config, cli_args={}) assert type(config.int_var) == int assert type(config.float_var) == float assert type(config.string_var) == str
import anyfig from datetime import datetime @anyfig.config_class(target=datetime) class MyConfig(): def __init__(self): self.year = 1996 self.month = 12 config = anyfig.init_config(default_config=MyConfig) build_args = dict(day=13) date = config.build(build_args) print(date) print(config) class DataProcesser: def __init__(self, algorithm, data): self.algorithm = algorithm self.data = data # ... Other methods @anyfig.config_class(target=DataProcesser) class MyConfig(): def __init__(self): self.algorithm = '+'
def main(): config = anyfig.init_config(default_config=MainConfig3) print(config)
# self.inner_config = InnerConfig() @anyfig.config_class class InnerConfig(): def __init__(self): self.inner_text = "Yo Dawg" # parser = argparse.ArgumentParser() # parser.add_argument("--start_time", # type=int, # help="display a square of a given number") # dict_args = vars(parser.parse_args()) # print('known', dict_args) # print('unknown', unknown) # args = dict(args) # print(args) import sys dict_args = sys.argv[1:] print(dict_args) dict_args = anyfig.parse_cli_args(dict_args) print(dict_args) dict_args.pop('start_time', None) config = anyfig.init_config(default_config=MyConfig, cli_args=dict_args) print(config)