import pathlib def test_init_raises_if_config_file_exists_default_path( invoke_cli, tmpdir ): expected_default_path = tmpdir / ".config" / "spud" / "config.json" pathlib.Path(expected_default_path).parent.mkdir(parents=True) expected_default_path.write("{}") result = invoke_cli(["init"]) assert result.exit_code == 1 assert ( str(result.exception) == f"File already exists ({str(expected_default_path)}), cannot initialize." ) def test_init_raises_if_config_file_exists_custom_path(invoke_cli, tmpdir): expected_default_path = tmpdir / "config.json" expected_default_path.write("{}") result = invoke_cli(["--config", str(expected_default_path), "init"]) assert result.exit_code == 1 assert ( str(result.exception) == f"File already exists ({str(expected_default_path)}), cannot initialize." ) def test_print_config_raises_if_no_config_file_default_path( invoke_cli, tmpdir ): expected_default_path = tmpdir / ".config" / "spud" / "config.json" result = invoke_cli(["print-config"]) assert result.exit_code == 1 assert ( str(result.exception) == f"Configuration file not found at {str(expected_default_path)}." ) def test_print_config_raises_if_no_config_file_custom_path( invoke_cli, tmpdir ): config_file = tmpdir / "config.json" result = invoke_cli(["--config", str(config_file), "print-config"]) assert result.exit_code == 1 assert ( str(result.exception) == f"Configuration file not found at {str(config_file)}." )