def test_subscriptions(self): QTest.mouseClick(window.left_menu_button_subscriptions, Qt.LeftButton) self.screenshot(window, name="subscriptions_loading") self.wait_for_list_populated(window.subscribed_channels_list) self.screenshot(window, name="subscriptions") # Sort window.subscribed_channels_list.sortByColumn(1, 1) self.wait_for_list_populated(window.subscribed_channels_list) self.screenshot(window, name="subscriptions_sorted") max_items = min(window.subscribed_channels_list.model().total_items, 50) self.assertLessEqual(window.subscribed_channels_list.verticalHeader().count(), max_items) # Filter old_num_items = window.subscribed_channels_list.verticalHeader().count() QTest.keyClick(window.subscribed_channels_filter_input, '1') self.wait_for_list_populated(window.subscribed_channels_list) self.screenshot(window, name="subscriptions_filtered") self.assertLessEqual(window.subscribed_channels_list.verticalHeader().count(), old_num_items) window.subscribed_channels_filter_input.setText('') self.wait_for_list_populated(window.subscribed_channels_list) # Unsubscribe and subscribe again index = self.get_index_of_row(window.subscribed_channels_list, 0) window.subscribed_channels_list.on_subscribe_control_clicked(index) QTest.qWait(200) self.screenshot(window, name="unsubscribed") window.subscribed_channels_list.on_subscribe_control_clicked(index) QTest.qWait(200)
def continueFunc(dialog): page = dialog._pageForItem["Plugins"] item = dialog._itemByPath(["Plugins"]) item.setSelected(True) page.update(self._ONE_USERPLUGINS) titleCard = \ page.children()[0].children()[0].children()[0].children()[2] enableBtn = titleCard.children()[2].children()[2].buttons()[0] cancelButton = dialog.children()[3].children()[2] QTest.mouseClick(enableBtn, Qt.LeftButton) lenBeforeDelete = len(core.loadedPlugins()) titleCard._uninstallPlugin() self.assertEqual( lenBeforeDelete - 1, len(core.loadedPlugins()), 'Plugins should be one fewer after uninstall.') self.assertFalse(titleCard._pluginEntry['isLoaded'], 'Plugin should not be loaded anymore') name = titleCard._pluginEntry['modulename'] self.assertFalse( core.config()["PluginManager"]["Plugins"][name]["Enabled"], 'Plugin should not be enabled in enki config') dirpath = os.path.join(PLUGIN_DIR_PATH, 'testplugin0') self.assertFalse(os.path.exists(dirpath), 'Plugin directory should not exist') QTest.mouseClick(cancelButton, Qt.LeftButton)
def test_tripleSecSpinBox(self): '''测试用例 test_tripleSecSpinBox ''' print('*** testCase test_tripleSecSpinBox begin ***') self.form.setWindowTitle('开始测试用例 test_tripleSecSpinBox ') '''测试修改spinBox部件的最大最小值 测试它的最小和最大值作为读者的练习。 ''' self.setFormToZero() # tripleSecSpinBox在界面中的取值范围为 0 到 11, 将它的最大值设为 12,看是否显示正常。 self.form.ui.tripleSecSpinBox.setValue(12) print('* 当执行self.form.ui.tripleSecSpinBox.setValue(12) 后,ui.tripleSecSpinBox.value() => ' + str( self.form.ui.tripleSecSpinBox.value() ) ) self.assertEqual(self.form.ui.tripleSecSpinBox.value(), 11 ) # tripleSecSpinBox在界面中的取值范围为 0 到 11, 将它的最小值设为 -1, 看是否显示正常。 self.form.ui.tripleSecSpinBox.setValue(-1) print('* 当执行self.form.ui.tripleSecSpinBox.setValue(-1) 后,ui.tripleSecSpinBox.value() => ' + str( self.form.ui.tripleSecSpinBox.value() ) ) self.assertEqual(self.form.ui.tripleSecSpinBox.value(), 0 ) self.form.ui.tripleSecSpinBox.setValue(2) # 用鼠标左键按OK按钮 okWidget = self.form.ui.okBtn QTest.mouseClick(okWidget, Qt.LeftButton) self.assertEqual(self.form.getJiggers(), 2) print('*** testCase test_tripleSecSpinBox end ***')
def test_simulator_graphics_view(self): self.__setup_project() self.add_all_signals_to_simulator() stc = self.form.simulator_tab_controller # type: SimulatorTabController self.assertGreater(len(stc.simulator_config.get_all_items()), 0) self.assertEqual(len(stc.simulator_scene.selectedItems()), 0) # select first message messages = stc.simulator_scene.get_all_message_items() pos = stc.ui.gvSimulator.mapFromScene(messages[0].scenePos()) QTest.mouseClick(stc.ui.gvSimulator.viewport(), Qt.LeftButton, Qt.NoModifier, pos) self.assertEqual(len(stc.simulator_scene.selectedItems()), 1) self.assertIsInstance(stc.simulator_scene.selectedItems()[0], MessageItem) rules = [item for item in stc.simulator_scene.items() if isinstance(item, RuleItem)] self.assertEqual(len(rules), 0) self.menus_to_ignore = [w for w in QApplication.topLevelWidgets() if isinstance(w, QMenu)] timer = QTimer(self.form) timer.setInterval(1) timer.setSingleShot(True) timer.timeout.connect(self.__on_context_menu_simulator_graphics_view_timer_timeout) timer.start() stc.ui.gvSimulator.contextMenuEvent(QContextMenuEvent(QContextMenuEvent.Mouse, pos)) rules = [item for item in stc.simulator_scene.items() if isinstance(item, RuleItem)] self.assertEqual(len(rules), 1)
def test_whole_word(self): qpart = core.workspace().currentDocument().qutepart qpart.text = _TEXT_WHOLE_WORD # select first 'string' QTest.keyClick(core.mainWindow(), Qt.Key_F, Qt.ControlModifier) self.keyClicks("bar") self.assertEqual(qpart.cursorPosition[0], 1) # 2 items found self.keyClick(Qt.Key_F3) self.assertEqual(qpart.cursorPosition[0], 2) self.keyClick(Qt.Key_F3) self.assertEqual(qpart.cursorPosition[0], 1) # only 1 item found QTest.mouseClick(_findSearchController()._widget.cbWholeWord, Qt.LeftButton) self.assertEqual(qpart.cursorPosition[0], 2) self.keyClick(Qt.Key_F3) self.assertEqual(qpart.cursorPosition[0], 2) # not moved, only line 2 # only 1 item found in reg exp mode qpart.cursorPosition = (0, 0) QTest.mouseClick(_findSearchController()._widget.cbRegularExpression, Qt.LeftButton) self.assertEqual(qpart.cursorPosition[0], 2) self.keyClick(Qt.Key_F3) self.assertEqual(qpart.cursorPosition[0], 2) # not moved, only line 2
def continueFunc(dialog): page = dialog._pageForItem["Plugins"] item = dialog._itemByPath(["Plugins"]) item.setSelected(True) page.update(self._ONE_USERPLUGINS) titleCard = \ page.children()[0].children()[0].children()[0].children()[2] enableBtn = titleCard.children()[2].children()[2].buttons()[0] self.assertEqual("Enable", enableBtn.text(), "Buttontext differs from Enable") self.assertFalse(enableBtn.isDown(), 'Button should not be down') QTest.mouseClick(enableBtn, Qt.LeftButton) self.assertEqual("Disable", enableBtn.text(), "Buttontext differs from Disable") self.assertTrue(enableBtn.isDown(), 'Button should be down') self.assertEqual( "testplugin0", core.loadedPlugins()[-1].__module__, 'Last module name should be userplugins.testplugin0') lenBeforeClick = len(core.loadedPlugins()) QTest.mouseClick(enableBtn, Qt.LeftButton) self.assertEqual("Enable", enableBtn.text(), "Buttontext differs from Enable") self.assertFalse(enableBtn.isDown(), 'Button should not be down') self.assertEqual( lenBeforeClick - 1, len(core.loadedPlugins()), "Length of loaded plugins should be one fewer after undload.") QTest.keyClick(dialog, Qt.Key_Escape)
async def exec_test(): srv, port, url = await mock.create_server() self.addCleanup(srv.close) await asyncio.sleep(1) QTest.mouseClick(process_community.lineedit_server, Qt.LeftButton) QTest.keyClicks(process_community.lineedit_server, "127.0.0.1") QTest.mouseDClick(process_community.spinbox_port, Qt.LeftButton) process_community.spinbox_port.setValue(port) self.assertEqual(process_community.stacked_pages.currentWidget(), process_community.page_node, msg="Current widget : {0}".format(process_community.stacked_pages.currentWidget().objectName())) self.assertEqual(process_community.lineedit_server.text(), "127.0.0.1") self.assertEqual(process_community.spinbox_port.value(), port) QTest.mouseClick(process_community.button_connect, Qt.LeftButton) await asyncio.sleep(2) self.assertEqual(mock.get_request(0).method, 'GET') self.assertEqual(mock.get_request(0).url, '/network/peering') self.assertEqual(mock.get_request(1).method, 'GET') self.assertEqual(mock.get_request(1).url, '/wot/certifiers-of/7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ') for i in range(2, 5): self.assertEqual(mock.get_request(i).method, 'GET') self.assertEqual(mock.get_request(i).url, '/wot/lookup/7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ') self.assertEqual(process_community.stacked_pages.currentWidget(), process_community.page_node, msg="Current widget : {0}".format(process_community.stacked_pages.currentWidget().objectName())) self.assertEqual(process_community.label_error.text(), "Could not find your identity on the network.") process_community.close()
def test_edit_channel_rssfeeds(self): QTest.mouseClick(window.left_menu_button_my_channel, Qt.LeftButton) self.wait_for_variable("edit_channel_page.channel_overview") QTest.mouseClick(window.edit_channel_rss_feeds_button, Qt.LeftButton) self.screenshot(window, name="edit_channel_rssfeeds_loading") self.wait_for_list_populated(window.edit_channel_rss_feeds_list) self.screenshot(window, name="edit_channel_rssfeeds")
def test_delete_all(self): self.select_all() QTest.mouseClick(self.deleteButton, Qt.LeftButton) self.assert_elog_files_deleted() self.assert_elog_count_consistent()
def test_delete_one(self): self.select_first() QTest.mouseClick(self.deleteButton, Qt.LeftButton) self.assert_elog_count_equal(TEST_SET_SIZE - 1) self.assert_elog_count_consistent()
def exec_test(): yield from asyncio.sleep(2) urls = [mock.get_request(i).url for i in range(0, 7)] self.assertTrue( "/wot/certifiers-of/7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ" in urls, msg="Not found in {0}".format(urls), ) self.assertTrue( "/wot/lookup/7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ" in urls, msg="Not found in {0}".format(urls) ) self.assertTrue( "/wot/certified-by/7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ" in urls, msg="Not found in {0}".format(urls), ) # requests 1 to 3 are for getting certifiers-of and certified-by # on john, + a lookup QTest.keyClicks(identities_tab.edit_textsearch, "doe") QTest.mouseClick(identities_tab.button_search, Qt.LeftButton) yield from asyncio.sleep(2) req = 7 self.assertEqual(mock.get_request(req).method, "GET") self.assertEqual( mock.get_request(req).url, "/blockchain/memberships/FADxcH5LmXGmGFgdixSes6nWnC4Vb4pRUBYT81zQRhjn" ) req += 1 self.assertEqual(identities_tab.table_identities.model().rowCount(), 1) yield from asyncio.sleep(2) self.lp.call_soon(close_dialog)
async def exec_test(): srv, port, url = await self.mock_nice_blockchain.create_server() self.addCleanup(srv.close) identities_tab.change_account(self.account, self.password_asker) identities_tab.change_community(self.community) await asyncio.sleep(1) urls = [self.mock_nice_blockchain.get_request(i).url for i in range(0, 7)] self.assertTrue('/wot/certifiers-of/7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ' in urls, msg="Not found in {0}".format(urls)) self.assertTrue('/wot/lookup/7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ' in urls, msg="Not found in {0}".format(urls)) self.assertTrue('/wot/certified-by/7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ' in urls, msg="Not found in {0}".format(urls)) # requests 1 to 3 are for getting certifiers-of and certified-by # on john, + a lookup QTest.keyClicks(identities_tab.ui.edit_textsearch, "doe") QTest.mouseClick(identities_tab.ui.button_search, Qt.LeftButton) await asyncio.sleep(2) req = 8 self.assertEqual(self.mock_nice_blockchain.get_request(req).method, 'GET') self.assertEqual(self.mock_nice_blockchain.get_request(req).url, '/blockchain/memberships/FADxcH5LmXGmGFgdixSes6nWnC4Vb4pRUBYT81zQRhjn') req += 1 self.assertEqual(identities_tab.ui.table_identities.model().rowCount(), 1) await asyncio.sleep(2) self.lp.call_soon(close_dialog)
def test_click_selects_first(self): self.qpart.text = 'aaaa\nbbbb\ncccX\ndddd\ncccY' QTest.keyClicks(self.qpart, "ccc") QTest.mouseClick(self.qpart, Qt.LeftButton) QTest.keyClick(self.qpart, Qt.Key_Enter) self.assertEqual(self.qpart.text, 'cccY\naaaa\nbbbb\ncccX\ndddd\ncccY')
def test_set_with_mouse(self): self.qpart.text = '\n' * 5 secondBlock = self.qpart.document().findBlockByNumber(2) geometry = self.qpart.blockBoundingGeometry(secondBlock).translated(self.qpart.contentOffset()) QTest.mouseClick(self.qpart._markArea, Qt.LeftButton, Qt.NoModifier, QPoint(0, geometry.bottom() - 1)) self.assertEqual(self._markedBlocks(), [1])
def test_all_cif_values(self): item = self.myapp.ui.cifList_treeWidget.topLevelItem(3) self.myapp.ui.cifList_treeWidget.setCurrentItem(item) QTest.mouseClick(self.myapp.ui.allEntrysTab, Qt.LeftButton) self.assertEqual('Id', self.myapp.ui.allCifTreeWidget.topLevelItem(0).text(0)) self.assertEqual('250', self.myapp.ui.allCifTreeWidget.topLevelItem(0).text(1)) self.assertEqual('C107 H142 N14 O26', self.myapp.ui.allCifTreeWidget.topLevelItem(10).text(1)) self.assertEqual(263, self.myapp.ui.cifList_treeWidget.topLevelItemCount())
def test_download_start_stop_remove_recheck(self): self.go_to_and_wait_for_downloads() QTest.mouseClick(window.downloads_list.topLevelItem(0).progress_slider, Qt.LeftButton) QTest.mouseClick(window.stop_download_button, Qt.LeftButton) QTest.mouseClick(window.start_download_button, Qt.LeftButton) QTest.mouseClick(window.remove_download_button, Qt.LeftButton) self.screenshot(window, name="remove_download_dialog") QTest.mouseClick(window.downloads_page.dialog.buttons[2], Qt.LeftButton)
def test_video_player_page(self): self.go_to_and_wait_for_downloads() QTest.mouseClick(window.downloads_list.topLevelItem(0).progress_slider, Qt.LeftButton) QTest.mouseClick(window.play_download_button, Qt.LeftButton) self.screenshot(window, name="video_player_page") self.wait_for_signal(window.left_menu_playlist.list_loaded, no_args=True) self.screenshot(window, name="video_player_left_menu_loaded")
def test_gui_place_cell(self): self.g1.startGame() pos = next(self.pg.next_pos()) pos = [x + 1 for _, x in enumerate(pos)] button = self.g1.othelloLayout.itemAtPosition(*pos).widget() self.assertTrue(isinstance(button, CellButton)) QTest.mouseClick(button, Qt.LeftButton) self.assertEqual(self.g1.board.board[pos[0]][pos[1]].status, Status.BLACK)
def test_gui_over(self): self.g1.startGame() for pos in self.pg.next_pos(): pos = [x + 1 for _, x in enumerate(pos)] button = self.g1.othelloLayout.itemAtPosition(*pos).widget() QTest.mouseClick(button, Qt.LeftButton) self.assertTrue(self.g1.board.get_is_over())
def testPlayNullCard(self): spy = QSignalSpy(self._hand_panel.cardPlayed) self._hand_panel.setCards([None, None, None]) card, rect = random.choice(self._hand_panel.cards()) self.assertIsNone(card) point = (rect.topLeft() + QPointF(1, 1)).toPoint() QTest.mouseClick(self._hand_panel, Qt.LeftButton, Qt.NoModifier, point) self.assertFalse(spy, card)
def test_refresh_button(self): self.select_all() QTest.mouseClick(self.deleteButton, Qt.LeftButton) self.reset_test_set() QTest.mouseClick(self.refreshButton, Qt.LeftButton) self.assert_elog_files_exist() self.assert_elog_count_consistent()
async def exec_test(): contact_dialog.view.table_contacts.selectRow(0) contact_dialog.edit_contact() assert contact_dialog.view.edit_pubkey.text() == "7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ" assert contact_dialog.view.edit_name.text() == "alice" contact_dialog.view.edit_name.setText("john") QTest.mouseClick(contact_dialog.view.button_delete, Qt.LeftButton) assert len(contact_dialog.view.table_contacts.model().sourceModel().contacts_data) == 0 QTest.mouseClick(contact_dialog.view.button_box.button(QDialogButtonBox.Close), Qt.LeftButton)
def test_hint(): """Use the test db and verify the hint for one password.""" # Given: form = MainController.create(APP, *_get_test_db()) # When we get the hint: form.ui.combobox_password_nicknames.setCurrentText(NICK1) QTest.mouseClick(form.ui.button_hint, Qt.LeftButton) # Then it matches what we created: assert form.ui.label_resp_body.text() == HINT1
def test_sync8(self): """Test with javascript disabled.""" # The ``_dock()`` method only works after the dock exists. # The method below creates it. self._doBasicTest("rst") self._dock()._onJavaScriptEnabledCheckbox(False) # Click. Nothing will happen, but make sure there's no assertion # or internal error. QTest.mouseClick(self._widget().webView, Qt.LeftButton)
def test_get(): """Use the test db and verify the real password for one password.""" # Given: form = MainController.create(APP, *_get_test_db()) # When we get the password (it's ok to leave the proto blank): form.ui.combobox_password_nicknames.setCurrentText(NICK2) QTest.mouseClick(form.ui.button_get, Qt.LeftButton) # Then it matches what we created: assert len(form.ui.label_resp_body.text()) == FINISH2 + 1 - START2
def test_cellchekcsd(self): """ Test if the unit cell of the current structure gets into the cellcheckcsd tab. """ item = self.myapp.ui.cifList_treeWidget.topLevelItem(2) self.myapp.ui.cifList_treeWidget.setCurrentItem(item) QTest.mouseClick(self.myapp.ui.CCDCSearchTab, Qt.LeftButton) if platform.system() == 'Windows': self.assertEqual('7.8783 10.4689 16.068 90.0 95.147 90.0', self.myapp.ui.cellSearchCSDLineEdit.text())
def testCheckInputWidget(self): w = self.newWidget() self.assertEqual(self.input_count, 0) self.assertTrue(w.isVisible()) QTest.mouseClick(w.check_button, Qt.LeftButton) self.assertEqual(self.input_count, 1) self.assertIn("Syntax OK", str(w.output.toPlainText())) QTest.mouseClick(w.hide_button, Qt.LeftButton) self.assertFalse(w.isVisible())
def changeParamValueToggle(self, w, path, value_name, old_path=None): param_widget = self.getParamWidget(w, path, value_name, old_path) self.assertNotEqual(param_widget, None) pos = param_widget.valueTestPosition() widget = param_widget.valueTestWidget() QTest.mouseMove(widget, pos) Testing.process_events(self.qapp, t=PROCESS_EVENT_TIME) QTest.mouseClick(widget, Qt.LeftButton, pos=pos) Testing.process_events(self.qapp, t=PROCESS_EVENT_TIME)
def test_download_details(self): self.go_to_and_wait_for_downloads() QTest.mouseClick(window.downloads_list.topLevelItem(0).progress_slider, Qt.LeftButton) QTest.qWait(500) # Wait until the details pane shows window.download_details_widget.setCurrentIndex(0) self.screenshot(window, name="download_detail") window.download_details_widget.setCurrentIndex(1) self.screenshot(window, name="download_files") window.download_details_widget.setCurrentIndex(2) self.screenshot(window, name="download_trackers")
def testChooseWorking(self, mock_open): main_win, w = self.createWidget() mock_open.return_value = "/no_exist" QTest.mouseClick(w.choose_working_button, Qt.LeftButton) self.assertEqual(w.working_line.text(), os.getcwd()) mock_open.return_value = "/" QTest.mouseClick(w.choose_working_button, Qt.LeftButton) self.assertEqual(self.working, "/") self.assertEqual(w.working_line.text(), "/")
def test_clickCaricaRete(self): self.form.ui.but_caricaRete.clicked.connect(self.click) self.form.ui.but_caricaRete.clicked.disconnect(self.form.openCaricaNN) QTest.mouseClick(self.form.ui.but_caricaRete, Qt.LeftButton) assert self.var == True self.var = False
def test_zOutButton(self): ''' Check clicking the z out button moves the agent ''' init_loc = self.m.env._location QTest.mouseClick(self.m.z_action.out_button, Qt.LeftButton) self.assertTrue(self.m.z_action.out_button.isChecked()) self.assertNotEqual(init_loc, self.m.env._location)
def test_scan_PB1_buttons(par_obj,win_obj): QTest.mouseClick(win_obj.prev_pane, QtCore.Qt.LeftButton) QTest.mouseClick(win_obj.next_pane, QtCore.Qt.LeftButton) QTest.mouseClick(win_obj.crop_data_btn, QtCore.Qt.LeftButton) QTest.mouseClick(win_obj.reprocess_btn, QtCore.Qt.LeftButton) QTest.mouseClick(win_obj.bleach_corr1_btn, QtCore.Qt.LeftButton) QTest.mouseClick(win_obj.bleach_corr_on_off, QtCore.Qt.LeftButton) QTest.mouseClick(win_obj.bleach_corr2_btn, QtCore.Qt.LeftButton) QTest.mouseClick(win_obj.CH0Auto_btn , QtCore.Qt.LeftButton) QTest.mouseClick(win_obj.CH1Auto_btn, QtCore.Qt.LeftButton) QTest.mouseClick(win_obj.CH01Cross_btn, QtCore.Qt.LeftButton) QTest.mouseClick(win_obj.addRegion_btn, QtCore.Qt.LeftButton) QTest.mouseClick(win_obj.clear_region_btn, QtCore.Qt.LeftButton) QTest.mouseClick(win_obj.save_corr_carpet_btn, QtCore.Qt.LeftButton) #QTest.mouseClick(win_obj.save_log_corr_carpet_btn, QtCore.Qt.LeftButton) QTest.mouseClick(win_obj.export_all_data_btn, QtCore.Qt.LeftButton) QTest.mouseClick(win_obj.export_region_btn, QtCore.Qt.LeftButton) QTest.mouseClick(win_obj.export_all_data_to_csv_btn, QtCore.Qt.LeftButton) win_obj.test_path = [os.getcwd()+'/test_files/out_img_D_0p2_noi_0_drift_False_ts_30000_mol_120_bleach_False_prob_0_with_PBC.tif'] win_obj.test_path[0] = win_obj.test_path[0].replace('\\','/') QTest.mouseClick(win_obj.openFile, QtCore.Qt.LeftButton) win_obj.file_import.file_dialog.done(1,win_obj.test_path) #Open the dialog for the line sampling (Hz): assert win_obj.diag.line_sampling_win.isVisible() == True, "Dialog for line sampling did not open." assert win_obj.diag.input_text.isVisible() == True, "Text input for line sampling did not open." assert str(win_obj.diag.label.text()) == 'Enter the line sampling (Hz):' QTest.keyClicks(win_obj.diag.input_text, str(1800)) assert win_obj.diag.input_text.text() == str(1800) QTest.mouseClick(win_obj.diag.ok, QtCore.Qt.LeftButton) assert win_obj.diag.line_sampling_win.isVisible() == False #Open the dialog for inputing the dwell time. assert win_obj.diag.dialog_dwell_win.isVisible() == True assert win_obj.diag.input_text.isVisible() == True assert str(win_obj.diag.label.text()) == 'Enter the pixel dwell time (us):' QTest.keyClicks(win_obj.diag.input_text, str(2.15)) assert win_obj.diag.input_text.text() == str(2.15) QTest.mouseClick(win_obj.diag.ok, QtCore.Qt.LeftButton) assert win_obj.diag.dialog_dwell_win.isVisible() == False #assert win_obj.diag.use_settings_win.isVisible() == False #QTest.mouseClick(win_obj.diag.no, QtCore.Qt.LeftButton) #assert win_obj.diag.use_settings_win.isVisible() == False #Check that the line sampling dialog doesn't appear again. assert win_obj.diag.line_sampling_win.isVisible() == False #Check that the previous and next pane visualisation works well. QTest.mouseClick(win_obj.prev_pane, QtCore.Qt.LeftButton) for objId in par_obj.objectRef: if(objId.cb.isChecked() == True): assert objId.pane == 0 break; QTest.mouseClick(win_obj.bleach_corr1_btn, QtCore.Qt.LeftButton) assert win_obj.bleach_corr1_plugin.bleach_corr1_win.isVisible() == True assert win_obj.bleach_corr_on_off.text() == ' OFF ' QTest.mouseClick(win_obj.bleach_corr1_plugin.apply_corr_btn, QtCore.Qt.LeftButton) QTest.mouseClick(win_obj.bleach_corr1_plugin.export_trace_btn, QtCore.Qt.LeftButton) assert win_obj.bleach_corr_on_off.text() == 'M1 ON ' print ('self.', np.sum(win_obj.bleach_corr1_plugin.objId.CH0_pc)) win_obj.bleach_corr1_plugin.close() assert win_obj.bleach_corr1_plugin.bleach_corr1_win.isVisible() == False win_obj.test_path = [os.getcwd()+'/test_files/out_img_D_0p2_noi_0_drift_False_ts_30000_mol_120_bleach_False_prob_0_numCH2_with_PBC.tif'] win_obj.test_path[0] = win_obj.test_path[0].replace('\\','/') QTest.mouseClick(win_obj.openFile, QtCore.Qt.LeftButton) win_obj.file_import.file_dialog.done(1,win_obj.test_path) #Open the dialog for the line sampling (Hz): assert win_obj.diag.line_sampling_win.isVisible() == True assert win_obj.diag.input_text.isVisible() == True assert str(win_obj.diag.label.text()) == 'Enter the line sampling (Hz):' QTest.keyClicks(win_obj.diag.input_text, str(1800)) assert win_obj.diag.input_text.text() == str(1800) QTest.mouseClick(win_obj.diag.ok, QtCore.Qt.LeftButton) assert win_obj.diag.line_sampling_win.isVisible() == False #Open the dialog for inputing the dwell time. assert win_obj.diag.dialog_dwell_win.isVisible() == True assert win_obj.diag.input_text.isVisible() == True assert str(win_obj.diag.label.text()) == 'Enter the pixel dwell time (us):' QTest.keyClicks(win_obj.diag.input_text, str(2.15)) assert win_obj.diag.input_text.text() == str(2.15) QTest.mouseClick(win_obj.diag.ok, QtCore.Qt.LeftButton) assert win_obj.diag.dialog_dwell_win.isVisible() == False #assert win_obj.diag.use_settings_win.isVisible() == False #QTest.mouseClick(win_obj.diag.no, QtCore.Qt.LeftButton) #assert win_obj.diag.use_settings_win.isVisible() == False #Check that the line sampling dialog doesn't appear again. assert win_obj.diag.line_sampling_win.isVisible() == False #Check that the previous and next pane visualisation works well. QTest.mouseClick(win_obj.prev_pane, QtCore.Qt.LeftButton) for objId in par_obj.objectRef: if(objId.cb.isChecked() == True): assert objId.pane == 0 break; QTest.mouseClick(win_obj.bleach_corr1_btn, QtCore.Qt.LeftButton) assert win_obj.bleach_corr1_plugin.bleach_corr1_win.isVisible() == True assert win_obj.bleach_corr_on_off.text() == ' OFF ' assert np.sum(win_obj.bleach_corr1_plugin.objId.CH0_pc) == 0 assert np.sum(win_obj.bleach_corr1_plugin.objId.CH1_pc) == 0 QTest.mouseClick(win_obj.bleach_corr1_plugin.apply_corr_btn, QtCore.Qt.LeftButton) QTest.mouseClick(win_obj.bleach_corr1_plugin.export_trace_btn, QtCore.Qt.LeftButton) assert win_obj.bleach_corr_on_off.text() == 'M1 ON ' #Check the carpet is modified by the photobleaching. assert np.sum(win_obj.bleach_corr1_plugin.objId.CH0_pc) != 0 assert np.sum(win_obj.bleach_corr1_plugin.objId.CH1_pc) != 0 assert np.sum(win_obj.bleach_corr1_plugin.objId.CH0_pc) != np.sum(win_obj.bleach_corr1_plugin.objId.CH0) assert np.sum(win_obj.bleach_corr1_plugin.objId.CH1_pc) != np.sum(win_obj.bleach_corr1_plugin.objId.CH1) assert np.sum(win_obj.bleach_corr1_plugin.objId.CH1_pc) != np.sum(win_obj.bleach_corr1_plugin.objId.CH0_pc) win_obj.bleach_corr1_plugin.close() assert win_obj.bleach_corr1_plugin.bleach_corr1_win.isVisible() == False assert par_obj.numOfLoaded == 2 for i in range(1,-1,-1): QTest.mouseClick(win_obj.xb[i], QtCore.Qt.LeftButton) assert par_obj.numOfLoaded == 0
def test_0spend_multiple_freeturn(self): app = QApplication(sys.argv) self.scenario['spins'] = [ "pickAccumulateFreeTurnToken", "pickBecomeBankrupt", "pickBecomeBankrupt", "pickRandomCategory1", "pickDoublePlayerRoundScore", "pickBecomeBankrupt", "pickBecomeBankrupt", "pickAccumulateFreeTurnToken", "pickBecomeBankrupt", "pickBecomeBankrupt", "pickLoseTurn", "pickBecomeBankrupt", "pickBecomeBankrupt", ] self.scenario['players'][0] = "spend_multiple_freeturn" self.scenario['options']['skipSpinAction'] = True self.args = build_args(logging.DEBUG, 10000, json.dumps(self.scenario), hints=h) h.append(self.args['hmi']['hmi_port']) h.append(self.args['game']['game_port']) self.logger.debug("hints=%s" % self.hints) self.game = None self.game = game.Game(**self.args['game']) self.game.start() self.hmi = None self.hmi = hmi.HMI(**self.args['hmi']) self.hmi.show() QTest.qWait(2000) spinWidget = self.hmi.buttonSpin self.assertEqual(self.hmi.main_scorebar.player0.getFreeTurnTokens(), str(0)) self.logger.debug("==============starting spin 1================") QTest.mouseClick(spinWidget, Qt.LeftButton) QTest.qWait(5000) self.logger.debug("==============starting spin 2================") QTest.mouseClick(spinWidget, Qt.LeftButton) QTest.qWait(3000) self.logger.debug("==============starting spin 3================") QTest.mouseClick(spinWidget, Qt.LeftButton) QTest.qWait(3000) self.assertEqual(self.hmi.main_scorebar.player0.getFreeTurnTokens(), str(1)) self.assertEqual(self.hmi.main_scorebar.player0.getScore(), str(0)) self.logger.debug("==============starting spin 4================") QTest.mouseClick(spinWidget, Qt.LeftButton) QTest.qWait(4000) self.logger.debug("right before thought about issue") while not hasattr(self.hmi, "scene_question"): QTest.qWait(50) self.logger.debug("==============starting spin 5================") QTest.mouseClick(self.hmi.scene_question.buttonReveal, Qt.LeftButton) QTest.qWait(1000) QTest.mouseClick(self.hmi.scene_question.buttonIncorrect, Qt.LeftButton) QTest.qWait(1000) QTest.mouseClick(self.hmi.scene_question.buttonFreeTurnSpend, Qt.LeftButton) QTest.qWait(3000) self.assertEqual(self.hmi.main_scorebar.player0.getScore(), "-100") self.assertEqual(self.hmi.main_scorebar.player0.getFreeTurnTokens(), str(0)) QTest.mouseClick(spinWidget, Qt.LeftButton) QTest.qWait(1000) self.assertEqual(self.hmi.main_scorebar.player0.getScore(), "-200") QTest.mouseClick(spinWidget, Qt.LeftButton) QTest.qWait(1000) QTest.mouseClick(spinWidget, Qt.LeftButton) QTest.qWait(1000) QTest.mouseClick(spinWidget, Qt.LeftButton) QTest.qWait(1000) self.assertEqual(self.hmi.main_scorebar.player0.getFreeTurnTokens(), str(1)) QTest.mouseClick(spinWidget, Qt.LeftButton) QTest.qWait(1000) QTest.mouseClick(spinWidget, Qt.LeftButton) QTest.qWait(1000) QTest.mouseClick(spinWidget, Qt.LeftButton) QTest.qWait(1000) while not hasattr(self.hmi, "scene_question"): QTest.qWait(50) QTest.mouseClick(self.hmi.scene_question.buttonFreeTurnSpend, Qt.LeftButton) QTest.qWait(1000) self.assertEqual(self.hmi.main_scorebar.player0.getFreeTurnTokens(), str(0)) QTest.mouseClick(spinWidget, Qt.LeftButton) QTest.qWait(1000) QTest.mouseClick(spinWidget, Qt.LeftButton) QTest.qWait(1000) self.assertEqual(self.hmi.main_scorebar.player0.getFreeTurnTokens(), str(0)) self.game.quit() self.hmi.close() QTest.qWait(1000) app.exit()
def __click_ok(self, customizer): QTest.mouseClick(customizer.gui.ui.settingsOkButton, Qt.LeftButton)
def test_log_to_fd_win(self): """Test transition from log display window to food dictionary display window.""" log_win = interface.LogWin() with patch.object(interface, 'FoodDictWin') as fd_win_mock: QTest.mouseClick(log_win.goto_fd_btn, Qt.LeftButton) fd_win_mock.assert_called()
def test_help_win(self): """QDialog should be called when the user clicks the help button.""" log_win = interface.LogWin() with patch.object(interface, 'QDialog') as dialog_mock: QTest.mouseClick(log_win.help_btn, Qt.LeftButton) dialog_mock.assert_called()
def test_lif_file_import(par_obj, win_obj): def test_line_sampling_dialog(sample_rate): #Open the dialog for the line sampling (Hz): assert win_obj.diag.line_sampling_win.isVisible() == True assert win_obj.diag.input_text.isVisible() == True assert str( win_obj.diag.label.text()) == 'Enter the line sampling (Hz):' QTest.keyClicks(win_obj.diag.input_text, str(sample_rate)) assert win_obj.diag.input_text.text() == str(sample_rate) QTest.mouseClick(win_obj.diag.ok, QtCore.Qt.LeftButton) assert win_obj.diag.line_sampling_win.isVisible() == False def test_dwell_dialog(dwell_time): #Open the dialog for inputing the dwell time. assert win_obj.diag.dialog_dwell_win.isVisible() == True assert win_obj.diag.input_text.isVisible() == True assert str( win_obj.diag.label.text()) == 'Enter the pixel dwell time (us):' QTest.keyClicks(win_obj.diag.input_text, str(dwell_time)) assert win_obj.diag.input_text.text() == str(dwell_time) QTest.mouseClick(win_obj.diag.ok, QtCore.Qt.LeftButton) #assert win_obj.diag.dialog_dwell_win.isVisible() == False ##Test MSR file import. win_obj.test_path = [] win_obj.test_path.append(os.getcwd() + '/test_files/Jurkat-SNAP-actin_scanningFCS.lif') win_obj.test_path.append( os.getcwd() + '/test_files/20150409_JCamSTED HG LCK-Cit_LCK-SiR.lif') for i in range(0, win_obj.test_path.__len__()): win_obj.test_path[i] = win_obj.test_path[i].replace('\\', '/') QTest.mouseClick(win_obj.openFile, QtCore.Qt.LeftButton) win_obj.file_import.file_dialog.done(1, win_obj.test_path) for i in range(0, 14): print(i) assert win_obj.diag.lif_import_win.item_list[i].checkState() == False win_obj.diag.lif_import_win.item_list[0].setCheckState(QtCore.Qt.Checked) win_obj.diag.lif_import_win.item_list[4].setCheckState(QtCore.Qt.Checked) win_obj.diag.lif_import_win.item_list[6].setCheckState(QtCore.Qt.Checked) win_obj.diag.lif_import_win.item_list[9].setCheckState(QtCore.Qt.Checked) #These files are empty as so will make the system fail. QTest.mouseClick(win_obj.diag.load_data_btn, QtCore.Qt.LeftButton) win_obj.diag.lif_import_win.item_list[0].setCheckState(QtCore.Qt.Checked) win_obj.diag.lif_import_win.item_list[4].setCheckState(QtCore.Qt.Checked) win_obj.diag.lif_import_win.item_list[6].setCheckState(QtCore.Qt.Checked) win_obj.diag.lif_import_win.item_list[9].setCheckState(QtCore.Qt.Checked) QTest.mouseClick(win_obj.diag.load_data_btn, QtCore.Qt.LeftButton) print('shape', par_obj.objectRef[0].CH0.shape) assert par_obj.objectRef[0].CH0.shape == (24576, 64) assert par_obj.objectRef[1].CH0.shape == (24576, 64) assert par_obj.objectRef[2].CH0.shape == (24576, 64) assert par_obj.objectRef[3].CH0.shape == (106496, 64) assert par_obj.objectRef[0].CH0_pc.shape == (24576, 64) assert par_obj.objectRef[1].CH0_pc.shape == (24576, 64) assert par_obj.objectRef[2].CH0_pc.shape == (24576, 64) assert par_obj.objectRef[3].CH0_pc.shape == (106496, 64) assert par_obj.objectRef[ 0].name == '1_Jurkat-SNAP-Actin_TMR_e552_0STED_24576f_1800Hz_z4864px' assert par_obj.objectRef[ 1].name == '3_Jurkat-SNAP-Actin_TMR_e552_0STED_24576f_1800Hz_z4864px_12bit' assert par_obj.objectRef[ 2].name == '4_Jurkat-SNAP-Actin_TMR_e552_0STED_24576f_1800Hz_z4864px_12bit' assert par_obj.objectRef[ 3].name == '5_Jurkat-SNAP-Actin_TMR_e552_00STED_106496f_8000Hz_z48_64px_12bit' assert np.round(np.average(par_obj.objectRef[3].CH0), 3) == 1140.479 assert np.round(np.min(par_obj.objectRef[3].CH0), 3) == 0.000 assert np.round(np.max(par_obj.objectRef[3].CH0), 3) == 4095.000 assert np.round(np.median(par_obj.objectRef[3].CH0), 3) == 1097 print(np.round(np.average(par_obj.objectRef[3].CH0[:, 0]), 3) == 1133.802) print(np.round(np.min(par_obj.objectRef[3].CH0[:, 0]), 3) == 0.000) print(np.round(np.max(par_obj.objectRef[3].CH0[:, 0]), 3) == 3568) print(np.round(np.median(par_obj.objectRef[3].CH0[:, 0]), 3) == 1086) #Tests how many files appear in main interface and then closes them. assert par_obj.numOfLoaded == 4 for i in range(3, -1, -1): QTest.mouseClick(win_obj.xb[i], QtCore.Qt.LeftButton) assert par_obj.numOfLoaded == 0 print('tests finished. LIF Import looks fine') return True
def test_multipledirectcategories(self): app = QApplication(sys.argv) self.scenario['spins'] = [ "pickRandomCategory1", "pickRandomCategory2", "pickRandomCategory3", ] self.scenario['players'][0] = "multipledirectcategories" self.scenario['options']['skipSpinAction'] = False self.args = build_args(logging.DEBUG, 10000, json.dumps(self.scenario), hints=h) h.append(self.args['hmi']['hmi_port']) h.append(self.args['game']['game_port']) self.logger.debug("hints=%s" % self.hints) self.game = None self.game = game.Game(**self.args['game']) self.game.start() self.hmi = None self.hmi = hmi.HMI(**self.args['hmi']) self.hmi.show() QTest.qWait(2000) spinWidget = self.hmi.buttonSpin QTest.mouseClick(spinWidget, Qt.LeftButton) QTest.qWait(10000) QTest.mouseClick(self.hmi.scene_question.buttonReveal, Qt.LeftButton) QTest.qWait(1000) QTest.mouseClick(self.hmi.scene_question.buttonCorrect, Qt.LeftButton) QTest.qWait(1000) self.assertEqual(self.hmi.main_scorebar.player0.getScore(), str(100)) QTest.mouseClick(spinWidget, Qt.LeftButton) QTest.qWait(10000) QTest.mouseClick(self.hmi.scene_question.buttonReveal, Qt.LeftButton) QTest.qWait(1000) QTest.mouseClick(self.hmi.scene_question.buttonCorrect, Qt.LeftButton) QTest.qWait(1000) self.assertEqual(self.hmi.main_scorebar.player1.getScore(), str(100)) self.game.quit() self.hmi.close() QTest.qWait(1000) app.exit()
def test_trust_page(tribler_api, window): QTest.mouseClick(window.token_balance_widget, Qt.LeftButton) wait_for_variable(window, "trust_page.history") screenshot(window, name="trust_page_values")
def test_home_page_torrents(self): QTest.mouseClick(window.left_menu_button_home, Qt.LeftButton) QTest.mouseClick(window.home_tab_torrents_button, Qt.LeftButton) self.screenshot(window, name="home_page_torrents_loading") self.wait_for_home_page_table_populated() self.screenshot(window, name="home_page_torrents")
def test_debug_pane(tribler_api, window): wait_for_variable(window, "tribler_settings") QTest.mouseClick(window.settings_button, Qt.LeftButton) QTest.mouseClick(window.settings_general_button, Qt.LeftButton) wait_for_settings(window) if not window.developer_mode_enabled_checkbox.isChecked(): QTest.mouseClick(window.developer_mode_enabled_checkbox, Qt.LeftButton) QTest.mouseClick(window.left_menu_button_debug, Qt.LeftButton) screenshot(window.debug_window, name="debug_panel_just_opened") wait_for_list_populated(window.debug_window.general_tree_widget) screenshot(window.debug_window, name="debug_panel_general_tab") window.debug_window.debug_tab_widget.setCurrentIndex(1) wait_for_list_populated(window.debug_window.requests_tree_widget) screenshot(window.debug_window, name="debug_panel_requests_tab") window.debug_window.debug_tab_widget.setCurrentIndex(2) wait_for_list_populated(window.debug_window.bandwidth_tree_widget) screenshot(window.debug_window, name="debug_panel_bandwidth_tab") window.debug_window.debug_tab_widget.setCurrentIndex(3) wait_for_list_populated(window.debug_window.ipv8_general_tree_widget) screenshot(window.debug_window, name="debug_panel_ipv8_tab") window.debug_window.ipv8_tab_widget.setCurrentIndex(1) wait_for_list_populated(window.debug_window.communities_tree_widget) screenshot(window.debug_window, name="debug_panel_communities_tab") # FIXME: add dummy tunnels to the core to test this # window.debug_window.debug_tab_widget.setCurrentIndex(4) # wait_for_list_populated(window.debug_window.circuits_tree_widget) # screenshot(window.debug_window, name="debug_panel_tunnel_circuits_tab") # window.debug_window.tunnel_tab_widget.setCurrentIndex(1) # wait_for_list_populated(window.debug_window.relays_tree_widget) # screenshot(window.debug_window, name="debug_panel_tunnel_relays_tab") # window.debug_window.tunnel_tab_widget.setCurrentIndex(2) # wait_for_list_populated(window.debug_window.exits_tree_widget) # screenshot(window.debug_window, name="debug_panel_tunnel_exits_tab") window.debug_window.debug_tab_widget.setCurrentIndex(5) wait_for_list_populated(window.debug_window.dhtstats_tree_widget) screenshot(window.debug_window, name="debug_panel_dht_stats_tab") window.debug_window.dht_tab_widget.setCurrentIndex(1) wait_for_list_populated(window.debug_window.buckets_tree_widget) screenshot(window.debug_window, name="debug_panel_dht_buckets_tab") window.debug_window.debug_tab_widget.setCurrentIndex(6) wait_for_list_populated(window.debug_window.events_tree_widget) screenshot(window.debug_window, name="debug_panel_events_tab") window.debug_window.debug_tab_widget.setCurrentIndex(7) wait_for_list_populated(window.debug_window.open_files_tree_widget) screenshot(window.debug_window, name="debug_panel_open_files_tab") window.debug_window.system_tab_widget.setCurrentIndex(1) wait_for_list_populated(window.debug_window.open_sockets_tree_widget) screenshot(window.debug_window, name="debug_panel_open_sockets_tab") window.debug_window.system_tab_widget.setCurrentIndex(2) wait_for_list_populated(window.debug_window.threads_tree_widget) screenshot(window.debug_window, name="debug_panel_threads_tab") # FIXME: enable logs injection to test log showing through debug window # Logs shown in ui and from the debug endpoint should be same window.debug_window.debug_tab_widget.setCurrentIndex(9) # logs from FakeTriblerApi # fake_logs = ''.join(f"Sample log [{i}]\n" for i in range(10)).strip() window.debug_window.log_tab_widget.setCurrentIndex(0) # Core tab wait_for_qtext_edit_populated(window.debug_window.core_log_display_area) # core_logs = window.debug_window.core_log_display_area.toPlainText().strip() # assert core_logs == fake_logs, "Core logs found different than expected." # screenshot(window.debug_window, name="debug_panel_logs_core") # window.debug_window.log_tab_widget.setCurrentIndex(1) # GUI tab # wait_for_qtext_edit_populated(window.debug_window.gui_log_display_area) # gui_logs = window.debug_window.gui_log_display_area.toPlainText().strip() # assert gui_logs == fake_logs, "GUI logs found different than expected." # screenshot(window.debug_window, name="debug_panel_logs_gui") window.debug_window.system_tab_widget.setCurrentIndex(3) QTest.qWait(1000) screenshot(window.debug_window, name="debug_panel_cpu_tab") window.debug_window.system_tab_widget.setCurrentIndex(4) QTest.qWait(1000) screenshot(window.debug_window, name="debug_panel_memory_tab") # Libtorrent tab window.debug_window.debug_tab_widget.setCurrentIndex(8) wait_for_list_populated( window.debug_window.libtorrent_settings_tree_widget) screenshot(window.debug_window, name="debug_panel_libtorrent_settings_tab") window.debug_window.libtorrent_tab_widget.setCurrentIndex(2) wait_for_list_populated( window.debug_window.libtorrent_settings_tree_widget) screenshot(window.debug_window, name="debug_panel_libtorrent_session_tab") window.debug_window.close()
def test_settings(tribler_api, window): QTest.mouseClick(window.settings_button, Qt.LeftButton) QTest.mouseClick(window.settings_general_button, Qt.LeftButton) screenshot(window, name="settings_not_loaded") wait_for_settings(window) screenshot(window, name="settings_general") QTest.mouseClick(window.settings_connection_button, Qt.LeftButton) screenshot(window, name="settings_connection") QTest.mouseClick(window.settings_bandwidth_button, Qt.LeftButton) screenshot(window, name="settings_bandwidth") QTest.mouseClick(window.settings_seeding_button, Qt.LeftButton) screenshot(window, name="settings_seeding") QTest.mouseClick(window.settings_anonymity_button, Qt.LeftButton) screenshot(window, name="settings_anonymity")
def test_discovered_page(tribler_api, window): QTest.mouseClick(window.left_menu_button_discovered, Qt.LeftButton) tst_channels_widget(window, window.discovered_page, "discovered_page", sort_column=2)
def testCalibrationCtrlWidget(self): widget = self.image_tool._calibration_view._ctrl_widget proc = self.pulse_worker._image_proc proc.update() self.assertFalse(proc._correct_gain) self.assertFalse(proc._correct_offset) self.assertEqual(slice(None), proc._gain_cells) self.assertEqual(slice(None), proc._offset_cells) self.assertTrue(proc._gain_cells_updated) self.assertTrue(proc._offset_cells_updated) self.assertTrue(proc._dark_as_offset) self.assertFalse(proc._recording_dark) widget._correct_gain_cb.setChecked(True) widget._correct_offset_cb.setChecked(True) widget._gain_cells_le.setText(":70") widget._offset_cells_le.setText("2:120:4") widget._dark_as_offset_cb.setChecked(False) QTest.mouseClick(widget.record_dark_btn, Qt.LeftButton) proc.update() self.assertTrue(proc._correct_gain) self.assertTrue(proc._correct_offset) self.assertEqual(slice(None, 70), proc._gain_cells) self.assertEqual(slice(2, 120, 4), proc._offset_cells) self.assertTrue(proc._gain_cells_updated) self.assertTrue(proc._offset_cells_updated) self.assertFalse(proc._dark_as_offset) self.assertTrue(proc._recording_dark) # test stop dark recording QTest.mouseClick(widget.record_dark_btn, Qt.LeftButton) proc.update() self.assertFalse(proc._recording_dark) # test remove dark data = np.ones((10, 10), dtype=np.float32) proc._dark = data proc._dark_mean = data QTest.mouseClick(widget._remove_dark_btn, Qt.LeftButton) proc.update() self.assertIsNone(proc._dark) self.assertIsNone(proc._dark_mean) # -------------------------------- # test load and remove gain/offset # -------------------------------- # Here we test that "proc._cal_sub.update()" works properly. The rest # is done in the unittests of ImageProcessor. gain_gt = np.random.randn(2, 2) offset_gt = np.random.randn(2, 2) def _read_constants_side_effect(fn): if fn == "gain/file/path": return gain_gt if fn == "offset/file/path": return offset_gt # caveat: first establish the connection proc._cal_sub.update() with patch('extra_foam.ipc.read_cal_constants', side_effect=_read_constants_side_effect): with patch( 'extra_foam.gui.image_tool.calibration_view.QFileDialog.getOpenFileName', return_value=["gain/file/path"]): QTest.mouseClick(widget.load_gain_btn, Qt.LeftButton) time.sleep(0.1) # wait to write into redis self.assertEqual("gain/file/path", widget.gain_fp_le.text()) n_attempts = 0 # repeat to prevent random failure at Travis while n_attempts < 10: n_attempts += 1 gain_updated, gain, offset_updated, offset = proc._cal_sub.update( ) if gain_updated: break time.sleep(0.001) np.testing.assert_array_equal(gain, gain_gt) self.assertFalse(offset_updated) self.assertIsNone(offset) QTest.mouseClick(widget.remove_gain_btn, Qt.LeftButton) self.assertEqual("", widget.gain_fp_le.text()) gain_updated, gain, offset_updated, offset = proc._cal_sub.update( ) self.assertTrue(gain_updated) self.assertIsNone(gain) with patch( 'extra_foam.gui.image_tool.calibration_view.QFileDialog.getOpenFileName', return_value=["offset/file/path"]): QTest.mouseClick(widget.load_offset_btn, Qt.LeftButton) time.sleep(0.1) # wait to write data into redis self.assertEqual("offset/file/path", widget.offset_fp_le.text()) gain_updated, gain, offset_updated, offset = proc._cal_sub.update( ) self.assertFalse(gain_updated) self.assertIsNone(gain) self.assertTrue(offset_updated) np.testing.assert_array_equal(offset, offset_gt) QTest.mouseClick(widget.remove_offset_btn, Qt.LeftButton) self.assertEqual("", widget.offset_fp_le.text()) gain_updated, gain, offset_updated, offset = proc._cal_sub.update( ) self.assertTrue(offset_updated) self.assertIsNone(offset) # test loading meta data mediator = widget._mediator mediator.onCalDarkAsOffset(True) mediator.onCalGainCorrection(False) mediator.onCalOffsetCorrection(False) mediator.onCalGainMemoCellsChange([0, None, 2]) mediator.onCalOffsetMemoCellsChange([0, None, 4]) widget.loadMetaData() self.assertEqual(True, widget._dark_as_offset_cb.isChecked()) self.assertEqual(False, widget._correct_gain_cb.isChecked()) self.assertEqual(False, widget._correct_offset_cb.isChecked()) self.assertEqual("0::2", widget._gain_cells_le.text()) self.assertEqual("0::4", widget._offset_cells_le.text())
def test_sequence(self): # set Options ttt.Options.o_is_computer = False ttt.Options.x_is_computer = False ttt.Options.load_previous_game = 'No' # instantiate GUI self.gui = ttt.TicTacToeGui() # copy the state for reference self.state = copy.deepcopy(self.gui.state) # establish defaults self._default() new_board = self.state.board.copy() # place piece 1 self._place_piece(0, 0) new_board[0, 0] = o np.testing.assert_array_equal(self.gui.state.board, new_board) self.assertEqual(self.gui.state.cur_move, 1) self.assertEqual(self.gui.state.cur_game, 0) # place piece 2 self._place_piece(1, 0) new_board[1, 0] = x np.testing.assert_array_equal(self.gui.state.board, new_board) self.assertEqual(self.gui.state.cur_move, 2) # undo second move QTest.mouseClick(self.gui.btn_undo, QtCore.Qt.LeftButton, delay=1) new_board[1, 0] = n np.testing.assert_array_equal(self.gui.state.board, new_board) self.assertEqual(self.gui.state.cur_move, 1) # undo first move QTest.mouseClick(self.gui.btn_undo, QtCore.Qt.LeftButton, delay=1) new_board[0, 0] = n np.testing.assert_array_equal(self.gui.state.board, new_board) self.assertEqual(self.gui.state.cur_move, 0) # redo first move QTest.mouseClick(self.gui.btn_redo, QtCore.Qt.LeftButton, delay=1) new_board[0, 0] = o np.testing.assert_array_equal(self.gui.state.board, new_board) self.assertEqual(self.gui.state.cur_move, 1) # redo second move QTest.mouseClick(self.gui.btn_redo, QtCore.Qt.LeftButton, delay=1) new_board[1, 0] = x np.testing.assert_array_equal(self.gui.state.board, new_board) self.assertEqual(self.gui.state.cur_move, 2) # complete game self._place_piece(0, 1) new_board[0, 1] = o self._place_piece(1, 1) new_board[1, 1] = x self._place_piece(0, 2) new_board[0, 2] = o np.testing.assert_array_equal(self.gui.state.board, new_board) self.assertEqual(self.gui.state.cur_move, 5) # make extra click self._place_piece(2, 2) np.testing.assert_array_equal(self.gui.state.board, new_board) self.assertEqual(self.gui.state.cur_move, 5) # start new game QTest.mouseClick(self.gui.btn_new, QtCore.Qt.LeftButton, delay=1) new_board = self.state.board.copy() self.assertEqual(self.gui.state.cur_move, 0) self.assertEqual(self.gui.state.cur_game, 1) # place one piece self._place_piece(1, 2) new_board[1, 2] = x self.assertEqual(self.gui.state.cur_move, 1) # click on existing piece self._place_piece(1, 2) self.assertEqual(self.gui.state.cur_move, 1) # click off the board self._place_piece(-1, 2) self.assertEqual(self.gui.state.cur_move, 1)
def testReferenceCtrlWidget(self): view = self.image_tool._reference_view widget = view._ctrl_widget corrected = view._corrected proc = self.pulse_worker._image_proc data, _ = self.data_with_assembled(1001, (4, 10, 10)) # test setting reference (no image) QTest.mouseClick(widget.set_current_btn, Qt.LeftButton) updated, ref = proc._ref_sub.update() self.assertFalse(updated) self.assertIsNone(ref) # test setting reference corrected._image = 2 * np.ones((10, 10), np.float32) QTest.mouseClick(widget.set_current_btn, Qt.LeftButton) updated, ref = proc._ref_sub.update() self.assertTrue(updated) np.testing.assert_array_equal(corrected.image, ref) # test setting reference multiple times for i in range(5): corrected._image = np.random.rand(10, 10).astype(np.float32) QTest.mouseClick(widget.set_current_btn, Qt.LeftButton) updated, ref = proc._ref_sub.update() self.assertTrue(updated) np.testing.assert_array_equal(corrected.image, ref) # test removing reference QTest.mouseClick(widget.remove_btn, Qt.LeftButton) updated, ref = proc._ref_sub.update() self.assertTrue(updated) self.assertIsNone(ref) # ------------------------------ # test load and remove reference # ------------------------------ # Here we test that "proc._ref_sub.update()" works properly. The rest # is done in the unittests of ImageProcessor. ref_gt = np.ones([2, 2], dtype=np.float32) def _read_image_side_effect(fn): if fn == "reference/file/path": return ref_gt with patch('extra_foam.ipc.read_image', side_effect=_read_image_side_effect): with patch( 'extra_foam.gui.image_tool.reference_view.QFileDialog.getOpenFileName', return_value=["reference/file/path"]): QTest.mouseClick(widget.load_btn, Qt.LeftButton) self.assertEqual("reference/file/path", widget.filepath_le.text()) updated, ref = proc._ref_sub.update() self.assertTrue(updated) np.testing.assert_array_equal(ref, ref_gt) QTest.mouseClick(widget.remove_btn, Qt.LeftButton) self.assertEqual("", widget.filepath_le.text()) updated, ref = proc._ref_sub.update() self.assertTrue(updated) self.assertIsNone(ref)
def test_log_win_to_edit_log_win_with_no_selected_entries(self, join_mock): """Test transition from log display window to edit log window without selecting any entries to edit.""" log_win = interface.LogWin() with patch.object(interface, 'MessageWin') as message_win_mock: QTest.mouseClick(log_win.edit_entries_btn, Qt.LeftButton) message_win_mock.assert_called()
def testRoiCtrlWidget(self): roi_ctrls = self.image_tool._corrected_view._roi_ctrl_widget._roi_ctrls proc = self.pulse_worker._image_roi self.assertEqual(4, len(roi_ctrls)) # test default proc.update() for i, ctrl in enumerate(roi_ctrls, 1): # test real ROI position and size matches the numbers in the GUI self.assertListEqual( [int(ctrl._px_le.text()), int(ctrl._py_le.text())], list(ctrl._roi.pos())) self.assertListEqual( [int(ctrl._width_le.text()), int(ctrl._height_le.text())], list(ctrl._roi.size())) self.assertListEqual(RectRoiGeom.INVALID, getattr(proc, f"_geom{i}")) for ctrl in roi_ctrls: self.assertFalse(ctrl._activate_cb.isChecked()) self.assertFalse(ctrl._lock_cb.isChecked()) self.assertFalse(ctrl._width_le.isEnabled()) self.assertFalse(ctrl._height_le.isEnabled()) self.assertFalse(ctrl._px_le.isEnabled()) self.assertFalse(ctrl._py_le.isEnabled()) # test activating ROI for i, item in enumerate(zip(roi_ctrls, self.view._rois), 1): ctrl, roi = item self.assertIs(ctrl._roi, roi) QTest.mouseClick(ctrl._activate_cb, Qt.LeftButton, pos=QPoint(2, ctrl._activate_cb.height() / 2)) self.assertTrue(ctrl._activate_cb.isChecked()) proc.update() w_gt, h_gt = int(ctrl._width_le.text()), int( ctrl._height_le.text()) self.assertTupleEqual((w_gt, h_gt), tuple(roi.size())) x_gt, y_gt = int(ctrl._px_le.text()), int(ctrl._py_le.text()) self.assertTupleEqual((x_gt, y_gt), tuple(roi.pos())) self.assertListEqual([x_gt, y_gt, w_gt, h_gt], getattr(proc, f"_geom{i}")) # use keyClicks to test that the QLineEdit is enabled ctrl._width_le.clear() QTest.keyClicks(ctrl._width_le, "10") QTest.keyPress(ctrl._width_le, Qt.Key_Enter) ctrl._height_le.clear() QTest.keyClicks(ctrl._height_le, "30") QTest.keyPress(ctrl._height_le, Qt.Key_Enter) self.assertTupleEqual((10, 30), tuple(roi.size())) # ROI can be outside of the image ctrl._px_le.clear() QTest.keyClicks(ctrl._px_le, "-1") QTest.keyPress(ctrl._px_le, Qt.Key_Enter) ctrl._py_le.clear() QTest.keyClicks(ctrl._py_le, "-3") QTest.keyPress(ctrl._py_le, Qt.Key_Enter) self.assertTupleEqual((-1, -3), tuple(roi.pos())) proc.update() self.assertListEqual([-1, -3, 10, 30], getattr(proc, f"_geom{i}")) # lock ROI ctrl QTest.mouseClick(ctrl._lock_cb, Qt.LeftButton, pos=QPoint(2, ctrl._lock_cb.height() / 2)) self.assertTrue(ctrl._activate_cb.isChecked()) self.assertTrue(ctrl._lock_cb.isChecked()) self.assertFalse(ctrl._width_le.isEnabled()) self.assertFalse(ctrl._height_le.isEnabled()) self.assertFalse(ctrl._px_le.isEnabled()) self.assertFalse(ctrl._py_le.isEnabled()) # deactivate ROI ctrl QTest.mouseClick(ctrl._activate_cb, Qt.LeftButton, pos=QPoint(2, ctrl._activate_cb.height() / 2)) self.assertFalse(ctrl._activate_cb.isChecked()) self.assertTrue(ctrl._lock_cb.isChecked()) self.assertFalse(ctrl._width_le.isEnabled()) self.assertFalse(ctrl._height_le.isEnabled()) self.assertFalse(ctrl._px_le.isEnabled()) self.assertFalse(ctrl._py_le.isEnabled()) proc.update() self.assertListEqual(RectRoiGeom.INVALID, getattr(proc, f"_geom{i}"))
def test_delHITLButton_notClickable(self): ''' Check the HITL delete button is not clickable if HITL mode is not enabled. ''' QTest.mouseClick(self.m.HITL_delete, Qt.LeftButton) self.assertTrue(not self.m.HITL_delete.isChecked())
def test_doublescore(self): app = QApplication(sys.argv) self.scenario['spins'] = [ "pickBecomeBankrupt", "pickBecomeBankrupt", "pickBecomeBankrupt", "pickRandomCategory1", "pickBecomeBankrupt", "pickBecomeBankrupt", "pickDoublePlayerRoundScore", ] self.scenario['players'][0] = "doublescore" self.args = build_args(logging.DEBUG, 10000, json.dumps(self.scenario), hints=h) h.append(self.args['hmi']['hmi_port']) h.append(self.args['game']['game_port']) self.logger.debug("hints=%s" % self.hints) self.game = None self.game = game.Game(**self.args['game']) self.game.start() self.hmi = None self.hmi = hmi.HMI(**self.args['hmi']) self.hmi.show() QTest.qWait(3000) spinWidget = self.hmi.buttonSpin QTest.mouseClick(spinWidget, Qt.LeftButton) QTest.qWait(1000) QTest.mouseClick(spinWidget, Qt.LeftButton) QTest.qWait(1000) QTest.mouseClick(spinWidget, Qt.LeftButton) QTest.qWait(1000) QTest.mouseClick(spinWidget, Qt.LeftButton) QTest.qWait(1000) while not hasattr(self.hmi, "scene_question"): QTest.qWait(50) QTest.mouseClick(self.hmi.scene_question.buttonReveal, Qt.LeftButton) QTest.qWait(1000) QTest.mouseClick(self.hmi.scene_question.buttonCorrect, Qt.LeftButton) QTest.qWait(1000) QTest.mouseClick(spinWidget, Qt.LeftButton) QTest.qWait(1000) QTest.mouseClick(spinWidget, Qt.LeftButton) QTest.qWait(1000) QTest.mouseClick(spinWidget, Qt.LeftButton) QTest.qWait(1000) self.assertEqual(self.hmi.main_scorebar.player0.getScore(), str(200)) self.game.quit() self.hmi.close() QTest.qWait(1000) app.exit()
def test_zoomOutButton(self): ''' Check clicking the zoom in button registers ''' QTest.mouseClick(self.m.zoomOutButton, Qt.LeftButton) self.assertTrue(self.m.zoomOutButton.isChecked())
def testCommonStartStopReset(self): win = self._win com_ctrl_widget = win._com_ctrl_st ctrl_widget = win._ctrl_widget_st client = win._client_st worker = win._worker_st self.assertFalse(com_ctrl_widget.stop_btn.isEnabled()) self.assertIsNone(client._endpoint_st) with patch.object(client, "start") as client_start: with patch.object(win._plot_timer_st, "start") as timer_start: spy = QSignalSpy(win.started_sgn) QTest.mouseClick(com_ctrl_widget.start_btn, Qt.LeftButton) self.assertEqual( f"tcp://{com_ctrl_widget._hostname_le.text()}:" f"{com_ctrl_widget._port_le.text()}", client._endpoint_st) self.assertEqual(2, len(client._catalog_st)) self.assertIn("device1:output property1", client._catalog_st) self.assertIn("device2 property2", client._catalog_st) self.assertEqual(1, len(spy)) self.assertTrue(com_ctrl_widget.stop_btn.isEnabled()) self.assertFalse(com_ctrl_widget.start_btn.isEnabled()) self.assertFalse(com_ctrl_widget.load_dark_run_btn.isEnabled()) self.assertFalse(ctrl_widget.dummy_widget.isEnabled()) client_start.assert_called_once() timer_start.assert_called_once() with patch.object(client, "terminateRunST") as client_stop: with patch.object(win._plot_timer_st, "stop") as timer_stop: spy = QSignalSpy(win.stopped_sgn) QTest.mouseClick(com_ctrl_widget.stop_btn, Qt.LeftButton) self.assertEqual(1, len(spy)) self.assertFalse(com_ctrl_widget.stop_btn.isEnabled()) self.assertTrue(com_ctrl_widget.start_btn.isEnabled()) self.assertTrue(com_ctrl_widget.load_dark_run_btn.isEnabled()) self.assertTrue(ctrl_widget.dummy_widget.isEnabled()) client_stop.assert_called_once() timer_stop.assert_called_once() with patch.object(client, "start") as client_start: with patch.object(win._plot_timer_st, "start") as timer_start: with patch.object(worker, "sources") as mocked_sources: with self.assertLogs(logger, level="ERROR") as cm: mocked_sources.return_value = [("", "property1", 1)] QTest.mouseClick(com_ctrl_widget.start_btn, Qt.LeftButton) client_start.assert_not_called() timer_start.assert_not_called() self.assertIn("Empty source", cm.output[0]) with self.assertLogs(logger, level="ERROR") as cm: mocked_sources.return_value = [("device", "", 0)] QTest.mouseClick(com_ctrl_widget.start_btn, Qt.LeftButton) client_start.assert_not_called() timer_start.assert_not_called() self.assertIn("Empty property", cm.output[0]) with self.assertLogs(logger, level="ERROR") as cm: mocked_sources.return_value = [("device", "property", 2)] QTest.mouseClick(com_ctrl_widget.start_btn, Qt.LeftButton) client_start.assert_not_called() timer_start.assert_not_called() self.assertIn("Not understandable data type", cm.output[0]) with patch.object(client, "onResetST") as client_reset: with patch.object(worker, "onResetST") as worker_reset: with patch.object(win._line, "reset") as line_reset: with patch.object(win._view, "reset") as view_reset: QTest.mouseClick(com_ctrl_widget.reset_btn, Qt.LeftButton) client_reset.assert_called_once() worker_reset.assert_called_once() line_reset.assert_called_once() view_reset.assert_called_once() with patch.object(worker._input_st, "clear") as input_clear: with patch.object(worker._output_st, "clear") as output_clear: worker._reset_st = False worker.onResetST() input_clear.assert_called_once() output_clear.assert_called_once() worker._reset_st = True with patch.object(client._transformer_st, "reset") as transformer_reset: with patch.object(client._output_st, "clear") as output_clear: client.onResetST() transformer_reset.assert_called_once() output_clear.assert_called_once()
def test_log_to_log_add_win_with_test_fd_file(self): """Test transition from log display window to add-to-log window using the test FD file.""" log_win = interface.LogWin() with patch.object(interface, 'EditLogWin') as edit_log_win_mock: QTest.mouseClick(log_win.add_entries_btn, Qt.LeftButton) edit_log_win_mock.assert_called()
sel = qtc.selectedText() print('{0} v {1}'.format(str, sel)) return str == sel test_target = ev.Editor # wait half a sec, key ctrl-up key_into('up', 'ctl', 200) # then shift-right to select "1." key_seq([('rt', 'shf'), ('rt', 'shf')]) # check that assert check_sel('1.') # click in the linenumber field, select-all, key a 3 and return test_target = ev.LineNumber QTest.mouseClick(test_target, Qt.LeftButton) key_into(Qt.Key_A, 'ctl') key_into(Qt.Key_3) key_into(Qt.Key_Enter) # focus should now be back to editor, shift-right to select "3." test_target = ev.Editor key_seq([('rt', 'shf'), ('rt', 'shf')]) # check that assert check_sel('3.') # try a couple of invalid line numbers, each time verifying the # selection hasn't changed. test_target = ev.LineNumber QTest.mouseClick(test_target, Qt.LeftButton) key_into(Qt.Key_A, 'ctl') key_into(Qt.Key_0) key_into(Qt.Key_Enter)
def test_checkHITLZoom(self): ''' Check that changing resolution doesn't make an action ''' buttons = [self.m.zoomInButton, self.m.zoomOutButton] for button in buttons: QTest.mouseClick(button, Qt.LeftButton) self.assertEqual(self.m.HITL_logger, [])
def test_enableHITLCheckBox(self): ''' Test the HITL checkbox works ''' self.m.HITL = False QTest.mouseClick(self.m.HITL_mode, Qt.LeftButton) self.assertTrue(self.m.HITL_mode.isChecked())
def test_log_to_log_add_win_no_fd_file(self, exists_mock): """Test transition from log window to add-to-log window while no FD file exists.""" log_win = interface.LogWin() with patch.object(interface, 'MessageWin') as message_win_mock: QTest.mouseClick(log_win.add_entries_btn, Qt.LeftButton) message_win_mock.assert_called()
def test_disableAutoGen(self): QTest.mouseClick(self.w.ui.enabledRb, Qt.LeftButton) QTest.mouseClick(self.w.ui.disabledRb, Qt.LeftButton) self.assertEqual(self.settings.value('directories_autogen'), 'false')
def go_to_and_wait_for_downloads(window): QTest.mouseClick(window.left_menu_button_downloads, Qt.LeftButton) QTest.mouseClick(window.downloads_all_button, Qt.LeftButton) wait_for_variable(window, "downloads_page.downloads")