This repository has been archived on 2024-06-02. You can view files and clone it, but cannot push or open issues or pull requests.
spud-py/tests/test_cli.py
Marc Cataford d09f0398d3
Some checks failed
/ Tests (push) Successful in 39s
/ Static Analysis (push) Failing after 42s
ci: lint + format + test on push
fix: ensure ci lints all source files

chore: formatting
2024-04-13 00:58:21 -04:00

57 lines
1.6 KiB
Python

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)}."
)