95 lines
4.3 KiB
Python
95 lines
4.3 KiB
Python
"""Tests for transmit command signal generation."""
|
|
|
|
from click.testing import CliRunner
|
|
|
|
from src.ria_toolkit_oss.ria_toolkit_oss_cli.cli import cli
|
|
|
|
|
|
class TestTransmitGenerate:
|
|
"""Test signal generation in transmit command."""
|
|
|
|
def test_transmit_help(self):
|
|
"""Test transmit command help."""
|
|
runner = CliRunner()
|
|
result = runner.invoke(cli, ["transmit", "--help"])
|
|
assert result.exit_code == 0
|
|
assert "Generate signal instead of loading from file" in result.output
|
|
assert "lfm" in result.output
|
|
assert "chirp" in result.output
|
|
assert "sine" in result.output
|
|
assert "pulse" in result.output
|
|
|
|
def test_generate_lfm_chirp(self):
|
|
"""Test LFM chirp generation (should fail without device)."""
|
|
runner = CliRunner()
|
|
result = runner.invoke(cli, ["transmit", "--generate", "lfm", "--device", "pluto", "-v"])
|
|
# Should fail because no device is connected, but should show it's generating LFM
|
|
# Error will be about device initialization, not about missing input file
|
|
assert "Generating LFM chirp signal" in result.output or "Failed to initialize" in result.output
|
|
|
|
def test_generate_sine_wave(self):
|
|
"""Test sine wave generation (should fail without device)."""
|
|
runner = CliRunner()
|
|
result = runner.invoke(cli, ["transmit", "--generate", "sine", "--device", "pluto", "-v"])
|
|
# Should fail because no device is connected, but should show it's generating sine
|
|
assert "Generating sine wave signal" in result.output or "Failed to initialize" in result.output
|
|
|
|
def test_generate_chirp(self):
|
|
"""Test simple chirp generation (should fail without device)."""
|
|
runner = CliRunner()
|
|
result = runner.invoke(cli, ["transmit", "--generate", "chirp", "--device", "pluto", "-v"])
|
|
# Should fail because no device is connected, but should show it's generating chirp
|
|
assert "Generating chirp signal" in result.output or "Failed to initialize" in result.output
|
|
|
|
def test_generate_pulse(self):
|
|
"""Test pulse generation (should fail without device)."""
|
|
runner = CliRunner()
|
|
result = runner.invoke(cli, ["transmit", "--generate", "pulse", "--device", "pluto", "-v"])
|
|
# Should fail because no device is connected, but should show it's generating pulse
|
|
assert "Generating pulse signal" in result.output or "Failed to initialize" in result.output
|
|
|
|
def test_default_generates_lfm_when_no_input(self):
|
|
"""Test that default generates LFM chirp when no input file specified."""
|
|
runner = CliRunner()
|
|
result = runner.invoke(cli, ["transmit", "--device", "pluto", "-v"])
|
|
# Should default to LFM chirp when no input file or --generate specified
|
|
assert "Generating LFM chirp signal" in result.output or "Failed to initialize" in result.output
|
|
|
|
def test_generate_overrides_input_file(self):
|
|
"""Test that --generate overrides --input file."""
|
|
runner = CliRunner()
|
|
result = runner.invoke(
|
|
cli, ["transmit", "--device", "pluto", "--input", "nonexistent.sigmf", "--generate", "lfm", "-v"]
|
|
)
|
|
# Should generate LFM, not try to load nonexistent.sigmf
|
|
assert "Generating LFM chirp signal" in result.output or "Failed to initialize" in result.output
|
|
# Should NOT say "Input file not found"
|
|
assert "Input file not found" not in result.output
|
|
|
|
def test_signal_generation_parameters(self):
|
|
"""Test that signal generation uses correct parameters from CLI."""
|
|
runner = CliRunner()
|
|
result = runner.invoke(
|
|
cli,
|
|
[
|
|
"transmit",
|
|
"--device",
|
|
"pluto",
|
|
"--generate",
|
|
"lfm",
|
|
"--sample-rate",
|
|
"10e6",
|
|
"--center-frequency",
|
|
"915M",
|
|
"--gain",
|
|
"-20",
|
|
"-v",
|
|
],
|
|
)
|
|
# Check that parameters are shown in output
|
|
if "Failed to initialize" in result.output:
|
|
# Device initialization failed (expected without real device)
|
|
assert "10.00 MHz" in result.output or "10.000 MHz" in result.output or "10.00 MS/s" in result.output
|
|
assert "915" in result.output
|
|
assert "-20 dB" in result.output or "-20.0 dB" in result.output
|