|
M
madrigal
262d6ce9ee
Some checks failed
Build Sphinx Docs Set / Build Docs (pull_request) Successful in 1m29s
Test with tox / Test with tox (3.11) (pull_request) Failing after 34s
Test with tox / Test with tox (3.12) (pull_request) Failing after 33s
Test with tox / Test with tox (3.10) (pull_request) Failing after 1m15s
Build Project / Build Project (3.10) (pull_request) Successful in 2m34s
Build Project / Build Project (3.11) (pull_request) Successful in 2m39s
Build Project / Build Project (3.12) (pull_request) Successful in 2m35s
|
|||
|---|---|---|---|
| .. | |||
| __init__.py | |||
| README.md | |||
| test_capture.py | |||
| test_common.py | |||
| test_convert.py | |||
| test_discover | |||
| test_generate.py | |||
| test_split.py | |||
| test_transmit_generate.py | |||
| test_transmit.py | |||
| test.combine.py | |||
CLI Tests
Comprehensive test suite for the utils CLI commands.
Test Structure
test_common.py- Tests for common CLI utilities (YAML loading, metadata parsing, frequency formatting)test_discover.py- Tests for device discovery functionalitytest_capture.py- Tests for the capture commandtest_transmit.py- Tests for the transmit command
Running Tests
Run all CLI tests:
poetry run pytest tests/utils_cli/ -v
Run specific test file:
poetry run pytest tests/utils_cli/test_common.py -v
poetry run pytest tests/utils_cli/test_discover.py -v
poetry run pytest tests/utils_cli/test_capture.py -v
Run specific test class or function:
poetry run pytest tests/utils_cli/test_capture.py::TestCaptureCommand::test_capture_basic -v
poetry run pytest tests/utils_cli/test_common.py::test_parse_frequency -v
Run with coverage:
poetry run pytest tests/utils_cli/ --cov=utils_cli --cov-report=html
Test Coverage
test_common.py
- YAML configuration file loading
- Metadata KEY=VALUE parsing
- Frequency parsing (scientific notation, suffixes)
- Frequency and sample rate formatting
test_discover.py
- Device discovery for all supported SDR types (PlutoSDR, HackRF, BladeRF, USRP, RTL-SDR, ThinkRF)
- Device auto-selection logic
- Device connection testing
- CLI command options (--verbose, --json-output, --test, --type)
- Error handling for missing devices and multiple devices
test_capture.py
- Basic capture functionality
- Parameter validation (sample rate, center frequency, duration/num-samples)
- Device auto-selection
- Multiple output formats (SigMF, NPY, WAV, Blue)
- Format auto-detection from file extension
- YAML configuration file loading
- Custom metadata handling
- Gain and bandwidth configuration
- Visualization saving (--save-image)
- Chunked capture for large recordings
- Verbose and quiet output modes
- Proper device cleanup on errors
test_transmit.py
- TX device initialization (PlutoSDR, HackRF, BladeRF, USRP only)
- RX-only device rejection (RTL-SDR, ThinkRF)
- TX device auto-selection
- Input file loading (SigMF, NPY, WAV, Blue)
- Legacy NPY format support
- TX gain validation and range checking
- Sample rate mismatch warnings
- Transmission modes:
- Single transmission
- Repeat mode with delays
- Continuous transmission with safety warnings
- YAML configuration file loading
- Safety confirmations for continuous mode
- Proper device cleanup on errors
- Verbose and quiet output modes
Mock Strategy
Tests use unittest.mock to:
- Mock SDR device instances to avoid requiring actual hardware
- Mock file I/O operations
- Mock discovery functions to simulate different device scenarios
- Verify proper function calls and parameters
Adding New Tests
When adding new CLI commands, follow this pattern:
- Create
test_<command>.pyin this directory - Use Click's
CliRunnerfor testing CLI commands - Mock external dependencies (SDR devices, file I/O)
- Test both success and error cases
- Verify proper resource cleanup (device.close(), file handles, etc.)
Example:
from click.testing import CliRunner
from unittest.mock import patch, MagicMock
def test_new_command():
runner = CliRunner()
with patch('module.dependency') as mock_dep:
mock_dep.return_value = expected_value
result = runner.invoke(command, ['--option', 'value'])
assert result.exit_code == 0
assert 'expected output' in result.output
CI/CD Integration
These tests are designed to run in CI/CD pipelines without requiring actual SDR hardware. All hardware interactions are mocked.
Notes
- Tests use temporary directories for file operations (cleaned up automatically)
- Device mocks simulate real SDR behavior without hardware dependencies
- Tests verify both command-line interface and underlying function behavior