47 lines
1.3 KiB
Python
47 lines
1.3 KiB
Python
import pytest
|
|
from target_simulator.gui.main_view import MainView
|
|
from target_simulator.core.models import Target
|
|
|
|
|
|
class DummyCommunicator:
|
|
def __init__(self):
|
|
self.sent_commands = []
|
|
self.is_open = True
|
|
|
|
def send_commands(self, commands):
|
|
self.sent_commands.extend(commands)
|
|
return True
|
|
|
|
def connect(self, cfg):
|
|
self.is_open = True
|
|
return True
|
|
|
|
def disconnect(self):
|
|
self.is_open = False
|
|
|
|
|
|
@pytest.fixture
|
|
def main_view(tmp_path, monkeypatch):
|
|
# Create a MainView but avoid opening the Tk mainloop
|
|
mv = MainView()
|
|
# Replace actual communicators with dummy to avoid I/O
|
|
dummy = DummyCommunicator()
|
|
mv.target_communicator = dummy
|
|
return mv
|
|
|
|
|
|
def test_reset_radar_state_sends_atomic_tgtset(main_view):
|
|
mv = main_view
|
|
# Ensure that the communicator reports open
|
|
assert mv.target_communicator.is_open
|
|
|
|
# Call the reset function
|
|
result = mv._reset_radar_state()
|
|
|
|
# Expect success
|
|
assert result is True
|
|
# Verify that two commands were sent: preparatory $mex.t_rows=80 then tgtset /-s
|
|
assert len(mv.target_communicator.sent_commands) == 2
|
|
assert mv.target_communicator.sent_commands[0].strip() == "$mex.t_rows=80"
|
|
assert mv.target_communicator.sent_commands[1].strip() == "tgtset /-s"
|