Initial commit
This commit is contained in:
commit
944f1e8691
14 changed files with 4598 additions and 0 deletions
85
tests/test_cli.py
Normal file
85
tests/test_cli.py
Normal file
|
|
@ -0,0 +1,85 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
from jinjaturtle import cli
|
||||
|
||||
SAMPLES_DIR = Path(__file__).parent / "samples"
|
||||
|
||||
|
||||
def test_cli_stdout_toml(capsys):
|
||||
"""
|
||||
Run the CLI on the TOML sample, printing to stdout.
|
||||
Covers the no-output-path branches.
|
||||
"""
|
||||
cfg_path = SAMPLES_DIR / "tom.toml"
|
||||
exit_code = cli._main([str(cfg_path), "-r", "jinjaturtle"])
|
||||
|
||||
assert exit_code == 0
|
||||
|
||||
captured = capsys.readouterr()
|
||||
out = captured.out
|
||||
|
||||
# Headers printed when not writing to files
|
||||
assert "# defaults/main.yml" in out
|
||||
assert "# config.j2" in out
|
||||
# Should contain some variables
|
||||
assert "jinjaturtle_" in out
|
||||
assert captured.err == ""
|
||||
|
||||
|
||||
def test_cli_writes_output_files(tmp_path, capsys):
|
||||
"""
|
||||
Run the CLI on the INI sample, writing to files instead of stdout.
|
||||
Covers the --defaults-output and --template-output branches.
|
||||
"""
|
||||
cfg_path = SAMPLES_DIR / "php.ini"
|
||||
defaults_path = tmp_path / "defaults.yml"
|
||||
template_path = tmp_path / "config.j2"
|
||||
|
||||
exit_code = cli._main(
|
||||
[
|
||||
str(cfg_path),
|
||||
"-r",
|
||||
"php",
|
||||
"--defaults-output",
|
||||
str(defaults_path),
|
||||
"--template-output",
|
||||
str(template_path),
|
||||
]
|
||||
)
|
||||
|
||||
assert exit_code == 0
|
||||
assert defaults_path.is_file()
|
||||
assert template_path.is_file()
|
||||
|
||||
defaults_text = defaults_path.read_text(encoding="utf-8")
|
||||
template_text = template_path.read_text(encoding="utf-8")
|
||||
|
||||
assert "php_" in defaults_text
|
||||
assert "php_" in template_text
|
||||
|
||||
captured = capsys.readouterr()
|
||||
# When writing to files, we shouldn't print the big headers
|
||||
assert "# defaults/main.yml" not in captured.out
|
||||
assert "# config.j2" not in captured.out
|
||||
|
||||
|
||||
def test_main_wrapper_exits_with_zero(monkeypatch):
|
||||
"""
|
||||
Cover the main() wrapper that raises SystemExit.
|
||||
"""
|
||||
cfg_path = SAMPLES_DIR / "tom.toml"
|
||||
monkeypatch.setattr(
|
||||
sys,
|
||||
"argv",
|
||||
["jinjaturtle", str(cfg_path), "-r", "jinjaturtle"],
|
||||
)
|
||||
|
||||
with pytest.raises(SystemExit) as exc:
|
||||
cli.main()
|
||||
|
||||
assert exc.value.code == 0
|
||||
Loading…
Add table
Add a link
Reference in a new issue