You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

21 lines
1.2 KiB

import time
from pathlib import Path
import pytest
from src.gui.experiment_controller import ExperimentController
from src.gui.gui_models import GuiExperimentRequest
CONFIG=str(Path(__file__).parents[1]/"config"/"experiment.yaml")
class FakeApp:
instances=[]
def __init__(self,config,**kwargs):self.stop=False;self.paused=False;self.kwargs=kwargs;FakeApp.instances.append(self)
def run(self):
while not self.stop:time.sleep(.005)
def request_stop(self):self.stop=True
def request_pause(self):self.paused=True
def request_resume(self):self.paused=False
def test_controller_start_stop_pause_without_camera()->None:
c=ExperimentController(FakeApp);c.start_experiment(GuiExperimentRequest(config_path=CONFIG));time.sleep(.02)
assert c.is_running();c.pause_experiment();assert FakeApp.instances[-1].paused;c.resume_experiment();assert not FakeApp.instances[-1].paused;c.stop_experiment();time.sleep(.03);assert not c.is_running()
def test_controller_prevents_double_start()->None:
c=ExperimentController(FakeApp);c.start_experiment(GuiExperimentRequest(config_path=CONFIG));
with pytest.raises(RuntimeError):c.start_experiment(GuiExperimentRequest(config_path=CONFIG))
c.stop_experiment()