mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-11-27 04:49:47 +01:00
- Defaults and config aligned with English-first product surface - Adds/removes ASR/TTS paths; drops China-only provider implementations and bundled SenseVoice assets - Westernizes prompts, plugin/tool copy, connection and handler behavior on upstream fixes - Powermem max_tokens and OpenAI no-thinking guard preserved on downstream path |
||
|---|---|---|
| .. | ||
| css | ||
| images | ||
| js | ||
| resources | ||
| favicon.ico | ||
| README.md | ||
| test_news_plugin.py | ||
| test_page.html | ||
| test_runner.py | ||
| test_weather_plugin.py | ||
Xiaozhi Server Tests
This directory contains comprehensive tests for the Xiaozhi ESP32 Server functionality.
Test Files
test_weather_plugin.py- Tests for the weather plugin functionalitytest_news_plugin.py- Tests for the news plugin functionalitytest_runner.py- Test runner script for executing all tests
Running Tests
Run All Tests
python test_runner.py
Run Specific Test Modules
# Weather plugin tests only
python test_runner.py weather
# News plugin tests only
python test_runner.py news
Run Individual Test Files
python -m unittest test_weather_plugin
python -m unittest test_news_plugin
Run with Verbose Output
python -m unittest -v test_weather_plugin
Test Coverage
The tests cover:
Weather Plugin
- ✅ Weather condition mapping
- ✅ API data fetching (success/failure scenarios)
- ✅ Report formatting
- ✅ Caching functionality
- ✅ IP-based location detection
- ✅ Configuration validation
- ✅ Error handling
News Plugin
- ✅ RSS feed parsing
- ✅ News source configuration
- ✅ Category mapping
- ✅ Content detail fetching
- ✅ Source rotation and fallback
- ✅ Caching functionality
- ✅ Error handling
Dependencies
The tests require the following Python packages:
unittest(built-in)unittest.mock(built-in)requests(for API mocking)beautifulsoup4(for HTML parsing)
Mocking
Tests use unittest.mock to mock external dependencies:
- API calls (OpenWeatherMap, RSS feeds)
- Cache operations
- Network requests
- Configuration objects
Test Data
Mock data is provided for:
- Weather API responses
- RSS feed XML content
- News article HTML
- Configuration objects
- Error scenarios
Continuous Integration
These tests are designed to run in CI/CD environments and can be executed with:
# From project root
./run_tests.sh --python-only # Linux/Mac
run_tests.bat --python-only # Windows
Troubleshooting
Common Issues
- Import Errors: Ensure you're running from the project root directory
- Mock Failures: Check that mocked methods are called with expected parameters
- API Errors: Verify that external API calls are properly mocked
Debug Mode
Run tests with debug output:
python -m pdb test_runner.py
Contributing
When adding new functionality:
- Create corresponding test files following the naming convention
test_*.py - Add test cases for both success and failure scenarios
- Update this README with new test descriptions
- Ensure all tests pass before submitting changes
Documentation
For detailed testing documentation, see: docs/testing-guide.md