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 dc57ecd228
Some checks failed
/ Static Analysis (push) Failing after 29s
/ Tests (push) Failing after 16s
feat: scaffolding + init and print configuration
2024-04-12 01:09:56 -04:00

40 lines
1.5 KiB
Python

import pytest
import click
import pathlib
def test_init_raises_if_config_file_exists_default_path(invoke_cli, tmpdir, monkeypatch):
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, monkeypatch):
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, monkeypatch):
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, monkeypatch):
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)}."