def test_serializing_config(config: Config): work_dir = mkdtemp() path = Path(work_dir) / "olivertwist.yml" ConfigIO.write(config, path) assert ConfigIO.read(path) == ConfigIO.read(PATH_TO_VALID_CONFIG)
def config(config_path): """Interactively create or edit configuration file""" config_path = Path(config_path or ConfigIO.DEFAULT_CONFIG_FILE_PATH) logging.debug(config_path) try: config_obj = ConfigIO.read(config_path) except FileNotFoundError: config_obj = Config.empty() config_obj = Configurator.update(config_obj) ConfigIO.write(config_obj, config_path) click.echo(f"Created/updated config in {config_path}")
def test_config_with_config_file_existing(_): runner = CliRunner() config_path = "twisted.yml" dummy_rule_config = RuleConfig("a", enabled=False) with runner.isolated_filesystem(): ConfigIO.write(Config(universal=[dummy_rule_config]), config_path) result = runner.invoke(main, ["config", "--config=twisted.yml"]) assert result.exit_code == 0 assert result.output == f"Created/updated config in {config_path}\n" assert (ConfigIO.read(config_path) == Config.empty() ), "existing config not overwritten"