def test_getModel(qtbot): table_view = DeviceStateTableView() table_model = DeviceStateTableModel() qtbot.addWidget(table_view) table_view.setModel(table_model) assert table_model == table_view.getModel()
def test_rowCount(good_node_states, good_device_states): table_model = DeviceStateTableModel() for i, good_states in enumerate(good_node_states): table_model.setNodeStates(good_states) table_model.setDeviceStates(good_device_states[i]) assert table_model.rowCount() == len(good_device_states[i]) - 1
class DeviceStateTableView(QtWidgets.QTableView): """Possible states/combinations? of a device""" def __init__(self, parent=None): super().__init__(parent) self.setSizeAdjustPolicy( QtWidgets.QAbstractScrollArea.AdjustToContents) self._item_delegate = ValidatedDelegate(self, self.model) self.setItemDelegate(self._item_delegate) def setModel(self, value): super().setModel(value) self.__setupGUI() def getModel(self): return self.model() def setIconLayerList(self, value): self._item_delegate.setIconLayerList(value.names) def __setupGUI(self): header = self.horizontalHeader() for column in range(header.count()): header.setSectionResizeMode(column, QtWidgets.QHeaderView.ResizeToContents) for row in range(0, self.model().rowCount()): self.openPersistentEditor(self.model().index( row, self.model().isWarningColumn())) self.openPersistentEditor(self.model().index( row, self.model().isAlarmColumn())) self.openPersistentEditor(self.model().index( row, self.model().triggersActionColumn())) self.openPersistentEditor(self.model().index( row, self.model().logEntranceColumn())) font = QtGui.QFont("Helvetica", 14) self.setFont(font) deviceStateTableView = QtCore.pyqtProperty(type(DeviceStateTableModel()), getModel, setModel)
def test_manualEditData(qtbot, open_window): if TestingFlags.ENABLE_MANUAL_TESTING is False: return table_model = DeviceStateTableModel() node_states = [('output', ['close', 'open']), ('open_limit', ['is_not_open', 'is_open'])] device_states = [[ 'state', 'status', 'icon_layer', 'is_warning', 'warning_timeout', 'warning_message', 'is_alarm', 'alarm_timeout', 'alarm_message', 'triggers_action', 'action_timeout', 'action', 'log_entrance' ], [ 0, 'Closed', 'layer_0', False, 0.0, '', False, 0.0, '', False, 0.0, None, True ], [ 1, 'Opening', 'layer_0', False, 0.0, '', False, 0.0, '', False, 0.0, None, True ], [ 2, 'Closing', 'layer_1', False, 0.0, '', False, 0.0, '', False, 0.0, None, True ], [ 3, 'High', 'layer_0', False, 0.0, '', False, 0.0, '', False, 0.0, None, False ]] table_model.setNodeStates(node_states) table_model.setDeviceStates(device_states) table_view = open_window(DeviceStateTableView) table_view.setWindowTitle("Device State Table View") table_view.setModel(table_model) layer_list = ['layer_0', 'layer_1', 'layer_2', 'layer_3'] table_view.setIconLayerList(enum(layer_list)) message = QtWidgets.QMessageBox() message.setText( "Manual testing of the device state table view\n - Turning is_warning, is_alarm or triggers_action to False should make those non-editable" ) message.exec_() qtbot.stopForInteraction()
def test_flags(good_node_states, good_device_states, good_truth_tables): table_model = DeviceStateTableModel() for i, good_states in enumerate(good_node_states): table_model.setNodeStates(good_states) table_model.setDeviceStates(good_device_states[i]) #No editing of the truth table section flags = (QtCore.Qt.ItemIsEnabled | QtCore.Qt.ItemIsSelectable) for i, row in enumerate(good_truth_tables[i]): for j, val in enumerate(row): assert table_model.flags( table_model.index(i, j, QtCore.QModelIndex())) == flags #Always allow editing of status, icon_layer, is_warning, is_alarm, triggers_action, log_entrance flags = (QtCore.Qt.ItemIsEnabled | QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEditable) assert table_model.flags( table_model.index(0, table_model.statusColumn(), QtCore.QModelIndex())) == flags assert table_model.flags( table_model.index(0, table_model.iconLayerColumn(), QtCore.QModelIndex())) == flags assert table_model.flags( table_model.index(0, table_model.isWarningColumn(), QtCore.QModelIndex())) == flags assert table_model.flags( table_model.index(0, table_model.isAlarmColumn(), QtCore.QModelIndex())) == flags assert table_model.flags( table_model.index(0, table_model.triggersActionColumn(), QtCore.QModelIndex())) == flags assert table_model.flags( table_model.index(0, table_model.logEntranceColumn(), QtCore.QModelIndex())) == flags
def test_headerData(good_node_states, good_device_states): table_model = DeviceStateTableModel() for i, good_states in enumerate(good_node_states): table_model.setNodeStates(good_states) table_model.setDeviceStates(good_device_states[i]) #check vertical header for row in range(table_model.rowCount()): assert str(row) == table_model.headerData(row, QtCore.Qt.Vertical, QtCore.Qt.DisplayRole) #Check horizontal headers headers = [row[0] for row in good_states] headers = headers[::-1] for i, val in enumerate(headers): assert val == table_model.headerData(i, QtCore.Qt.Horizontal, QtCore.Qt.DisplayRole) assert 'Status' == table_model.headerData(table_model.statusColumn(), QtCore.Qt.Horizontal, QtCore.Qt.DisplayRole) assert 'Icon Layer\nName' == table_model.headerData( table_model.iconLayerColumn(), QtCore.Qt.Horizontal, QtCore.Qt.DisplayRole) assert 'Is Warning' == table_model.headerData( table_model.isWarningColumn(), QtCore.Qt.Horizontal, QtCore.Qt.DisplayRole) assert 'Warning\nTimeout (sec)' == table_model.headerData( table_model.warningTimeoutColumn(), QtCore.Qt.Horizontal, QtCore.Qt.DisplayRole) assert 'Warning Message' == table_model.headerData( table_model.warningMessageColumn(), QtCore.Qt.Horizontal, QtCore.Qt.DisplayRole) assert 'Is Alarm' == table_model.headerData( table_model.isAlarmColumn(), QtCore.Qt.Horizontal, QtCore.Qt.DisplayRole) assert 'Alarm\nTimeout (sec)' == table_model.headerData( table_model.alarmTimeoutColumn(), QtCore.Qt.Horizontal, QtCore.Qt.DisplayRole) assert 'Alarm Message' == table_model.headerData( table_model.alarmMessageColumn(), QtCore.Qt.Horizontal, QtCore.Qt.DisplayRole) assert 'Triggers\nAction' == table_model.headerData( table_model.triggersActionColumn(), QtCore.Qt.Horizontal, QtCore.Qt.DisplayRole) assert 'Action\nTimeout (sec)' == table_model.headerData( table_model.actionTimeoutColumn(), QtCore.Qt.Horizontal, QtCore.Qt.DisplayRole) assert 'Action' == table_model.headerData(table_model.actionColumn(), QtCore.Qt.Horizontal, QtCore.Qt.DisplayRole) assert 'Log Entrance' == table_model.headerData( table_model.logEntranceColumn(), QtCore.Qt.Horizontal, QtCore.Qt.DisplayRole)
def test_setDeviceStates(good_node_states, good_device_states): table_model = DeviceStateTableModel() for i, good_states in enumerate(good_node_states): assert True == table_model.setNodeStates(good_states) assert True == table_model.setDeviceStates(good_device_states[i]) assert good_device_states[i] == table_model.deviceStates() table_model.setNodeStates([('output', ['off', 'on'])]) with pytest.raises(TypeError): states = [[ 'istate', 'status', 'icon_layer', 'is_warning', 'warning_timeout', 'warning_message', 'is_alarm', 'alarm_timeout', 'alarm_message', 'triggers_action', 'action_timeout', 'action', 'log_entrance' ], [ 0, 'Device Off', 'layer_0', False, 0.0, '', False, 0.0, '', False, 0.0, None, True ], [ 1, 'Device On', 'layer_1', False, 0.0, '', False, 0.0, '', False, 0.0, None, True ]] table_model.setDeviceStates(states) with pytest.raises(ValueError): states = [[ 'state', 'status', 'icon_layer', 'is_warning', 'warning_timeout', 'warning_message', 'is_alarm', 'alarm_timeout', 'alarm_message', 'triggers_action', 'action_timeout', 'action', 'log_entrance' ], [ 1, 'Device Off', 'layer_0', False, 0.0, '', False, 0.0, '', False, 0.0, None, True ], [ 1, 'Device On', 'layer_1', False, 0.0, '', False, 0.0, '', False, 0.0, None, True ]] table_model.setDeviceStates(states) with pytest.raises(TypeError): states = [[ 'state', 'status', 'icon_layer', 'is_warning', 'warning_timeout', 'warning_message', 'is_alarm', 'alarm_timeout', 'alarm_message', 'triggers_action', 'action_timeout', 'action', 'log_entrance' ], [ 0, 'Device Off', False, False, 0.0, '', False, 0.0, '', False, 0.0, None, True ], [ 1, 'Device On', 'layer_1', False, 0.0, '', False, 0.0, '', False, 0.0, None, True ]] table_model.setDeviceStates(states)
def test_setNodeStates(good_node_states, good_truth_tables): table_model = DeviceStateTableModel() for i, good_states in enumerate(good_node_states): table_model.setNodeStates(good_states) assert good_truth_tables[i] == table_model.truthTable() with pytest.raises(TypeError): table_model.setNodeStates([(1, ['off', True])]) with pytest.raises(TypeError): table_model.setNodeStates([('output', ['off', True])]) with pytest.raises(TypeError): table_model.setNodeStates([('output', 'off', 'on')])