def test_read_no_delim(self): delim = "" fileName = "good_delim.txt" QTest.qWaitForWindowActive(ReadFileTests.gui) QtCore.QTimer.singleShot(1000, lambda: inject(QApplication.activeModalWidget(), delim)) QTest.keyPress(ReadFileTests.gui, Qt.Key_F, Qt.ControlModifier | Qt.ShiftModifier) QTest.keyRelease(ReadFileTests.gui, Qt.Key_F, Qt.ControlModifier | Qt.ShiftModifier) self.assertEqual(core._attributes, []) self.assertEqual(ReadFileTests.gui.ui.schemaLine.text(), "")
def test_no_file(self): QTest.qWaitForWindowActive(DatabaseTests.gui) QtCore.QTimer.singleShot( 2000, lambda: QTest.keyPress(QApplication.activeModalWidget(), Qt. Key_Escape)) QTest.keyPress(DatabaseTests.gui, Qt.Key_I, Qt.ControlModifier) QTest.keyRelease(DatabaseTests.gui, Qt.Key_I, Qt.ControlModifier) self.assertEqual(core._attributes, []) self.assertEqual(core._fds, []) self.assertEqual(core._cover, []) self.assertEqual(DatabaseTests.gui.ui.schemaLine.text(), "")
def test_if_key_presses_registered_as_action(self, row_chosen, qtbot, key, row, expected_action): # GIVEN main window displayed and a row selected - handled by fixture # WHEN action key pressed # self.mark_rows_with_actions(row, key) QTest.keyPress(self.ui, key, Qt.NoModifier, 100) QTest.keyRelease(self.ui, key) # THEN Action column value changed to action data = list() for i in range(7): index = self.ui.model.createIndex(row, i) data.append(index.data(Qt.DisplayRole)) assert data[Column.Action.index] == expected_action assert data[Column.Processed.index] is False
def test_good_file_multi_table(self): fileName = "database.db" QTest.qWaitForWindowActive(DatabaseTests.gui) QtCore.QTimer.singleShot( 1000, lambda: inject(QApplication.activeModalWidget(), fileName)) QtCore.QTimer.singleShot( 2000, lambda: inject(QApplication.activeModalWidget(), "Beers")) QTest.keyPress(DatabaseTests.gui, Qt.Key_I, Qt.ControlModifier) QTest.keyRelease(DatabaseTests.gui, Qt.Key_I, Qt.ControlModifier) self.assertEqual(core._attributes, ['name', 'manf']) self.assertEqual(core._fds, []) self.assertEqual(core._cover, []) self.assertEqual(DatabaseTests.gui.ui.schemaLine.text(), "name,manf")
def mark_rows_with_keys(self, rows, keys): actions = self.convert_keys_to_actions(keys) for row, key, action in zip(rows, keys, actions): if row == -1: row = self.ui.model.rowCount(0) - 1 self.ui.tableView.selectRow(row) QTest.keyPress(self.ui, key, Qt.NoModifier, 100) QTest.keyRelease(self.ui, key) data = list() for i in range(7): index = self.ui.model.createIndex(row, i) data.append(index.data(Qt.DisplayRole)) # group = data[Column.Group.index] assert data[Column.Action.index] == action.value assert data[Column.Processed.index] is False
def test_processing_changes_table_values(self, row_chosen, qtbot, key, row, expected_action, expected_processed): # todo reuse same logic among tests # GIVEN actions assigned to some files QTest.keyPress(self.ui, key, Qt.NoModifier, 100) QTest.keyRelease(self.ui, key) data = list() for i in range(7): index = self.ui.model.createIndex(row, i) data.append(index.data(Qt.DisplayRole)) assert data[Column.Action.index] == expected_action assert data[Column.Processed.index] is False # WHEN click Execute Action button QTest.mouseClick(self.ui.pushButton_2, Qt.LeftButton) # THEN Processed set == True where Action is not empty data.clear() for i in range(7): index = self.ui.model.createIndex(row, i) data.append(index.data(Qt.DisplayRole)) assert data[Column.Processed.index] == expected_processed
def release_key(self, key): if KeyboardLayout.is_modifier(key): self._modifiers &= ~KeyboardLayout.modifier_code(key) else: QTest.keyRelease(self._widget_under_cursor(), KeyboardLayout.key_code(key), self._modifiers)
def test_group_validations_popup_message_shown(self, main_window_displayed, group_to_mark, keys, qtbot): # GIVEN actions assigned to all members of some range if group_to_mark == -1: # if group is -1 then take last group in the table last_index_row = self.ui.model.rowCount(0) - 1 last_group_value_index = self.ui.model.createIndex( last_index_row, Column.Group.index) group_to_mark = last_group_value_index.data(Qt.DisplayRole) indexes_of_group = self.ui.model.find_indexes_of_value( Column.Group.index, group_to_mark) if len(keys) == 1: for index in indexes_of_group: self.ui.tableView.selectRow(index.row()) QTest.keyPress(self.ui, keys[0], Qt.NoModifier, 0) QTest.keyRelease(self.ui, keys[0]) data = list() for i in range(7): index = self.ui.model.createIndex(index.row(), i) data.append(index.data(Qt.DisplayRole)) # group = data[Column.Group.index] # assert data[Column.Action.index] == expected_action todo activate assert data[Column.Processed.index] is False else: for index, key in zip(indexes_of_group, keys): self.ui.tableView.selectRow(index.row()) QTest.keyPress(self.ui, key, Qt.NoModifier, 0) QTest.keyRelease(self.ui, key) data = list() for i in range(7): index = self.ui.model.createIndex(index.row(), i) data.append(index.data(Qt.DisplayRole)) # group = data[Column.Group.index] # assert data[Column.Action.index] == expected_action todo activate assert data[Column.Processed.index] is False # WHEN click Execute Action button QTest.mouseClick(self.ui.pushButton_2, Qt.LeftButton) # THEN popup shown with ranges which will be fully removed # QTimer.singleShot(1000, handle_popup_waiting) assert self.ui.files_exterminated_question_window.isActiveWindow() assert self.ui.files_exterminated_question_window.isVisible() assert str( group_to_mark) in self.ui.files_exterminated_question_window.text( ) # todo test proper format # WHEN clicked Cancel buttons = self.ui.files_exterminated_question_window.buttons() no_button = None yes_button = None for button in buttons: if 'No' in button.text(): no_button = button elif 'Yes' in button.text(): yes_button = button QTest.mouseClick(no_button, Qt.LeftButton) # THEN actions not executed and files not touched assert not self.ui.files_exterminated_question_window.isActiveWindow() assert not self.ui.files_exterminated_question_window.isVisible() # todo assert files exist # todo add validation of popup text # WHEN click Execute Action button again QTest.mouseClick(self.ui.pushButton_2, Qt.LeftButton) # THEN popup shown with ranges which will be fully removed assert self.ui.files_exterminated_question_window.isActiveWindow() assert self.ui.files_exterminated_question_window.isVisible() # WHEN clicked Yes QTest.mouseClick(yes_button, Qt.LeftButton) # THEN actions applied to duplicates, files removed assert not self.ui.files_exterminated_question_window.isActiveWindow() assert not self.ui.files_exterminated_question_window.isVisible() # todo assert files not exist assert 1
def set_file(self, fileName): QTest.qWaitForWindowActive(CoverEqualityTests.gui) QtCore.QTimer.singleShot(2000, lambda: inject(QApplication.activeModalWidget(), fileName)) QTest.keyPress(CoverEqualityTests.gui, Qt.Key_O, Qt.ControlModifier) QTest.keyRelease(CoverEqualityTests.gui, Qt.Key_O, Qt.ControlModifier)
def set_file(self, delim, fileName): QTest.qWaitForWindowActive(ReadFileTests.gui) QtCore.QTimer.singleShot(1000, lambda: inject(QApplication.activeModalWidget(), delim)) QtCore.QTimer.singleShot(2000, lambda: inject(QApplication.activeModalWidget(), fileName)) QTest.keyPress(ReadFileTests.gui, Qt.Key_F, Qt.ControlModifier | Qt.ShiftModifier) QTest.keyRelease(ReadFileTests.gui, Qt.Key_F, Qt.ControlModifier | Qt.ShiftModifier)