-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathtest_cli.py
More file actions
46 lines (34 loc) · 1.95 KB
/
Copy pathtest_cli.py
File metadata and controls
46 lines (34 loc) · 1.95 KB
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
import pytest
from click.testing import CliRunner
from unittest.mock import patch
from bootstraprag.cli import cli, download_and_extract_template # replace 'your_cli_module' with the actual module name
@pytest.fixture
def runner():
return CliRunner()
def test_create_project_without_overwrite(runner):
# Mock Path.exists to simulate that the project directory already exists
with patch('pathlib.Path.exists', return_value=True), \
patch('shutil.copytree') as mock_copy, \
patch('InquirerPy.inquirer.select') as mock_inquirer_select:
# Ensure copytree wasn't called since the directory exists
mock_copy.assert_not_called()
# Ensure no prompt was triggered
mock_inquirer_select.assert_not_called()
# The prompts should not be triggered because the function should exit early
result = runner.invoke(cli, ['create', 'test_project'])
# Assert that the command exited with success (in this case we expect no project creation)
assert result.exit_code == 0, f"Exit code was {result.exit_code}, output: {result.output}"
assert "Error: Project directory test_project already exists!" in result.output
def test_framework_selection_llamaindex(runner):
with patch('InquirerPy.inquirer.select.execute', return_value='llamaindex'):
result = runner.invoke(cli, ['create', 'test_project'])
assert result.exit_code == 0
assert 'You have selected framework: llamaindex' in result.output
def test_download_and_extract_template_with_observability():
with patch('shutil.copytree') as mock_copy:
download_and_extract_template('test_project', 'llamaindex', 'simple-rag', 'Yes')
mock_copy.assert_called_once()
def test_download_and_extract_template_without_observability():
with patch('shutil.copytree') as mock_copy:
download_and_extract_template('test_project', 'llamaindex', 'simple-rag', 'No')
mock_copy.assert_called_once()