Initial upload: PatternForge CLI tool with pattern detection and boilerplate generation
This commit is contained in:
66
tests/test_cli.py
Normal file
66
tests/test_cli.py
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
import tempfile
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
from click.testing import CliRunner
|
||||||
|
|
||||||
|
from patternforge.cli import main
|
||||||
|
|
||||||
|
|
||||||
|
class TestCLI:
|
||||||
|
def test_cli_help(self) -> None:
|
||||||
|
runner = CliRunner()
|
||||||
|
result = runner.invoke(main, ["--help"])
|
||||||
|
assert result.exit_code == 0
|
||||||
|
assert "analyze" in result.output
|
||||||
|
|
||||||
|
def test_analyze_command(self) -> None:
|
||||||
|
runner = CliRunner()
|
||||||
|
with tempfile.TemporaryDirectory() as tmpdir:
|
||||||
|
py_file = Path(tmpdir) / "test.py"
|
||||||
|
py_file.write_text("def test(): pass\n")
|
||||||
|
result = runner.invoke(
|
||||||
|
main,
|
||||||
|
["analyze", tmpdir, "--language", "python", "--output", f"{tmpdir}/patterns.yaml"],
|
||||||
|
)
|
||||||
|
assert result.exit_code == 0
|
||||||
|
assert Path(tmpdir, "patterns.yaml").exists()
|
||||||
|
|
||||||
|
def test_template_create_command(self) -> None:
|
||||||
|
runner = CliRunner()
|
||||||
|
with tempfile.TemporaryDirectory() as tmpdir:
|
||||||
|
pattern_file = Path(tmpdir) / "patterns.yaml"
|
||||||
|
pattern_file.write_text("language: python\nsummary:\n primary_naming: snake_case")
|
||||||
|
result = runner.invoke(
|
||||||
|
main,
|
||||||
|
["template", "create", "cli-test", "--pattern", str(pattern_file)],
|
||||||
|
)
|
||||||
|
assert result.exit_code == 0
|
||||||
|
|
||||||
|
def test_generate_command(self) -> None:
|
||||||
|
runner = CliRunner()
|
||||||
|
with tempfile.TemporaryDirectory() as tmpdir:
|
||||||
|
pattern_file = Path(tmpdir) / "patterns.yaml"
|
||||||
|
pattern_file.write_text("language: python\nsummary:\n primary_naming: snake_case")
|
||||||
|
output_dir = Path(tmpdir) / "output"
|
||||||
|
result = runner.invoke(
|
||||||
|
main,
|
||||||
|
[
|
||||||
|
"template",
|
||||||
|
"create",
|
||||||
|
"gen-cli-test",
|
||||||
|
"--pattern",
|
||||||
|
str(pattern_file),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
assert result.exit_code == 0
|
||||||
|
result = runner.invoke(
|
||||||
|
main, ["generate", "gen-cli-test", "--output", str(output_dir)]
|
||||||
|
)
|
||||||
|
assert result.exit_code == 0
|
||||||
|
assert any(output_dir.iterdir())
|
||||||
|
|
||||||
|
def test_config_command(self) -> None:
|
||||||
|
runner = CliRunner()
|
||||||
|
result = runner.invoke(main, ["config"])
|
||||||
|
assert result.exit_code == 0
|
||||||
|
assert "Configuration" in result.output
|
||||||
Reference in New Issue
Block a user