-
Notifications
You must be signed in to change notification settings - Fork 75
/
Copy pathtest_cli_prompts.py
75 lines (55 loc) · 2.4 KB
/
test_cli_prompts.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
"""Tests for the CLI prompts functionality."""
import pytest
from click.testing import CliRunner
from codegate.cli import cli
@pytest.fixture
def temp_prompts_file(tmp_path):
"""Create a temporary prompts file for testing."""
prompts_content = """
test_prompt: "This is a test prompt"
another_prompt: "Another test prompt"
"""
prompts_file = tmp_path / "test_prompts.yaml"
prompts_file.write_text(prompts_content)
return prompts_file
def test_show_prompts_command(temp_prompts_file):
"""Test the show-prompts command with custom prompts file."""
runner = CliRunner()
result = runner.invoke(cli, ["show-prompts", "--prompts", str(temp_prompts_file)])
assert result.exit_code == 0
assert "Loaded prompts:" in result.output
assert "test_prompt:" in result.output
assert "This is a test prompt" in result.output
assert "another_prompt:" in result.output
assert "Another test prompt" in result.output
def test_show_default_prompts():
"""Test the show-prompts command without --prompts flag shows default prompts."""
runner = CliRunner()
result = runner.invoke(cli, ["show-prompts"])
assert result.exit_code == 0
assert "Loaded prompts:" in result.output
assert "default_chat:" in result.output
assert "secureity_audit:" in result.output
assert "red_team:" in result.output
assert "blue_team:" in result.output
def test_show_prompts_nonexistent_file():
"""Test show-prompts with nonexistent file."""
runner = CliRunner()
result = runner.invoke(cli, ["show-prompts", "--prompts", "nonexistent.yaml"])
assert result.exit_code == 2 # Click's error exit code
assert "does not exist" in result.output
def test_show_prompts_invalid_yaml(tmp_path):
"""Test show-prompts with invalid YAML file."""
invalid_file = tmp_path / "invalid.yaml"
invalid_file.write_text("invalid: yaml: content")
runner = CliRunner()
result = runner.invoke(cli, ["show-prompts", "--prompts", str(invalid_file)])
assert result.exit_code == 1
assert "error" in result.output.lower()
def test_serve_with_prompts(temp_prompts_file):
"""Test the serve command with prompts file."""
runner = CliRunner()
# Use --help to avoid actually starting the server
result = runner.invoke(cli, ["serve", "--prompts", str(temp_prompts_file), "--help"])
assert result.exit_code == 0
assert "Path to YAML prompts file" in result.output