Skip to content

Commit 2f880f1

Browse files
authored
Merge pull request #81 from imonlinux/test_suite
Comprehensive Test Suite Implementation (293 tests, 99.3% passing)
2 parents f822b6f + ebfa55c commit 2f880f1

31 files changed

Lines changed: 8495 additions & 16 deletions

.github/workflows/tests.yml

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
name: Tests
2+
3+
on:
4+
push:
5+
branches: [ main, upstream_refactor ]
6+
pull_request:
7+
branches: [ main, upstream_refactor ]
8+
workflow_dispatch:
9+
10+
jobs:
11+
test:
12+
runs-on: ${{ matrix.os }}
13+
strategy:
14+
fail-fast: false
15+
matrix:
16+
os: [ubuntu-latest]
17+
python-version: ['3.11', '3.12', '3.13']
18+
19+
steps:
20+
- uses: actions/checkout@v4
21+
22+
- name: Set up Python ${{ matrix.python-version }}
23+
uses: actions/setup-python@v5
24+
with:
25+
python-version: ${{ matrix.python-version }}
26+
cache: 'pip'
27+
28+
- name: Install system dependencies
29+
run: |
30+
sudo apt-get update
31+
sudo apt-get install -y \
32+
libportaudio2 \
33+
libmpv-dev \
34+
mpv \
35+
build-essential
36+
37+
- name: Install Python dependencies
38+
run: |
39+
python -m pip install --upgrade pip
40+
pip install pytest pytest-asyncio pytest-cov pytest-mock
41+
pip install -e .
42+
43+
- name: Install development dependencies
44+
run: |
45+
pip install black flake8 mypy pylint
46+
47+
- name: Lint with flake8
48+
run: |
49+
# Stop the build if there are Python syntax errors or undefined names
50+
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
51+
# Exit-zero treats all errors as warnings
52+
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
53+
54+
- name: Check formatting with black
55+
run: |
56+
black --check linux_voice_assistant/ tests/
57+
58+
- name: Type check with mypy
59+
run: |
60+
mypy linux_voice_assistant/ --ignore-missing-imports || true
61+
62+
- name: Run tests with pytest
63+
run: |
64+
pytest tests/ -v --tb=short --cov=linux_voice_assistant --cov-report=xml --cov-report=term-missing
65+
66+
- name: Upload coverage to Codecov
67+
uses: codecov/codecov-action@v4
68+
with:
69+
file: ./coverage.xml
70+
flags: unittests
71+
name: codecov-umbrella
72+
fail_ci_if_error: false
73+
74+
test-hardware:
75+
runs-on: [self-hosted, linux]
76+
if: github.event_name == 'workflow_dispatch'
77+
strategy:
78+
matrix:
79+
hardware: [xvf3800, resppeaker2mic]
80+
81+
steps:
82+
- uses: actions/checkout@v4
83+
84+
- name: Set up Python
85+
uses: actions/setup-python@v5
86+
with:
87+
python-version: '3.12'
88+
89+
- name: Install dependencies
90+
run: |
91+
python -m pip install --upgrade pip
92+
pip install pytest pytest-asyncio
93+
pip install -e .
94+
95+
- name: Run hardware-specific tests
96+
run: |
97+
pytest tests/ -v -m hardware -k ${{ matrix.hardware }}
98+
99+
test-performance:
100+
runs-on: ubuntu-latest
101+
if: github.event_name == 'workflow_dispatch'
102+
103+
steps:
104+
- uses: actions/checkout@v4
105+
106+
- name: Set up Python
107+
uses: actions/setup-python@v5
108+
with:
109+
python-version: '3.12'
110+
111+
- name: Install dependencies
112+
run: |
113+
python -m pip install --upgrade pip
114+
pip install pytest pytest-benchmark
115+
pip install -e .
116+
117+
- name: Run performance benchmarks
118+
run: |
119+
pytest tests/ -v -m benchmark --benchmark-only
120+
121+
security-scan:
122+
runs-on: ubuntu-latest
123+
124+
steps:
125+
- uses: actions/checkout@v4
126+
127+
- name: Run security scan
128+
run: |
129+
pip install bandit
130+
bandit -r linux_voice_assistant/ -f json -o bandit-report.json || true
131+
132+
- name: Upload security scan results
133+
uses: actions/upload-artifact@v4
134+
with:
135+
name: security-scan-results
136+
path: bandit-report.json

README.md

