def test_volt(): config = Configuration() config.read('config/test_config.ini') assert config.volt_device == 'test_volt_device' assert config.volt_interval == 1.5
class App(): def __init__(self): self.CONFIG_FILENAME = 'config/config.ini' self._config = None self._api = None self._gpsDevice = None self._accelDevice = None self._thermoDevice = None self._voltDevice = None self._baroDevice = None self._obdDevice = None self.read_configuration_file() self.configure_obd() self.configure_gps() self.configure_thermo() self.configure_acceleromenter() self.configure_volt() self.configure_baro() self._deviceList = DeviceCollection(thermoDevice=self._thermoDevice, gpsDevice=self._gpsDevice, accelDevice=self._accelDevice, voltDevice=self._voltDevice, baroDevice=self._baroDevice, obdDevice=self._obdDevice) self._manager = Manager(self._config, self._deviceList) def read_configuration_file(self): self._config = Configuration() self._config.read(self.CONFIG_FILENAME) def configure_obd(self): if self._config.obd_device == "obd": self._obdDevice = OBDDevice() elif self._config.obd_device == "mock": self._obdDevice = MockOBDDevice() else: print("incorrect obd config") def configure_gps(self): if self._config.gps_device == "fixed_mock": self._gpsDevice = MockFixedGPSDevice() elif self._config.gps_device == "gps3": self._gpsDevice = GPS3Device() else: print("incorrect gps config") def configure_thermo(self): if self._config.thermo_device == 'fixed_mock': self._thermoDevice = MockFixedThermoDevice() elif self._config.thermo_device == 'rising_mock': self._thermoDevice = MockRisingThermoDevice() elif self._config.thermo_device == "mpu": self._thermoDevice = MPUThermoDevice() else: print("incorrect thermo config") def configure_acceleromenter(self): if self._config.accel_device == "fixed_mock": self._accelDevice = MockFixedAccelDevice() elif self._config.accel_device == "mpu": self._accelDevice = MPUAccelDevice() else: print("incorrect accel config") def configure_volt(self): if self._config.volt_device == 'mock': self._voltDevice = MockVoltDevice() else: print("incorrect volt config") def configure_baro(self): if self._config.baro_device == 'mock': self._baroDevice = MockBaroDevice() else: print("incorrect baro config") def run(self): self._manager.print_all_accumulator_means()
def test_accel(): config = Configuration() config.read('config/test_config.ini') assert config.accel_device == 'test_accel_device' assert config.accel_interval == 1.3
def test_baro(): config = Configuration() config.read('config/test_config.ini') assert config.baro_device == 'test_baro_device' assert config.baro_interval == 1.4
def test_manager(): config = Configuration() config.read('config/test_config.ini') assert config.manager_moving_average_items == 3 assert config.manager_print_interval == 0.7
def test_gps(): config = Configuration() config.read('config/test_config.ini') assert config.gps_device == 'test_gps_device' assert config.gps_interval == 1.1
def test_obd(): config = Configuration() config.read('config/test_config.ini') assert config.obd_device == 'test_obd_device' assert config.rpm_interval == 0.8 assert config.speed_interval == 0.9
class SettingsDialog(QtWidgets.QDialog): def __init__(self, parent=None): QtWidgets.QDialog.__init__(self, parent) # temporary Configuration which saves the current changes self._tmp = Configuration() self._tmp.read() vbox = QtWidgets.QVBoxLayout() tab_widget = QtWidgets.QTabWidget() graphics_page = GraphicsSettingsPage(tab_widget, self._tmp) path_page = PathSettingsPage(tab_widget, self._tmp) comp_page = ComputationSettingsPage(tab_widget, self._tmp) self.cutoff_history_entries_for_deletion = lambda: comp_page.tw_cutoff_history.history_entries_for_deletion self.cutoff_preset_entries_for_deletion = lambda: comp_page.tw_cutoff_presets.preset_entries_for_deletion # Ok, Cancel and Restore defaults Buttons ok = QtWidgets.QPushButton('Ok', self) cancel = QtWidgets.QPushButton('Cancel', self) restore_btn = QtWidgets.QPushButton('Restore defaults', self) ok.clicked.connect(self.ok) cancel.clicked.connect(self.cancel) restore_btn.clicked.connect(self.restore_defaults) tab_widget.addTab(graphics_page, 'graphics') tab_widget.addTab(path_page, 'path') tab_widget.addTab(comp_page, 'computation') vbox.addWidget(tab_widget) hbox = QtWidgets.QHBoxLayout() hbox.addStretch() hbox.addWidget(ok) hbox.addStretch() hbox.addWidget(cancel) hbox.addStretch() hbox.addWidget(restore_btn) hbox.addStretch() vbox.addLayout(hbox) self.setLayout(vbox) self.exec_() def ok(self): global config self._tmp.save() config.read() cutoff_history.remove_list(self.cutoff_history_entries_for_deletion()) cutoff_history.save() cutoff_presets.remove_list(self.cutoff_preset_entries_for_deletion()) cutoff_presets.save() self.accept() for widget in QtWidgets.QApplication.topLevelWidgets(): for gl_widget in widget.findChildren(GLWidget): gl_widget.update_needed = True QtWidgets.QApplication.postEvent(gl_widget, UpdateGLEvent()) def restore_defaults(self): reply = QtWidgets.QMessageBox.question(self, 'Message', "Are you sure to restore the defaults?", QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.No, QtWidgets.QMessageBox.No) if reply == QtWidgets.QMessageBox.Yes: self._tmp = Configuration() self._tmp.save() config.read() self.accept() def cancel(self): self.reject()
class SettingsDialog(QtWidgets.QDialog): def __init__(self, parent=None): QtWidgets.QDialog.__init__(self, parent) # temporary Configuration which saves the current changes self._tmp = Configuration() self._tmp.read() vbox = QtWidgets.QVBoxLayout() tab_widget = QtWidgets.QTabWidget() graphics_page = GraphicsSettingsPage(tab_widget, self._tmp) path_page = PathSettingsPage(tab_widget, self._tmp) comp_page = ComputationSettingsPage(tab_widget, self._tmp) self.cutoff_history_entries_for_deletion = lambda: comp_page.tw_cutoff_history.history_entries_for_deletion self.cutoff_preset_entries_for_deletion = lambda: comp_page.tw_cutoff_presets.preset_entries_for_deletion # Ok, Cancel and Restore defaults Buttons ok = QtWidgets.QPushButton('Ok', self) cancel = QtWidgets.QPushButton('Cancel', self) restore_btn = QtWidgets.QPushButton('Restore defaults', self) ok.clicked.connect(self.ok) cancel.clicked.connect(self.cancel) restore_btn.clicked.connect(self.restore_defaults) tab_widget.addTab(graphics_page, 'graphics') tab_widget.addTab(path_page, 'path') tab_widget.addTab(comp_page, 'computation') vbox.addWidget(tab_widget) hbox = QtWidgets.QHBoxLayout() hbox.addStretch() hbox.addWidget(ok) hbox.addStretch() hbox.addWidget(cancel) hbox.addStretch() hbox.addWidget(restore_btn) hbox.addStretch() vbox.addLayout(hbox) self.setLayout(vbox) self.exec_() def ok(self): global config self._tmp.save() config.read() cutoff_history.remove_list(self.cutoff_history_entries_for_deletion()) cutoff_history.save() cutoff_presets.remove_list(self.cutoff_preset_entries_for_deletion()) cutoff_presets.save() self.accept() for widget in QtWidgets.QApplication.topLevelWidgets(): for gl_widget in widget.findChildren(GLWidget): gl_widget.update_needed = True QtWidgets.QApplication.postEvent(gl_widget, UpdateGLEvent()) def restore_defaults(self): reply = QtWidgets.QMessageBox.question( self, 'Message', "Are you sure to restore the defaults?", QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.No, QtWidgets.QMessageBox.No) if reply == QtWidgets.QMessageBox.Yes: self._tmp = Configuration() self._tmp.save() config.read() self.accept() def cancel(self): self.reject()