99 lines
2.7 KiB
Python
99 lines
2.7 KiB
Python
"""Tests for zsh completion."""
|
|
|
|
import subprocess
|
|
|
|
from flow.app.completion import complete
|
|
from flow.core.config import AppConfig, FlowContext
|
|
from flow.core.console import Console
|
|
from flow.core.platform import PlatformInfo
|
|
from flow.core.runtime import SystemRuntime
|
|
|
|
|
|
def _make_ctx():
|
|
return FlowContext(
|
|
config=AppConfig(),
|
|
manifest={},
|
|
platform=PlatformInfo(),
|
|
console=Console(color=False),
|
|
runtime=SystemRuntime(),
|
|
)
|
|
|
|
|
|
def test_complete_top_level():
|
|
result = complete(_make_ctx(), ["flow", ""], 1)
|
|
assert "dotfiles" in result
|
|
assert "packages" in result
|
|
assert "setup" in result
|
|
assert "remote" in result
|
|
assert "dev" in result
|
|
assert "projects" in result
|
|
|
|
|
|
def test_complete_top_level_prefix():
|
|
result = complete(_make_ctx(), ["flow", "do"], 1)
|
|
assert result == ["dotfiles"]
|
|
|
|
|
|
def test_complete_dotfiles_subcommands():
|
|
result = complete(_make_ctx(), ["flow", "dotfiles", ""], 2)
|
|
assert "link" in result
|
|
assert "unlink" in result
|
|
assert "status" in result
|
|
assert "edit" in result
|
|
assert "repos" in result
|
|
# Removed commands should not appear
|
|
assert "sync" not in result
|
|
assert "relink" not in result
|
|
assert "undo" not in result
|
|
assert "clean" not in result
|
|
assert "modules" not in result
|
|
|
|
|
|
def test_complete_dotfiles_repos_subcommands():
|
|
result = complete(_make_ctx(), ["flow", "dotfiles", "repos", ""], 3)
|
|
assert "list" in result
|
|
assert "status" in result
|
|
assert "pull" in result
|
|
assert "push" in result
|
|
|
|
|
|
def test_complete_dotfiles_repos_pull_flags():
|
|
result = complete(_make_ctx(), ["flow", "dotfiles", "repos", "pull", "--"], 4)
|
|
assert "--repo" in result
|
|
assert "--dry-run" in result
|
|
|
|
|
|
def test_complete_dotfiles_edit_packages():
|
|
result = complete(_make_ctx(), ["flow", "dotfiles", "edit", "--"], 3)
|
|
assert "--no-commit" in result
|
|
|
|
|
|
def test_complete_dotfiles_link_flags():
|
|
result = complete(_make_ctx(), ["flow", "dotfiles", "link", "--"], 3)
|
|
assert "--profile" in result
|
|
assert "--dry-run" in result
|
|
|
|
|
|
def test_complete_unknown_command():
|
|
result = complete(_make_ctx(), ["flow", "unknown", ""], 2)
|
|
assert result == []
|
|
|
|
|
|
def test_complete_packages_subcommands():
|
|
result = complete(_make_ctx(), ["flow", "packages", ""], 2)
|
|
assert "install" in result
|
|
assert "remove" in result
|
|
assert "list" in result
|
|
|
|
|
|
def test_complete_dev_attach_returns_empty_on_timeout():
|
|
ctx = _make_ctx()
|
|
|
|
def fake_ps(**kwargs):
|
|
assert kwargs["timeout"] == 1.0
|
|
raise subprocess.TimeoutExpired("docker ps", kwargs["timeout"])
|
|
|
|
ctx.runtime.containers.ps = fake_ps # type: ignore[method-assign]
|
|
result = complete(ctx, ["flow", "dev", "attach", ""], 3)
|
|
assert result == []
|