def test_top_level_in_ini(): # values with no sections dump and load in .ini as we would expect in .toml s = """ value1 = "foo" [section] value2 = 1 """ f = io.StringIO(s) c = load_config(f, ext=".toml") newf = io.StringIO() dump_config(c, newf, ext=".ini") newf.seek(0) assert c == load_config(newf, ext=".ini")
def test_cli_result(args, result, config_format, capsys): cli_result = cli.run(args) assert cli_result == result if config_format: out = capsys.readouterr().out parsed = load_config(StringIO(out), ext=config_format) assert parsed == result
def test_dump_load_python_yaml(conf, ext, tmp): if not os.path.exists(tmp): with open(tmp + ext, "w"): pass dump_config(conf, tmp, ext=ext) conf_ = load_config(tmp + ext, disambiguate=True) assert jsonify(conf, str_keys=False) == jsonify(conf_, str_keys=False) os.remove(tmp + ext)
def load_config_from_file(filename) -> Dict[str, Any]: conf = load_config(filename) if not isinstance(conf, dict): warn( "Warning: the loaded config does not appear to be a key-value mapping; a call to " "logging.config.dictConfig or configure_logging will fail.") return conf
def test_dump_load_class_instances(ext, conf, tmp): dump_config(conf, tmp, ext=ext) conf_ = load_config(tmp, disambiguate=True) models = construct_instances_recursively(conf) models_ = construct_instances_recursively(conf_) for m in (models, models_): for v in m.values(): assert isinstance(v, BaseEstimator) assert models_.keys() == models.keys() for k in models: m1 = models[k] m2 = models_[k] c = conf[k] for attr in c[KWARGS_KEY]: attr1 = getattr(m1, attr) if ext == ".json": attr1 = jsonify(attr1) assert attr1 == getattr(m2, attr)
def test_dump_load_json(conf, tmp): ext = ".json" dump_config(conf, tmp, ext=ext) conf_ = load_config(tmp, disambiguate=True) assert jsonify(conf) == conf_