87 lines
2.3 KiB
Python
87 lines
2.3 KiB
Python
"""Tests for CLI."""
|
|
|
|
import os
|
|
import subprocess
|
|
import sys
|
|
|
|
|
|
def test_version_flag():
|
|
"""Test --version flag works."""
|
|
result = subprocess.run(
|
|
[sys.executable, "-m", "flow", "--version"],
|
|
capture_output=True, text=True,
|
|
)
|
|
assert result.returncode == 0
|
|
assert "flow" in result.stdout
|
|
|
|
|
|
def test_help_flag():
|
|
"""Test --help shows commands."""
|
|
result = subprocess.run(
|
|
[sys.executable, "-m", "flow", "--help"],
|
|
capture_output=True, text=True,
|
|
)
|
|
assert result.returncode == 0
|
|
assert "dotfiles" in result.stdout
|
|
assert "packages" in result.stdout
|
|
assert "setup" in result.stdout
|
|
|
|
|
|
def test_dotfiles_help():
|
|
result = subprocess.run(
|
|
[sys.executable, "-m", "flow", "dotfiles", "--help"],
|
|
capture_output=True, text=True,
|
|
)
|
|
assert result.returncode == 0
|
|
assert "link" in result.stdout
|
|
assert "unlink" in result.stdout
|
|
|
|
|
|
def test_packages_help():
|
|
result = subprocess.run(
|
|
[sys.executable, "-m", "flow", "packages", "--help"],
|
|
capture_output=True, text=True,
|
|
)
|
|
assert result.returncode == 0
|
|
assert "install" in result.stdout
|
|
|
|
|
|
def test_invalid_config_is_reported_without_traceback(tmp_path):
|
|
config_root = tmp_path / "config"
|
|
(config_root / "flow").mkdir(parents=True)
|
|
(config_root / "flow" / "config.yaml").write_text(":\n bad\n")
|
|
|
|
env = dict(os.environ)
|
|
env["XDG_CONFIG_HOME"] = str(config_root)
|
|
result = subprocess.run(
|
|
[sys.executable, "-m", "flow", "completion"],
|
|
capture_output=True,
|
|
text=True,
|
|
env=env,
|
|
)
|
|
assert result.returncode == 1
|
|
assert "Invalid YAML" in result.stderr
|
|
assert "Traceback" not in result.stderr
|
|
|
|
|
|
def test_local_manifest_is_loaded(tmp_path):
|
|
config_root = tmp_path / "config"
|
|
flow_dir = config_root / "flow"
|
|
flow_dir.mkdir(parents=True)
|
|
(flow_dir / "manifest.yaml").write_text(
|
|
"profiles:\n"
|
|
" demo:\n"
|
|
" os: linux\n"
|
|
)
|
|
|
|
env = dict(os.environ)
|
|
env["XDG_CONFIG_HOME"] = str(config_root)
|
|
result = subprocess.run(
|
|
[sys.executable, "-m", "flow", "setup", "list"],
|
|
capture_output=True,
|
|
text=True,
|
|
env=env,
|
|
)
|
|
assert result.returncode == 0
|
|
assert "demo" in result.stdout
|