def _ClickInViewCenter(self): view = OMUI.M3dView.active3dView() viewWidget = wrapInstance(int(view.widget()), QWidget) QTest.mouseClick(viewWidget, QtCore.Qt.LeftButton, QtCore.Qt.NoModifier, viewWidget.rect().center())
def keyRelease(self, widget, key, modifier=qt.Qt.NoModifier, delay=-1): """Sends a Qt key release event. See QTest.keyRelease for details. """ QTest.keyRelease(widget, key, modifier, delay) self.qWait(20)
def test_roll(self): old = self.data.value while self.data.value == old: QTest.mouseClick(self.form.button, Qt.LeftButton) self.assertNotEqual(old, self.data.value) self.assertEqual(self.data.value, self.form.edit.value()) self.assertEqual(self.data.value, self.form.otheredit.value())
def test_show(self, qtbot: QTest, main_widget: MainWidget): main_widget.testnet_group_box.node_set.lnd_client.generate_seed = MagicMock( return_value=GenSeedResponse( cipher_seed_mnemonic=['test', 'seed'])) qtbot.mouseClick( main_widget.testnet_group_box.lnd_wallet_layout. create_wallet_button, Qt.LeftButton)
def keyClick(self, widget, key, modifier=qt.Qt.NoModifier, delay=-1): """Simulate clicking a key. See QTest.keyClick for details. """ QTest.keyClick(widget, key, modifier, delay) self.qWait(20)
def test_select_directory_button(self, reveal_patch: MagicMock, select_directory_dialog_patch: MagicMock, data_directory_box: DataDirectoryBox, qtbot: QTest): qtbot.mouseClick(data_directory_box.select_directory_button, Qt.LeftButton) data_directory_box.file_dialog.select_new.assert_called_once()
def test_bitcoin_qt_node_button(self, mock_bitcoin_launch: MagicMock, qtbot: QTest): launch_widget = LaunchWidget() qtbot.mouseClick( launch_widget.testnet_group_box.nodes_layout.bitcoin_qt_button, Qt.LeftButton) mock_bitcoin_launch.assert_called_once()
def test_ButtonClickOnInput_e_of_x(self): """test the plotting of f(x)=e(x)""" self.form.input_field.clear() QTest.keyClicks(self.form.input_field, "e(x)") assert self.form.input_field.text() == "e(x)" QTest.mouseClick(self.form.button, QtCore.Qt.LeftButton) assert self.form.msg.text() == 'Error'
def test_LongInfoMessage(self): """Test LongInfoMessage""" with patch("physbiblio.gui.basicDialogs.LongInfoMessage.exec_", autospec=True) as _e: win = LongInfoMessage("mymessage") _e.assert_called_once_with() self.assertIsInstance(win, QDialog) self.assertEqual(win.windowTitle(), "Information") self.assertIsInstance(win.layout(), QGridLayout) self.assertEqual(win.layout(), win.gridlayout) self.assertIsInstance(win.layout().itemAtPosition(0, 0).widget(), QTextEdit) self.assertEqual(win.layout().itemAtPosition(0, 0).widget(), win.textarea) self.assertEqual(win.textarea.isReadOnly(), True) self.assertEqual(win.textarea.toPlainText(), "mymessage") self.assertIsInstance(win.layout().itemAtPosition(1, 1).widget(), QPushButton) self.assertEqual(win.layout().itemAtPosition(1, 1).widget(), win.okbutton) self.assertEqual(win.okbutton.text(), "OK") with patch("PySide2.QtWidgets.QDialog.close") as _c: QTest.mouseClick(win.okbutton, Qt.LeftButton) _c.assert_called_once_with(win) mb = MagicMock() with patch("physbiblio.gui.basicDialogs.LongInfoMessage.exec_", autospec=True) as _e: win = LongInfoMessage("mymessage", "mytitle") self.assertEqual(win.windowTitle(), "mytitle")
def test_ButtonClickOnInputX(self): """test the plotting of f(x)=x""" self.form.input_field.clear() QTest.keyClicks(self.form.input_field, "x") assert self.form.input_field.text() == "x" QTest.mouseClick(self.form.button, QtCore.Qt.LeftButton) assert self.form.canvas.figure is not None
def testObjectPosition(self): """ Tests that an object created interactively is positioned correctly on the live surface. """ # Make our proxy shape live. cmds.makeLive('Block_1') # Enter interactive creation context. cmds.setToolTo('CreatePolyTorusCtx') # Click in the center of the viewport widget. QTest.mouseClick(self._viewWidget, QtCore.Qt.LeftButton, QtCore.Qt.NoModifier, self._viewWidget.rect().center()) # Find the torus (it should be called pTorus1). self.assertTrue(cmds.ls('pTorus1')) # Check the torus's transform. # The Block_1 is originally 1 unit deep and centered at the origin, so # its original top plane is aligned at z=0.5. # It is scaled 5x, which makes the top plane aligned at z=2.5. # Then it is translated along z by 4.0, so its top plane is finally # aligned at z=6.5. translate = cmds.xform('pTorus1', q=True, t=True) self.assertAlmostEqual(translate[2], 6.5, places=3)
def test_mainnet_rest_url_copy_button(self, qtbot: QTest, launch_widget: LaunchWidget): qtbot.mouseClick(launch_widget.mainnet_group_box.rest_url_copy_button, Qt.LeftButton) rest_url = launch_widget.node_launcher.command_generator.mainnet_rest_url( ) assert QClipboard().text() == rest_url
def keyClicks(self, widget, sequence, modifier=qt.Qt.NoModifier, delay=-1): """Simulate clicking a sequence of keys. See QTest.keyClick for details. """ QTest.keyClicks(widget, sequence, modifier, delay) self.qWait(20)
def keyPress(self, widget, key, modifier=qt.Qt.NoModifier, delay=-1): """Sends a Qt key press event. See QTest.keyPress for details. """ QTest.keyPress(widget, key, modifier, delay) self.qWait(20)
def test_selection_in_design_view_6(self): """Test multiple item selection in Design View. First mouse click on project item (Ctrl-key pressed). Second mouse click on a project item (Ctrl-key pressed). """ self._temp_dir = TemporaryDirectory() create_project(self.toolbox, self._temp_dir.name) dc1 = "DC1" dc2 = "DC2" add_dc(self.toolbox.project(), dc1, x=0, y=0) add_dc(self.toolbox.project(), dc2, x=100, y=100) n_items = self.toolbox.project_item_model.n_items() self.assertEqual(n_items, 2) # Check the number of project items dc1_index = self.toolbox.project_item_model.find_item(dc1) dc2_index = self.toolbox.project_item_model.find_item(dc2) gv = self.toolbox.ui.graphicsView dc1_item = self.toolbox.project_item_model.item(dc1_index).project_item dc2_item = self.toolbox.project_item_model.item(dc2_index).project_item dc1_center_point = self.find_click_point_of_pi(dc1_item, gv) dc2_center_point = self.find_click_point_of_pi(dc2_item, gv) # Mouse click on dc1 QTest.mouseClick(gv.viewport(), Qt.LeftButton, Qt.ControlModifier, dc1_center_point) # Then mouse click on dc2 QTest.mouseClick(gv.viewport(), Qt.LeftButton, Qt.ControlModifier, dc2_center_point) tv_sm = self.toolbox.ui.treeView_project.selectionModel() self.assertEqual(2, len(tv_sm.selectedIndexes())) self.assertTrue(tv_sm.isSelected(dc1_index)) self.assertTrue(tv_sm.isSelected(dc2_index)) # NOTE: No test for tv_sm current index here! self.assertEqual(2, len(gv.scene().selectedItems())) # Active project item should be None self.assertIsNone(self.toolbox.active_project_item)
def test_autocaps(self): self.editor.autocaps = True QTest.keyClicks(self.editor, 'thi!\' ') self.assertEqual(self.editor.textCursor().block().text(), 'The!\' ') QTest.keyClicks(self.editor, 'thi. the ') self.assertEqual(self.editor.textCursor().block().text(), 'The!\' The. The ')
def test_selection_in_design_view_1(self): """Test item selection in Design View. Simulates mouse click on a Data Connection item. Test a single item selection. """ self._temp_dir = TemporaryDirectory() create_project(self.toolbox, self._temp_dir.name) dc1 = "DC1" add_dc(self.toolbox.project(), dc1, x=0, y=0) n_items = self.toolbox.project_item_model.n_items() self.assertEqual(n_items, 1) # Check that the project contains one item dc1_index = self.toolbox.project_item_model.find_item(dc1) gv = self.toolbox.ui.graphicsView dc1_item = self.toolbox.project_item_model.item(dc1_index).project_item dc1_center_point = self.find_click_point_of_pi( dc1_item, gv) # Center point in graphics view viewport coords. # Simulate mouse click on Data Connection in Design View QTest.mouseClick(gv.viewport(), Qt.LeftButton, Qt.NoModifier, dc1_center_point) tv_sm = self.toolbox.ui.treeView_project.selectionModel() self.assertTrue(tv_sm.isSelected(dc1_index)) self.assertEqual(dc1_index, tv_sm.currentIndex()) self.assertEqual(1, len(tv_sm.selectedIndexes())) self.assertEqual(1, len(gv.scene().selectedItems())) # Active project item should be DC1 self.assertEqual( self.toolbox.project_item_model.item(dc1_index).project_item, self.toolbox.active_project_item)
def test_selection_in_design_view_3(self): """Test item selection in Design View. First mouse click on project item. Second mouse click on design view. """ self._temp_dir = TemporaryDirectory() create_project(self.toolbox, self._temp_dir.name) dc1 = "DC1" add_dc(self.toolbox.project(), dc1, x=0, y=0) dc1_index = self.toolbox.project_item_model.find_item(dc1) gv = self.toolbox.ui.graphicsView dc1_item = self.toolbox.project_item_model.item(dc1_index).project_item dc1_center_point = self.find_click_point_of_pi(dc1_item, gv) # Mouse click on dc1 QTest.mouseClick(gv.viewport(), Qt.LeftButton, Qt.NoModifier, dc1_center_point) # Then mouse click somewhere else in Design View (not on project item) QTest.mouseClick(gv.viewport(), Qt.LeftButton, Qt.NoModifier, QPoint(1, 1)) # Treeview current index should be dc1_index tv_sm = self.toolbox.ui.treeView_project.selectionModel() self.assertEqual(dc1_index, tv_sm.currentIndex()) self.assertEqual(0, len( tv_sm.selectedIndexes())) # No items in pi list should be selected self.assertEqual(0, len(gv.scene().selectedItems()) ) # No items in design view should be selected # Active project item should be None self.assertIsNone(self.toolbox.active_project_item)
def test_selection_in_project_item_list_1(self): """Test item selection in treeView_project. Simulates a mouse click on a Data Store item in the project Tree View widget (i.e. the project item list). """ with TemporaryDirectory() as project_dir: create_project(self.toolbox, project_dir) ds1 = "DS1" add_ds(self.toolbox.project(), ds1) n_items = self.toolbox.project_item_model.n_items() self.assertEqual(n_items, 1) # Check that the project contains one item ds_ind = self.toolbox.project_item_model.find_item(ds1) tv = self.toolbox.ui.treeView_project tv.expandAll() # NOTE: mouseClick does not work without this tv_sm = tv.selectionModel() # Scroll to item -> get rectangle -> click tv.scrollTo(ds_ind) # Make sure the item is 'visible' ds1_rect = tv.visualRect(ds_ind) # logging.debug("viewport geometry:{0}".format(tv.viewport().geometry())) # this is pos() and size() combined # logging.debug("item rect:{0}".format(ds1_rect)) # Simulate mouse click on selected item QTest.mouseClick(tv.viewport(), Qt.LeftButton, Qt.NoModifier, ds1_rect.center()) self.assertTrue(tv_sm.isSelected(ds_ind)) self.assertEqual(tv_sm.currentIndex(), ds_ind) self.assertEqual(1, len(tv_sm.selectedIndexes())) # Active project item should be DS1 self.assertEqual( self.toolbox.project_item_model.item(ds_ind).project_item, self.toolbox.active_project_item)
def test_selection_in_project_item_list_2(self): """Test item selection in treeView_project. Simulates mouse clicks on a Data Store items. Click on a project item and then on another project item. """ with TemporaryDirectory() as project_dir: create_project(self.toolbox, project_dir) ds1 = "DS1" ds2 = "DS2" add_ds(self.toolbox.project(), ds1) add_ds(self.toolbox.project(), ds2) n_items = self.toolbox.project_item_model.n_items() self.assertEqual(n_items, 2) ds1_ind = self.toolbox.project_item_model.find_item(ds1) ds2_ind = self.toolbox.project_item_model.find_item(ds2) tv = self.toolbox.ui.treeView_project tv.expandAll() tv_sm = tv.selectionModel() # Scroll to item -> get rectangle -> click tv.scrollTo(ds1_ind) ds1_rect = tv.visualRect(ds1_ind) QTest.mouseClick(tv.viewport(), Qt.LeftButton, Qt.NoModifier, ds1_rect.center()) # Scroll to item -> get rectangle -> click tv.scrollTo(ds2_ind) ds2_rect = tv.visualRect(ds2_ind) QTest.mouseClick(tv.viewport(), Qt.LeftButton, Qt.NoModifier, ds2_rect.center()) self.assertTrue(tv_sm.isSelected(ds2_ind)) self.assertEqual(tv_sm.currentIndex(), ds2_ind) self.assertEqual(1, len(tv_sm.selectedIndexes())) # Active project item should be DS2 self.assertEqual( self.toolbox.project_item_model.item(ds2_ind).project_item, self.toolbox.active_project_item)
def test_selection_in_design_view_2(self): """Test item selection in Design View. First mouse click on project item. Second mouse click on a project item. """ create_project(self.toolbox) dc1 = "DC1" dc2 = "DC2" add_dc(self.toolbox.project(), dc1, x=0, y=0) add_dc(self.toolbox.project(), dc2, x=100, y=100) n_items = self.toolbox.project_item_model.n_items() self.assertEqual(n_items, 2) # Check the number of project items dc1_index = self.toolbox.project_item_model.find_item(dc1) dc2_index = self.toolbox.project_item_model.find_item(dc2) gv = self.toolbox.ui.graphicsView dc1_item = self.toolbox.project_item_model.item(dc1_index).project_item dc2_item = self.toolbox.project_item_model.item(dc2_index).project_item dc1_center_point = self.find_click_point_of_pi(dc1_item, gv) dc2_center_point = self.find_click_point_of_pi(dc2_item, gv) # Mouse click on dc1 QTest.mouseClick(gv.viewport(), Qt.LeftButton, Qt.NoModifier, dc1_center_point) # Then mouse click on dc2 QTest.mouseClick(gv.viewport(), Qt.LeftButton, Qt.NoModifier, dc2_center_point) tv_sm = self.toolbox.ui.treeView_project.selectionModel() self.assertTrue(tv_sm.isSelected(dc2_index)) self.assertEqual(dc2_index, tv_sm.currentIndex()) self.assertEqual(1, len(tv_sm.selectedIndexes())) self.assertEqual(1, len(gv.scene().selectedItems())) # Active project item should be DC2 self.assertEqual( self.toolbox.project_item_model.item(dc2_index).project_item, self.toolbox.active_project_item)
def test_click_insn(self): main_window = self._open_a_project() func = main_window.workspace.instance.project.kb.functions['main'] self.assertIsNotNone(func) # display function main disasm_view = main_window.workspace._get_or_create_disassembly_view() disasm_view._t_flow_graph_visible = True disasm_view.display_function(func) # get and click the first bbl of function main block = disasm_view.current_graph._insaddr_to_block.get(func.addr) insn = block.addr_to_insns[func.addr] scene = QGraphicsScene() scene.addItem(insn) view = QGraphicsView(scene) QTest.mouseClick(view.viewport(), Qt.MouseButton.LeftButton) # assert that slacrs logged the information sleep(5) self.session = Slacrs(database=Conf.checrs_backend_str).session() result = self.session.query(HumanActivity).filter( HumanActivity.project_md5 == self.project_md5, HumanActivity.addr == insn.addr, ).one() self.session.close() self.assertIsNotNone(result)
def test_index_preservation(self): text = 'e den ' alt_text = 'i den ' QTest.keyClicks(self.editor, text) self.editor.handle_mode_toggle() # wordcheck mode cur = self.editor.textCursor() cur.setPosition(0) self.editor.setTextCursor(cur) QTest.keyClick(self.editor, Qt.Key_R) new_text = self.editor.toPlainText() self.assertEqual(alt_text, new_text, msg="e to i") # Move to other word and back. cur = self.editor.textCursor() cur.setPosition(4) self.editor.setTextCursor(cur) cur = self.editor.textCursor() cur.setPosition(0) self.editor.setTextCursor(cur) QTest.keyClick(self.editor, Qt.Key_R) QTest.keyClick(self.editor, Qt.Key_R) QTest.keyClick(self.editor, Qt.Key_R) new_text = self.editor.toPlainText() self.assertEqual(text, new_text, msg="i to e")
def test_roll(self, data_instance, form): old = data_instance.value #while data_instance.value == old: QTest.mouseClick(form.button, Qt.LeftButton) assert old != data_instance.value assert data_instance.value == form.edit.value() assert data_instance.value == form.otheredit.value()
def closeDialog(self, close): """ :param close: False => Close only the Dialog True => Close the entire Application :return: None """ self.lineEdit_identity.setText("Closing ...") """ Without QTest.qWait(10) the precedent line is ignored ! Pause to show the MsgDialog closing sequence. """ if PYSIDE2: time.sleep(10 / 1000) # [s] (ms >= 10) Process events while waiting else: QTest.qWait(10) # [ms] # # if not close: # Close only Dialog v.close_button = "" # Reset references to QPushButtons v.yes_button = "" v.no_button = "" self.close() else: # Close GeoAnalyzer print("MsgDialog.closeDialog returned: Program terminated") QtWidgets.QApplication.instance( ).quit # See /home/lorenzo/Python3/PyQt5/examples/widgets/tetrix.py sys.exit()
def testObjectNormal(self): """ Tests that an object created interactively by dragging in the viewport has the correct orientation based on the live surface normal. """ from pxr import Gf # Load our reference assembly. UsdMaya.LoadReferenceAssemblies() # Create a new custom viewport. window = cmds.window(widthHeight=(500, 400)) cmds.paneLayout() panel = cmds.modelPanel() cmds.modelPanel(panel, edit=True, camera='persp') cmds.modelEditor(cmds.modelPanel(panel, q=True, modelEditor=True), edit=True, displayAppearance='smoothShaded', rnm='vp2Renderer') cmds.showWindow(window) # Get the viewport widget. view = OMUI.M3dView() OMUI.M3dView.getM3dViewFromModelPanel(panel, view) viewWidget = wrapInstance(long(view.widget()), QWidget) # Make our assembly live. cmds.makeLive('Block_2') # Enter interactive creation context. cmds.setToolTo('CreatePolyConeCtx') # Click in the center of the viewport widget. QTest.mouseClick(viewWidget, QtCore.Qt.LeftButton, QtCore.Qt.NoModifier, viewWidget.rect().center()) # Find the cone (it should be called pCone1). self.assertTrue(cmds.ls('pCone1')) # Check the cone's rotation. # Because our scene is Z-axis up, the cone's Z-axis should be aligned # with Block_2's surface normal (though it might not necessarily have # the same exact rotation). rotationAngles = cmds.xform('pCone1', q=True, ro=True) rotation = (Gf.Rotation(Gf.Vec3d.XAxis(), rotationAngles[0]) * Gf.Rotation(Gf.Vec3d.YAxis(), rotationAngles[1]) * Gf.Rotation(Gf.Vec3d.ZAxis(), rotationAngles[2])) actualZAxis = rotation.TransformDir(Gf.Vec3d.ZAxis()) expectedRotation = (Gf.Rotation(Gf.Vec3d.XAxis(), 75.0) * Gf.Rotation(Gf.Vec3d.YAxis(), 90.0)) expectedZAxis = expectedRotation.TransformDir(Gf.Vec3d.ZAxis()) # Verify that the error angle between the two axes is less than # 0.1 degrees (less than ~0.0003 of a revolution, so not bad). That's # about as close as we're going to get. errorRotation = Gf.Rotation(actualZAxis, expectedZAxis) self.assertLess(errorRotation.GetAngle(), 0.1)
def test_show_bitcoin_conf(self, reveal_patch: MagicMock, bitcoind_configuration_tab, qtbot: QTest): qtbot.mouseClick(bitcoind_configuration_tab.show_bitcoin_conf, Qt.LeftButton) reveal_patch.assert_called_with('/test/bitcoin')
def _SelectAreaInView(viewWidget, selectAreaRange, keyboardModifier=QtCore.Qt.NoModifier): pressPoint = QtCore.QPoint(selectAreaRange.min[0], selectAreaRange.min[1]) releasePoint = QtCore.QPoint(selectAreaRange.max[0], selectAreaRange.max[1]) QTest.mousePress(viewWidget, QtCore.Qt.LeftButton, keyboardModifier, pressPoint) QTest.mouseRelease(viewWidget, QtCore.Qt.LeftButton, keyboardModifier, releasePoint)
def test_alerts_on_invalid_parameter(self): #using NoMicrographsChosen as a representative of InvalidParameter a = Main_window() with patch('ui_elements.main_window.Main_window.alert_user') as p: QTest.mouseClick( a.runButton, Qt.LeftButton) #will trigger no micrographs selected p.assert_called_with()
def test_open_zap_desktop_button( self, qlabel_patch: MagicMock, qpixmap_patch: MagicMock, webbrowser_patch: MagicMock, get_qrcode_img_patch: MagicMock, get_deprecated_lndconnect_url_patch: MagicMock, zap_layout: ZapLayout, qtbot: QTest): qtbot.mouseClick(zap_layout.open_zap_desktop_button, Qt.LeftButton) get_deprecated_lndconnect_url_patch.assert_called_once() webbrowser_patch.open.assert_called_once()
def testKeyEvent(self): widget = QLineEdit() key = Qt.Key_A eventFilter = KeyEventFilter(widget, QEvent.KeyPress, key) widget.installEventFilter(eventFilter) QTest.keyClick(widget, key) self.assert_(eventFilter.processed)
def testBasic(self): '''QTest.mouseClick with QCheckBox''' button = QPushButton() button.setCheckable(True) button.setChecked(False) QTest.mouseClick(button, Qt.LeftButton) self.assert_(button.isChecked()) QTest.mouseClick(button, Qt.LeftButton) self.assertFalse(button.isChecked())
def generateEvent(self): o = QTest.touchEvent(self) o.press(0, QPoint(10, 10)) o.commit() del o QTest.touchEvent(self).press(0, QPoint(10, 10)) QTest.touchEvent(self).stationary(0).press(1, QPoint(40, 10)) QTest.touchEvent(self).move(0, QPoint(12, 12)).move(1, QPoint(45, 5)) QTest.touchEvent(self).release(0, QPoint(12, 12)).release(1, QPoint(45, 5)) QTimer.singleShot(200, self.deleteLater)