Spaces:
Running
Running
Add unit tests for CLI
Browse files- tests/__init__.py +0 -0
- tests/unit/__init__.py +0 -0
- tests/unit/conftest.py +9 -0
- tests/unit/test_cli.py +97 -0
tests/__init__.py
ADDED
|
File without changes
|
tests/unit/__init__.py
ADDED
|
File without changes
|
tests/unit/conftest.py
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Pytest configuration file.
|
| 3 |
+
"""
|
| 4 |
+
import sys
|
| 5 |
+
from pathlib import Path
|
| 6 |
+
|
| 7 |
+
# Add the src directory to Python path for importing slidedeckai
|
| 8 |
+
src_path = Path(__file__).parent.parent / 'src'
|
| 9 |
+
sys.path.insert(0, str(src_path))
|
tests/unit/test_cli.py
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Unit tests for the cli module.
|
| 3 |
+
"""
|
| 4 |
+
from unittest.mock import patch, MagicMock
|
| 5 |
+
import sys
|
| 6 |
+
from pathlib import Path
|
| 7 |
+
|
| 8 |
+
import pytest
|
| 9 |
+
|
| 10 |
+
from slidedeckai.cli import (
|
| 11 |
+
group_models_by_provider,
|
| 12 |
+
format_models_as_bullets,
|
| 13 |
+
CustomArgumentParser,
|
| 14 |
+
main
|
| 15 |
+
)
|
| 16 |
+
from slidedeckai.global_config import GlobalConfig
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
def test_group_models_by_provider():
|
| 20 |
+
# Test with sample model names
|
| 21 |
+
test_models = [
|
| 22 |
+
'[az]azure/open-ai',
|
| 23 |
+
'[gg]gemini-2.0-flash',
|
| 24 |
+
'[gg]gemini-2.0-flash-lite',
|
| 25 |
+
'[to]deepseek-ai/DeepSeek-V3',
|
| 26 |
+
]
|
| 27 |
+
|
| 28 |
+
result = group_models_by_provider(test_models)
|
| 29 |
+
|
| 30 |
+
assert 'an' not in result
|
| 31 |
+
assert 'az' in result
|
| 32 |
+
assert len(result['gg']) == 2
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
def test_format_models_as_bullets():
|
| 36 |
+
test_models = [
|
| 37 |
+
'[az]azure/open-ai',
|
| 38 |
+
'[gg]gemini-2.0-flash',
|
| 39 |
+
'[gg]gemini-2.0-flash-lite',
|
| 40 |
+
'[to]deepseek-ai/DeepSeek-V3',
|
| 41 |
+
]
|
| 42 |
+
|
| 43 |
+
result = format_models_as_bullets(test_models)
|
| 44 |
+
print(result)
|
| 45 |
+
|
| 46 |
+
assert 'anthropic:' not in result
|
| 47 |
+
assert 'deepseek' in result
|
| 48 |
+
assert '• [gg]gemini-2.0-flash-lite' in result
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
def test_argument_parser_model_validation():
|
| 52 |
+
parser = CustomArgumentParser()
|
| 53 |
+
parser.add_argument(
|
| 54 |
+
'--model',
|
| 55 |
+
choices=GlobalConfig.VALID_MODELS.keys()
|
| 56 |
+
)
|
| 57 |
+
|
| 58 |
+
# Test valid model
|
| 59 |
+
valid_model = next(iter(GlobalConfig.VALID_MODELS.keys()))
|
| 60 |
+
args = parser.parse_args(['--model', valid_model])
|
| 61 |
+
assert args.model == valid_model
|
| 62 |
+
|
| 63 |
+
# Test invalid model
|
| 64 |
+
with pytest.raises(SystemExit):
|
| 65 |
+
parser.parse_args(['--model', 'invalid-model'])
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
@patch('slidedeckai.cli.SlideDeckAI')
|
| 69 |
+
def test_main_generate_command(mock_slidedeckai):
|
| 70 |
+
# Mock the SlideDeckAI instance
|
| 71 |
+
mock_instance = MagicMock()
|
| 72 |
+
mock_instance.generate.return_value = Path("test_presentation.pptx")
|
| 73 |
+
mock_slidedeckai.return_value = mock_instance
|
| 74 |
+
|
| 75 |
+
# Test generate command
|
| 76 |
+
test_args = [
|
| 77 |
+
'generate',
|
| 78 |
+
'--model', next(iter(GlobalConfig.VALID_MODELS.keys())),
|
| 79 |
+
'--topic', 'Test Topic'
|
| 80 |
+
]
|
| 81 |
+
|
| 82 |
+
with patch.object(sys, 'argv', ['slidedeckai'] + test_args):
|
| 83 |
+
main()
|
| 84 |
+
|
| 85 |
+
# Verify SlideDeckAI was called with correct parameters
|
| 86 |
+
mock_slidedeckai.assert_called_once()
|
| 87 |
+
mock_instance.generate.assert_called_once()
|
| 88 |
+
|
| 89 |
+
|
| 90 |
+
def test_main_list_models():
|
| 91 |
+
# Test --list-models flag
|
| 92 |
+
with patch.object(sys, 'argv', ['slidedeckai', '--list-models']):
|
| 93 |
+
with patch('builtins.print') as mock_print:
|
| 94 |
+
main()
|
| 95 |
+
mock_print.assert_called_once()
|
| 96 |
+
output = mock_print.call_args[0][0]
|
| 97 |
+
assert "Supported SlideDeck AI models:" in output
|