def test_update_exist_first(config: LoadConfig, config_file: str, path): def read(cfg): result = cfg for item in path: result = getattr(result, item) assert isinstance(result, int) return result def update(cfg, value): result = cfg for item in path[:-1]: result = getattr(result, item) setattr(result, path[-1], value) old_value = read(config) new_value = old_value**2 + 5 update(config, new_value) assert read(config) == new_value assert read(LoadConfig(config_file)) == old_value config.update() assert read(LoadConfig(config_file)) == new_value
def _config_from_opts(options, default=None): if not default: default = LoadConfig() for param_name in ("guarantee", "limit", "swap_limit"): if options.__dict__[param_name] is None: options.__dict__[param_name] = default.__dict__[param_name] return LoadConfig(options.guarantee, options.limit, options.swap_limit)
def _make_request(type, id="", config=LoadConfig()): req = rpc_proto.Request() req.type = type req.id = id req.config.guarantee = config.guarantee req.config.limit = config.limit req.config.swap_limit = config.swap_limit return req
def _make_response(type, errcode=0, errmsg="", id="", config=LoadConfig(), list_len=0): resp = rpc_proto.Response() resp.type = type resp.errcode = errcode resp.errmsg = errmsg resp.id = id resp.config.guarantee = config.guarantee resp.config.limit = config.limit resp.config.swap_limit = config.swap_limit resp.list_len = list_len return resp
async def main(): if len(argv) < 2: app_name = argv[0] if argv else "app" print(f"Please use {app_name} <path/to/config_file.yaml> [command]") print("Instead:") print(argv) print(f"CWD: {os.getcwd()}") config = LoadConfig(argv[1]) command_name = argv[2] if len(argv) >= 3 else None print(f"Execute command: {command_name}") command = commands.get(command_name, default_cmd) answer = await command(config) if answer: print(f"Application finished with answer {answer}")
def config(): return LoadConfig("configs/test.yaml")
def _config_from_msg(msg): return LoadConfig(msg.config.guarantee, msg.config.limit, msg.config.swap_limit)
def config(config_file): return LoadConfig(config_file)