本文整理汇总了Python中qtpy.QtTest.QTest类的典型用法代码示例。如果您正苦于以下问题:Python QTest类的具体用法?Python QTest怎么用?Python QTest使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QTest类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_phase_name_difference_after_modified
def test_phase_name_difference_after_modified(self):
self.main_controller = MainController(use_settings=False)
self.main_controller.model.calibration_model.integrate_1d = self.model.calibration_model.integrate_1d
self.main_controller.model.calibration_model.load(os.path.join(data_path, 'LaB6_40keV_MarCCD.poni'))
self.main_controller.calibration_controller.set_calibrant(7)
self.main_controller.model.img_model.load(os.path.join(data_path, 'LaB6_40keV_MarCCD.tif'))
self.main_controller.widget.tabWidget.setCurrentIndex(2)
self.main_controller.widget.integration_widget.tabWidget.setCurrentIndex(3)
QtWidgets.QFileDialog.getOpenFileNames = MagicMock(
return_value=[os.path.join(jcpds_path, 'au_Anderson.jcpds')])
self.phase_controller = self.main_controller.integration_controller.phase_controller
click_button(self.phase_controller.widget.phase_add_btn)
# Erwin starts the software loads Gold and wants to see what is in the jcpds file, however since he does not
# change anything the names every are the same...
self.phase_controller = self.main_controller.integration_controller.phase_controller
self.jcpds_editor_controller = self.phase_controller.jcpds_editor_controller
self.jcpds_widget = self.jcpds_editor_controller.widget
self.jcpds_phase = self.main_controller.model.phase_model.phases[0]
self.jcpds_in_spec = self.main_controller.integration_controller.widget.pattern_widget.phases[0]
self.assertEqual('au_Anderson', self.jcpds_phase.name)
self.assertEqual('au_Anderson', str(self.phase_controller.widget.phase_tw.item(0, 2).text()))
self.phase_controller.widget.phase_tw.selectRow(0)
QTest.mouseClick(self.phase_controller.widget.phase_edit_btn, QtCore.Qt.LeftButton)
QtWidgets.QApplication.processEvents()
self.assertEqual('au_Anderson', self.jcpds_phase.name)
self.assertEqual('au_Anderson', str(self.phase_controller.widget.phase_tw.item(0, 2).text()))
示例2: test_automatic_file_processing
def test_automatic_file_processing(self):
# get into a specific folder
QtWidgets.QFileDialog.getOpenFileNames = MagicMock(
return_value=[os.path.join(unittest_data_path, 'image_001.tif')])
click_button(self.widget.load_img_btn)
self.assertEqual(str(self.widget.img_filename_txt.text()), 'image_001.tif')
self.assertEqual(self.model.working_directories['image'], unittest_data_path)
# enable autoprocessing:
QTest.mouseClick(self.widget.autoprocess_cb, QtCore.Qt.LeftButton,
pos=QtCore.QPoint(2, self.widget.autoprocess_cb.height() / 2.0))
self.assertFalse(self.model.configurations[0].img_model._directory_watcher.signalsBlocked())
self.assertFalse(
self.model.configurations[0].img_model._directory_watcher._file_system_watcher.signalsBlocked())
self.assertTrue(self.widget.autoprocess_cb.isChecked())
self.assertTrue(self.model.img_model.autoprocess)
shutil.copy2(os.path.join(unittest_data_path, 'image_001.tif'),
os.path.join(unittest_data_path, 'image_003.tif'))
self.model.configurations[0].img_model._directory_watcher._file_system_watcher.directoryChanged.emit(
unittest_data_path)
self.assertEqual('image_003.tif', str(self.widget.img_filename_txt.text()))
示例3: test_changing_supersampling_amount_integrating_to_cake_with_mask
def test_changing_supersampling_amount_integrating_to_cake_with_mask(self):
# Edith opens the program, calibrates everything and looks in to the options menu. She sees that there is a
# miraculous parameter called supersampling. It is currently set to 1 which seems to be normal
self.assertEqual(self.integration_widget.supersampling_sb.value(), 1)
# then she sets it to two and she sees that the number of pattern bin changes and that the pattern looks
# smoother
# values before:
px1 = self.model.calibration_model.pattern_geometry.pixel1
px2 = self.model.calibration_model.pattern_geometry.pixel2
img_shape = self.model.img_data.shape
self.integration_widget.supersampling_sb.setValue(2)
self.assertEqual(self.model.calibration_model.pattern_geometry.pixel1, 0.5 * px1)
self.assertEqual(self.model.calibration_model.pattern_geometry.pixel2, 0.5 * px2)
self.assertEqual(self.model.calibration_model.cake_geometry.pixel1, px1)
self.assertEqual(self.model.calibration_model.cake_geometry.pixel2, px2)
# img data has doubled dimensions
self.assertEqual(self.model.img_data.shape[0], 2 * img_shape[0])
self.assertEqual(self.model.img_data.shape[1], 2 * img_shape[1])
# but plot should still be the same:
self.assertEqual(self.integration_widget.img_widget.img_data.shape[0], img_shape[0])
self.assertEqual(self.integration_widget.img_widget.img_data.shape[1], img_shape[1])
self.model.mask_model.mask_below_threshold(self.model.img_model._img_data, 100)
QTest.mouseClick(self.integration_widget.img_mask_btn, QtCore.Qt.LeftButton)
QTest.mouseClick(self.integration_widget.img_mode_btn, QtCore.Qt.LeftButton)
示例4: test_name_widget_close_button_pressed_calls_presenter
def test_name_widget_close_button_pressed_calls_presenter(self):
plot_numbers = [0, 1, 2]
self.view.set_plot_list(plot_numbers)
widget = self.view.table_widget.cellWidget(1, 1)
QTest.mouseClick(widget.close_button, Qt.LeftButton)
self.presenter.close_single_plot.assert_called_once_with(1)
示例5: test_name_widget_close_button_pressed_leaves_selection_unchanged
def test_name_widget_close_button_pressed_leaves_selection_unchanged(self):
plot_numbers = [0, 1, 2]
self.view.set_plot_list(plot_numbers)
# Set the selected items by clicking with control held
for row in [0, 2]:
widget = self.view.table_widget.cellWidget(row, Column.Name)
QTest.mouseClick(widget, Qt.LeftButton, Qt.ControlModifier)
# Expected result: [0, 2]
# Something goes wrong in QTest here and the selection is
# not set with the control key modifier.
plots_selected_old = self.view.get_all_selected_plot_numbers()
self.assertEquals(plots_selected_old, [])
widget = self.view.table_widget.cellWidget(1, Column.Name)
QTest.mouseClick(widget.close_button, Qt.LeftButton)
# We need to actually update the plot list, as the presenter would
self.view.remove_from_plot_list(1)
self.presenter.close_single_plot.assert_called_once_with(1)
plots_selected_new = self.view.get_all_selected_plot_numbers()
# Expected result: [0, 2]
# Something goes wrong in QTest here and the selection is
# not set with the control key modifier.
self.assertEquals(plots_selected_old, plots_selected_new)
示例6: test_remove_subset_triggers_selection_changed
def test_remove_subset_triggers_selection_changed(self):
layer = self.add_layer()
grp = self.collect.new_subset_group()
mock = MagicMock()
self.select_layers(grp)
self.widget.ui.layerTree.selection_changed.connect(mock)
QTest.mouseClick(self.widget.ui.layerRemoveButton, Qt.LeftButton)
assert mock.call_count > 0
示例7: show_context_menu
def show_context_menu(self, widget, pos, pause=0):
QTest.mouseMove(widget, pos)
yield pause
QTest.mouseClick(widget, Qt.RightButton, Qt.NoModifier, pos)
yield pause
ev = QMouseEvent(QEvent.ContextMenu, pos, Qt.RightButton, Qt.NoButton, Qt.NoModifier)
QApplication.postEvent(widget, ev)
yield self.wait_for_popup()
示例8: test_rename_button_pressed_makes_line_editable
def test_rename_button_pressed_makes_line_editable(self):
plot_numbers = [0, 1, 2]
self.view.set_plot_list(plot_numbers)
name_widget = self.view.table_widget.cellWidget(0, 1)
QTest.mouseClick(name_widget.rename_button, Qt.LeftButton)
self.assertFalse(name_widget.line_edit.isReadOnly())
self.assertTrue(name_widget.rename_button.isChecked())
示例9: test_run_dialog_opens_on_double_click
def test_run_dialog_opens_on_double_click(self):
with patch(createDialogFromName_func_name) as createDialog:
widget = AlgorithmSelectorWidget()
self._select_in_tree(widget, 'Load v.1')
selected_item = widget.tree.selectedItems()[0]
item_pos = widget.tree.visualItemRect(selected_item).center()
QTest.mouseDClick(widget.tree.viewport(), Qt.LeftButton,
Qt.NoModifier, pos=item_pos)
createDialog.assert_called_once_with('Load', 1)
示例10: open_file_in_editor
def open_file_in_editor(main_window, fname, directory=None):
"""Open a file using the Editor and its open file dialog"""
top_level_widgets = QApplication.topLevelWidgets()
for w in top_level_widgets:
if isinstance(w, QFileDialog):
if directory is not None:
w.setDirectory(directory)
input_field = w.findChildren(QLineEdit)[0]
input_field.setText(fname)
QTest.keyClick(w, Qt.Key_Enter)
示例11: test_saving_image
def test_saving_image(self):
# the widget has to be shown to be able to save the image:
self.integration_widget.show()
# Tests if the image save procedures are working for the different possible file endings
QtWidgets.QFileDialog.getSaveFileName = MagicMock(return_value=os.path.join(data_path, 'Test_img.png'))
QTest.mouseClick(self.integration_widget.qa_save_img_btn, QtCore.Qt.LeftButton)
QtWidgets.QFileDialog.getSaveFileName = MagicMock(return_value=os.path.join(data_path, 'Test_img.tiff'))
QTest.mouseClick(self.integration_widget.qa_save_img_btn, QtCore.Qt.LeftButton)
self.assertTrue(os.path.exists(os.path.join(data_path, 'Test_img.png')))
self.assertTrue(os.path.exists(os.path.join(data_path, 'Test_img.tiff')))
示例12: test_select_all_button
def test_select_all_button(self):
plot_numbers = [0, 1, 2]
self.view.set_plot_list(plot_numbers)
QTest.mouseClick(self.view.select_all_button, Qt.LeftButton)
selected_plot_numbers = self.view.get_all_selected_plot_numbers()
# Expected result: [0, 1, 2]
# Something goes wrong in QTest here and the selection is
# always the first plot.
self.assertEqual([0], selected_plot_numbers)
示例13: test_rename_finishing_editing_makes_line_uneditable_and_calls_presenter
def test_rename_finishing_editing_makes_line_uneditable_and_calls_presenter(self):
plot_numbers = [0, 1, 2]
self.view.set_plot_list(plot_numbers)
name_widget = self.view.table_widget.cellWidget(1, Column.Name)
QTest.mouseClick(name_widget.rename_button, Qt.LeftButton)
QTest.keyPress(name_widget.line_edit, Qt.Key_Return)
self.presenter.rename_figure.assert_called_once_with(1, "Plot2")
self.assertTrue(name_widget.line_edit.isReadOnly())
self.assertFalse(name_widget.rename_button.isChecked())
示例14: test_pattern_bkg_txt_fields_change_linear_regions
def test_pattern_bkg_txt_fields_change_linear_regions(self):
self.model.pattern_model.load_pattern(os.path.join(data_path, 'pattern_001.xy'))
self.widget.bkg_pattern_gb.setChecked(True)
self.widget.bkg_pattern_inspect_btn.toggle()
self.widget.bkg_pattern_x_min_txt.setText('5')
QTest.keyPress(self.widget.bkg_pattern_x_min_txt, QtCore.Qt.Key_Enter)
self.widget.bkg_pattern_x_max_txt.setText('11')
QTest.keyPress(self.widget.bkg_pattern_x_max_txt, QtCore.Qt.Key_Enter)
x_min, x_max = self.widget.pattern_widget.linear_region_item.getRegion()
self.assertAlmostEqual(x_min, 5, delta=0.02)
self.assertAlmostEqual(x_max, 11, delta=0.02)
示例15: test_plot_name_double_clicked_calls_presenter_and_makes_plot_current
def test_plot_name_double_clicked_calls_presenter_and_makes_plot_current(self):
plot_numbers = [0, 1, 2]
self.view.set_plot_list(plot_numbers)
item = self.view.table_widget.item(1, 1)
item_center = self.view.table_widget.visualItemRect(item).center()
# This single click should not be required, but otherwise the double click is not registered
QTest.mouseClick(self.view.table_widget.viewport(), Qt.LeftButton, pos=item_center)
QTest.mouseDClick(self.view.table_widget.viewport(), Qt.LeftButton, pos=item_center)
self.assertEqual(self.presenter.show_single_selected.call_count, 1)
# Expected result: 1
# Something goes wrong in QTest here and the selection is
# always the first plot.
self.assertEqual(self.view.get_currently_selected_plot_number(), 0)