def test_mainWindowExit(self, qtbot, mocker): mocker.patch('PyQt5.QtWidgets.QMainWindow.close') mw = SpotMotionMonitor() mw.show() qtbot.addWidget(mw) mw.actionExit.trigger() assert QMainWindow.close.call_count == 1
def test_mainWindowAbout(self, qtbot, mocker): mocker.patch( 'spot_motion_monitor.views.main_window.SpotMotionMonitor.about') mw = SpotMotionMonitor() mw.show() qtbot.addWidget(mw) mw.actionAbout.trigger() assert SpotMotionMonitor.about.call_count == 1
def test_cameraMenu(self, qtbot, mocker): mocker.patch( 'spot_motion_monitor.views.main_window.SpotMotionMonitor.handleCameraSelection' ) mw = SpotMotionMonitor() mw.show() qtbot.addWidget(mw) numCameras = len(mw.cameraController.getAvailableCameras()) assert len(mw.menuCamera.actions()) == numCameras # Force camera setup mw.cameraController.setupCamera('GaussianCamera') assert mw.menuCamera.isEnabled() is True qtbot.mouseClick(mw.cameraControl.startStopButton, Qt.LeftButton) assert mw.menuCamera.isEnabled() is False
def test_updateStatusBar(self, qtbot): mw = SpotMotionMonitor() mw.show() qtbot.addWidget(mw) message1 = "Hello World!" mw.cameraController.updater.displayStatus.emit( message1, ONE_SECOND_IN_MILLISECONDS) assert mw.statusbar.currentMessage() == message1 message2 = "Have a nice evening!" mw.plotController.updater.displayStatus.emit( message2, ONE_SECOND_IN_MILLISECONDS) assert mw.statusbar.currentMessage() == message2 message3 = "See you later!" mw.dataController.updater.displayStatus.emit( message3, ONE_SECOND_IN_MILLISECONDS) assert mw.statusbar.currentMessage() == message3
def test_saveConfiguration(self, qtbot, mocker): mw = SpotMotionMonitor() mw.show() qtbot.addWidget(mw) # Force camera setup mw.cameraController.setupCamera('GaussianCamera') truthFile = "./configuration.yaml" mask = mw.getSaveConfigurationMask() assert mask == 0 mw._saveFileDialog = mocker.Mock(return_value=truthFile) mw.saveConfiguration() assert os.path.exists(truthFile) os.remove(truthFile)
def test_configurationMenu(self, qtbot): mw = SpotMotionMonitor() mw.show() qtbot.addWidget(mw) # Force camera setup mw.cameraController.setupCamera('GaussianCamera') assert mw.actionCameraConfig.isEnabled() is True assert mw.actionPlotsConfig.isEnabled() is True assert mw.actionDataConfig.isEnabled() is True assert mw.actionGeneralConfig.isEnabled() is True assert mw.actionCameraInfo.isEnabled() is False qtbot.mouseClick(mw.cameraControl.startStopButton, Qt.LeftButton) assert mw.actionCameraConfig.isEnabled() is False assert mw.actionPlotsConfig.isEnabled() is True assert mw.actionDataConfig.isEnabled() is True assert mw.actionGeneralConfig.isEnabled() is True assert mw.actionCameraInfo.isEnabled() is True
def test_setConfiguration(self, qtbot, mocker): mw = SpotMotionMonitor() mw.show() qtbot.addWidget(mw) # Force camera setup mw.cameraController.setupCamera('GaussianCamera') filename = "test_config.yaml" self.write_config(filename) mw.setConfiguration(filename) assert mw.cameraController.doAutoRun is True assert mw.dataController.getGeneralConfiguration( ).configVersion == "1.5.2" assert mw.dataController.getDataConfiguration( ).buffer.bufferSize == 512 os.remove(filename)
def test_saveConfigurationMask(self, qtbot): mw = SpotMotionMonitor() mw.show() qtbot.addWidget(mw) # Force camera setup mw.cameraController.setupCamera('GaussianCamera') mask = mw.getSaveConfigurationMask() assert mask == 0 mw.actionWritePlotConfig.setChecked(True) mask = mw.getSaveConfigurationMask() assert mask == 1 mw.actionWriteEmptyConfig.setChecked(True) mask = mw.getSaveConfigurationMask() assert mask == 3 mw.actionWritePlotConfig.setChecked(False) mask = mw.getSaveConfigurationMask() assert mask == 2
def test_autoRun(self, qtbot, mocker): mw = SpotMotionMonitor() mw.show() qtbot.addWidget(mw) # Force camera setup mw.cameraController.setupCamera('GaussianCamera') mockCameraControllerAutoRun = mocker.patch.object( mw.cameraController, 'autoRun') args = collections.namedtuple('args', [ 'profile', 'telemetry_dir', 'config_file', 'auto_run', 'vimba_camera_index' ]) args.telemetry_dir = None args.auto_run = True mw.handleConfig(args) mw.autoRunIfNecessary() assert mockCameraControllerAutoRun.call_count == 1
def test_commandLineConfiguration(self, qtbot, mocker): mw = SpotMotionMonitor() mw.show() qtbot.addWidget(mw) # Force camera setup mw.cameraController.setupCamera('GaussianCamera') args = collections.namedtuple('args', [ 'profile', 'telemetry_dir', 'config_file', 'auto_run', 'vimba_camera_index' ]) args.telemetry_dir = "/new/path/for/telemetry" args.auto_run = False filename = "test_new_config.yaml" args.config_file = filename self.write_config(filename) mw.handleConfig(args) assert mw.dataController.getDataConfiguration( ).fullTelemetrySavePath == args.telemetry_dir assert mw.dataController.bufferModel.bufferSize == 512 os.remove(filename)