KumaCLI Tests
This directory contains the test suite for kumacli.
Running Tests
Prerequisites
Install test dependencies:
pip install -e ".[test]"
# or
pip install pytest pytest-cov
Run All Tests
# Using pytest directly
python3 -m pytest
# Using the test runner script
python3 run_tests.py
# From the project root
python3 -m pytest tests/
Run Specific Tests
# Test a specific file
pytest tests/test_info.py
# Test a specific class
pytest tests/test_monitor.py::TestMonitorCommands
# Test a specific method
pytest tests/test_monitor.py::TestMonitorCommands::test_pause_monitors_by_pattern
Run Tests with Coverage
pytest --cov=kumacli --cov-report=html
python run_tests.py --cov
Test Options
# Verbose output
pytest -v
# Stop on first failure
pytest -x
# Run tests in parallel (requires pytest-xdist)
pytest -n auto
Test Structure
conftest.py
- Shared fixtures and test configurationtest_info.py
- Tests for the info commandtest_monitor.py
- Tests for monitor commands (list, pause, resume)test_maintenance.py
- Tests for maintenance commandstest_client.py
- Tests for the KumaClient classtest_cli_integration.py
- Integration tests for CLI functionality
Test Coverage
The tests cover:
- ✅ Command argument parsing
- ✅ API method calls and responses
- ✅ Error handling and edge cases
- ✅ Help message functionality
- ✅ Monitor pause/resume operations
- ✅ Maintenance operations
- ✅ Client utility functions
- ✅ Integration between components
Mock Strategy
Tests use unittest.mock to:
- Mock the UptimeKumaApi calls
- Simulate API responses and errors
- Test command logic without requiring a live server
- Verify correct API method calls with expected parameters
Adding New Tests
When adding new functionality:
- Add unit tests for the new commands/methods
- Add integration tests if the feature involves multiple components
- Test both success and error cases
- Mock external dependencies (API calls, file operations)
- Use descriptive test names that explain what is being tested