Lines changed: 87 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@ linux-voice-assistant/
236236
│   ├── linux-voice-assistant-xvf3800.md     # ReSpeaker XVF3800 4-Mic USB Array configuration
237237
│   ├── linux-voice-assistant-xvf3800-mute.md # Hardware mute button and LED sync details
238238
│   ├── lva-desktop.md             # Running LVA on a Linux desktop with the tray client
239+
│   ├── testing-guide.md         # Comprehensive testing documentation
239240
│   └── xvf3800_legacy_led_effects_mapping.md # LED functions when running firmware older than 2.0.7
240241
├── linux_voice_assistant
241242
│   ├── api_server.py             # ESPHome API server
@@ -250,9 +251,11 @@ linux-voice-assistant/
250251
│   ├── __init__.py
251252
│   ├── led_controller.py             # LED effects and state mapping
252253
│   ├── __main__.py                 # Application entry point
254+
│   ├── microwakeword.py # Micro wake word detection module
253255
│   ├── models.py                 # Shared state and data models
254256
│   ├── mpv_player.py             # Media playback via mpv
255257
│   ├── mqtt_controller.py             # MQTT discovery and entity management
258+
│   ├── openwakeword.py # Open wake word detection module
256259
│   ├── satellite.py             # ESPHome voice assistant protocol
257260
│   ├── sendspin                 # Sendspin client subsystem
258261
│   │   ├── client.py             # WebSocket connection and protocol
@@ -302,13 +305,30 @@ linux-voice-assistant/
302305
│   │   └── timer_finished.flac
303306
│   └── wakeup                 # Wake word triggered sounds
304307
│   └── wake_word_triggered.flac
305-
├── tests
306-
│   ├── lva_mic_capture.py
307-
│   ├── ok_nabu.wav
308-
│   ├── test_microwakeword.py
309-
│   ├── test_openwakeword.py
310-
│   ├── xvf3800_hid_mute_probe.py
311-
│   └── xvf3800_probe.py
308+
├── tests # Comprehensive test suite (293 tests, 99.3% passing)
309+
│ ├── README.md # Test documentation
310+
│ ├── conftest.py # Shared pytest fixtures
311+
│ ├── diagnose_imports.py # Import diagnostic utility
312+
│ ├── test_audio_engine.py # Audio engine tests
313+
│ ├── test_button_controller.py # Button controller tests
314+
│ ├── test_configuration.py # Configuration management tests
315+
│ ├── test_end_to_end_workflows.py # End-to-end integration tests
316+
│ ├── test_event_bus.py # Event system architecture tests
317+
│ ├── test_format_mac.py # MAC address formatting tests
318+
│ ├── test_led_controller.py # LED control tests
319+
│ ├── test_microwakeword.py # MicroWakeWord detection tests
320+
│ ├── test_mqtt_controller.py # MQTT integration tests
321+
│ ├── test_openwakeword.py # OpenWakeWord detection tests
322+
│ ├── test_sendspin_client.py # Sendspin client tests
323+
│ ├── test_sendspin_discovery.py # Sendspin discovery tests
324+
│ ├── test_state_management.py # State management tests
325+
│ ├── test_volume_management.py # Volume control tests
326+
│ ├── test_xvf3800_button_controller.py # XVF3800 button hardware tests
327+
│ ├── test_xvf3800_led_backend.py # XVF3800 LED hardware tests
328+
│ ├── lva_mic_capture.py # Audio capture utility
329+
│ ├── ok_nabu.wav # Test audio file
330+
│ ├── xvf3800_hid_mute_probe.py # XVF3800 hardware probe
331+
│ └── xvf3800_probe.py # XVF3800 device probe
312332
├── wakewords                 # Wake word models
313333
│   ├── alexa.json
314334
│   ├── alexa.tflite
@@ -359,6 +379,66 @@ linux-voice-assistant/
359379

360380
---
361381

382+
## Development & Testing
383+
384+
### Running Tests
385+
386+
The project includes a comprehensive test suite covering the fork's new architecture:
387+
388+
```bash
389+
# Install development dependencies
390+
./script/setup --dev
391+
392+
# Run all tests
393+
./script/test
394+
395+
# Run specific test file
396+
./script/test test_event_bus.py
397+
398+
# Run with coverage report
399+
pytest tests/ --cov=linux_voice_assistant --cov-report=html
400+
401+
# Run specific test with verbose output
402+
pytest tests/test_event_bus.py -v
403+
404+
# Run excluding hardware tests
405+
pytest tests/ -m "not hardware"
406+
```
407+
408+
### Test Structure
409+
410+
- **Unit Tests**: Core architecture (EventBus, State, Configuration)
411+
- **Integration Tests**: Controllers and hardware abstractions
412+
- **Hardware Tests**: Physical device integration (XVF3800, ReSpeaker)
413+
- **End-to-End Tests**: Complete voice assistant workflows
414+
415+
### Current Test Status
416+
417+
- **Total Tests**: 293
418+
- **Passing**: 291 (99.3%)
419+
- **Skipped**: 2 (hardware-dependent tests)
420+
- **Test Framework**: pytest 7.4.4 with asyncio, mock, and coverage support
421+
422+
See [Testing Guide](docs/testing-guide.md) for detailed testing documentation and [tests/README.md](tests/README.md) for test-specific information.
423+
424+
### Code Quality
425+
426+
```bash
427+
# Format code
428+
black linux_voice_assistant/ tests/
429+
430+
# Lint code
431+
flake8 linux_voice_assistant/ tests/
432+
433+
# Type checking
434+
mypy linux_voice_assistant/
435+
436+
# Run diagnostics
437+
python tests/diagnose_imports.py
438+
```
439+
440+
---
441+
362442
## License
363443

364444
Licensed under the [Apache License 2.0](LICENSE.md).

0 commit comments

Comments
 (0)