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)
Esempio n. 2
0
 def setUp(self):
     # create figure
     self._fig = _create_fig()
     # create GUI
     self.dialog = ExportDialog()
     self.dialog.show()
     QTest.qWaitForWindowActive(self.dialog)
Esempio n. 3
0
    def test_open_workspace_on_success(self):
        thread_event = threading.Event()

        class _SampleTarget(object):
            @staticmethod
            def validate(args, limit_to=None):
                return []

            @staticmethod
            def execute(args):
                thread_event.wait()

        form = FormTest.make_ui()
        target = _SampleTarget().execute
        form.run(target=target)

        self.assertTrue(form.run_dialog.openWorkspaceCB.isVisible())
        self.assertFalse(form.run_dialog.openWorkspaceButton.isVisible())

        form.run_dialog.openWorkspaceCB.setChecked(True)
        self.assertTrue(form.run_dialog.openWorkspaceCB.isChecked())

        thread_event.set()

        # close the window by pressing the back button.
        QTest.mouseClick(form.run_dialog.backButton,
                         QtCore.Qt.LeftButton)
Esempio n. 4
0
    def test_copy(self):
        data = self.fillTable(10)

        # no selection
        QTest.mouseClick(self.view.copy, Qt.LeftButton)
        for i in range(len(self.model._samples)):
            self.assertEqual(self.model._samples[i].getParameterValues(),
                             data[i])

        # row(s)
        self.selectRow(0, Qt.NoModifier)
        QTest.mouseClick(self.view.copy, Qt.LeftButton)
        for i in range(len(self.model._samples)):
            self.assertEqual(self.model._samples[i].getParameterValues(),
                             data[i])
        self.selectRow(0, Qt.NoModifier)
        self.selectRow(5, Qt.ControlModifier)
        QTest.mouseClick(self.view.copy, Qt.LeftButton)
        for i in range(len(self.model._samples)):
            self.assertEqual(self.model._samples[i].getParameterValues(),
                             data[i])

        # cells
        self.selectCell(0, 0, Qt.NoModifier)
        QTest.mouseClick(self.view.copy, Qt.LeftButton)
        for i in range(len(self.model._samples)):
            self.assertEqual(self.model._samples[i].getParameterValues(),
                             data[i])
        self.selectCell(0, 0, Qt.NoModifier)
        self.selectCell(5, 0, Qt.ShiftModifier)
        QTest.mouseClick(self.view.copy, Qt.LeftButton)
        for i in range(len(self.model._samples)):
            self.assertEqual(self.model._samples[i].getParameterValues(),
                             data[i])
    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()))
    def test_automatic_calibration(self):
        QtWidgets.QFileDialog.getOpenFileName = MagicMock(
            return_value=os.path.join(unittest_data_path,
                                      'LaB6_40keV_MarCCD.tif'))
        QTest.mouseClick(self.calibration_widget.load_img_btn,
                         QtCore.Qt.LeftButton)
        self.calibration_controller.search_peaks(1179.6, 1129.4)
        self.calibration_controller.search_peaks(1268.5, 1119.8)
        self.calibration_controller.widget.sv_wavelength_txt.setText('0.31')
        self.calibration_controller.widget.sv_distance_txt.setText('200')
        self.calibration_controller.widget.sv_pixel_width_txt.setText('79')
        self.calibration_controller.widget.sv_pixel_height_txt.setText('79')
        calibrant_index = self.calibration_widget.calibrant_cb.findText('LaB6')
        self.calibration_controller.widget.calibrant_cb.setCurrentIndex(
            calibrant_index)

        QTest.mouseClick(self.calibration_widget.calibrate_btn,
                         QtCore.Qt.LeftButton)
        self.app.processEvents()
        self.model.calibration_model.integrate_1d.assert_called_once()
        self.model.calibration_model.integrate_2d.assert_called_once()
        self.assertEqual(QtWidgets.QProgressDialog.setValue.call_count, 15)

        calibration_parameter = self.model.calibration_model.get_calibration_parameter(
        )[0]
        self.assertAlmostEqual(calibration_parameter['dist'], .1967, places=4)
Esempio n. 7
0
    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)
Esempio n. 8
0
    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()))
Esempio n. 9
0
    def test_setup(self):
        """
        Create the GUI
        """
        cs = chisurf.cs

        cs.comboBox_experimentSelect.setCurrentIndex(1)
        cs.comboBox_setupSelect.setCurrentIndex(0)
        filename_decay = "./test/data/tcspc/ibh_sample/Decay_577D.txt"
        filename_irf = "./test/data/tcspc/ibh_sample/Prompt.txt"

        cs.current_setup.skiprows = 11
        cs.current_setup.reading_routine = 'csv'
        cs.current_setup.is_jordi = False
        cs.current_setup.use_header = True
        cs.current_setup.matrix_columns = []
        cs.current_setup.polarization = 'vm'
        cs.current_setup.rep_rate = 10.0
        cs.current_setup.dt = 0.0141

        chisurf.macros.add_dataset(filename=filename_decay)
        chisurf.macros.add_dataset(filename=filename_irf)

        self.assertEqual(len(chisurf.imported_datasets), 3)

        # click on decay_item
        items = chisurf.widgets.get_all_items(cs.dataset_selector)
        rect = cs.dataset_selector.visualItemRect(items[1])
        QTest.mouseClick(cs.dataset_selector.viewport(), Qt.LeftButton,
                         Qt.NoModifier, rect.center())

        # click on add fit
        QTest.mouseClick(cs.pushButton_2, Qt.LeftButton)
    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)
    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)
Esempio n. 12
0
 def test_workspaceCalculator_enterPressed_rhs_scaling(self):
     presenter = WorkspaceCalculator(None, model=self.model)
     QTest.keyClick(presenter.view.rhs_scaling, Qt.Key_Return)
     # check calls
     self.assertEqual(presenter.model.updateParameters.call_count, 1)
     self.assertEqual(presenter.model.validateInputs.call_count, 0)
     self.assertEqual(presenter.model.performOperation.call_count, 0)
Esempio n. 13
0
 def test_saveRundex(self, mOpen, mJson, mFileDialog):
     self.model.setInstrument("D11")
     mFileDialog.getSaveFileName.return_value = ["test", "test"]
     QTest.mouseClick(self.view.save, Qt.LeftButton)
     visualSettings = {
         'FoldedColumns': [],
         'HiddenColumns': [],
         'ColumnsOrder': RundexSettings.COLUMNS['SANS']
     }
     visualSettings.update(RundexSettings.VISUAL_SETTINGS["SANS"])
     json = {
         'Instrument':
         'D11',
         'AcquisitionMode':
         'SANS',
         'VisualSettings':
         visualSettings,
         'GlobalSettings':
         {p.getName(): p.getValue()
          for p in self.model.getParameters()},
         'ExportAlgorithms': [
             algo
             for algo in RundexSettings.EXPORT_ALGORITHMS['SANS'].keys()
             if RundexSettings.EXPORT_ALGORITHMS['SANS'][algo]
         ]
     }
     self.assertDictEqual(json, mJson.dump.call_args[0][0])
    def test_jumpToAnnotations(self):
        """ Jumping to next/previous annotation """
        self.createInstance(os.path.join("ClickPointsExamples", "BirdAttack"))

        # wait for image to be loaded
        self.wait_for_image_load()

        # open annotation window
        self.keyPress(Qt.Key_A)
        self.assertIsNotNone(self.window.GetModule("AnnotationHandler").AnnotationEditorWindow, "Annotation window was not opened")

        # add text
        annotationWindow = self.window.GetModule("AnnotationHandler").AnnotationEditorWindow
        annotationWindow.pteAnnotation.setPlainText("A bird attacks.")
        QTest.mouseClick(annotationWindow.pbConfirm, Qt.LeftButton)

        # jump 10 frames
        self.window.JumpFrames(10)
        self.wait_for_image_load()

        # add an annotation
        self.keyPress(Qt.Key_A)
        annotationWindow = self.window.GetModule("AnnotationHandler").AnnotationEditorWindow
        annotationWindow.pteAnnotation.setPlainText("A bird attacks.")
        QTest.mouseClick(annotationWindow.pbConfirm, Qt.LeftButton)

        # jump back to the first annotation
        self.keyPress(Qt.Key_Left, Qt.ControlModifier)
        self.wait_for_image_load()
        self.assertEqual(self.window.target_frame, 0, "Didn't jump to annotation in frame 1 in Ctrl+Left")

        # jump to the second annotation
        self.keyPress(Qt.Key_Right, Qt.ControlModifier)
        self.wait_for_image_load()
        self.assertEqual(self.window.target_frame, 10, "Didn't jump to annotation in frame 10 in Ctrl+Right")
Esempio n. 15
0
    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()))
Esempio n. 16
0
    def test_select_all(self):
        w = ConsoleWidget()
        w._append_plain_text('Header\n')
        w._prompt = 'prompt>'
        w._show_prompt()
        control = w._control
        app = QtWidgets.QApplication.instance()

        cursor = w._get_cursor()
        w._insert_plain_text_into_buffer(cursor, "if:\n    pass")

        cursor.clearSelection()
        control.setTextCursor(cursor)

        # "select all" action selects cell first
        w.select_all_smart()
        QTest.keyClick(control, QtCore.Qt.Key_C, QtCore.Qt.ControlModifier)
        copied = app.clipboard().text()
        self.assertEqual(copied,  'if:\n>     pass')

        # # "select all" action triggered a second time selects whole document
        w.select_all_smart()
        QTest.keyClick(control, QtCore.Qt.Key_C, QtCore.Qt.ControlModifier)
        copied = app.clipboard().text()
        self.assertEqual(copied,  'Header\nprompt>if:\n>     pass')
Esempio n. 17
0
    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.assertEqual(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.assertEqual(plots_selected_old, plots_selected_new)
Esempio n. 18
0
 def test_run_dialog_opens_on_return_press(self):
     with patch(createDialogFromName_func_name) as createDialog:
         widget = AlgorithmSelectorWidget()
         self._select_in_tree(widget, 'DoStuff v.2')
         QTest.keyClick(widget.search_box, Qt.Key_Return)
         createDialog.assert_called_once_with('DoStuff', 2, None, False, {},
                                              '', [])
Esempio n. 19
0
    def test_cut(self):
        data = self.fillTable(10)

        # no selection
        QTest.mouseClick(self.view.cut, Qt.LeftButton)
        self.assertEqual(self.model.samples, data)

        # 1 row
        self.selectRow(0, Qt.NoModifier)
        QTest.mouseClick(self.view.cut, Qt.LeftButton)
        data[0] = {}
        self.assertEqual(self.model.samples, data)

        # several rows
        self.selectRow(0, Qt.NoModifier)
        self.selectRow(2, Qt.ControlModifier)
        QTest.mouseClick(self.view.cut, Qt.LeftButton)
        data[0] = {}
        data[2] = {}
        self.assertEqual(self.model.samples, data)
        self.selectRow(3, Qt.NoModifier)
        self.selectRow(5, Qt.ShiftModifier)
        QTest.mouseClick(self.view.cut, Qt.LeftButton)
        data[3] = {}
        data[4] = {}
        data[5] = {}
        self.assertEqual(self.model.samples, data)

        # cells
        self.selectCell(6, 0, Qt.NoModifier)
        self.selectCell(6, 1, Qt.ControlModifier)
        QTest.mouseClick(self.view.cut, Qt.LeftButton)
        del data[6][self.view.columns[0]]
        del data[6][self.view.columns[1]]
        self.assertEqual(self.model.samples, data)
Esempio n. 20
0
    def test_load_data(self):
        import glob
        make_decay_button = self.form.tcspc_setup_widget.pushButton

        self.assertEqual(
            len(
                self.form.curve_selector.get_data_sets()
            ),
            0
        )

        spcFileWidget = self.form.tcspc_setup_widget.spcFileWidget
        filenames = glob.glob("./test/data/tttr/BH/132/*.spc")
        file_type = "bh132"
        spcFileWidget.onLoadSample(
            event=None,
            filenames=filenames,
            file_type=file_type
        )
        QTest.mouseClick(make_decay_button, Qt.LeftButton)

        self.assertEqual(
            len(
                self.form.curve_selector.get_data_sets()
            ),
            1
        )
        print(
            self.form.curve_selector.get_data_sets()
        )
Esempio n. 21
0
 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
Esempio n. 22
0
 def tearDown(self):
     # close window
     QTest.qWait(100)
     if "window" in dir(self):
         self.window.data_file.exists = True  # to prevent the "do you want to save" window
         self.window.close()
         QTest.qWait(100)
         self.window.data_file.db.close()
Esempio n. 23
0
 def test_execute_on_return_press(self):
     with patch(
             'mantidqt.interfacemanager.InterfaceManager.createDialogFromName'
     ) as createDialog:
         widget = AlgorithmSelectorWidget()
         self._select_in_tree(widget, 'DoStuff v.2')
         QTest.keyClick(widget.search_box, Qt.Key_Return)
         createDialog.assert_called_once_with('DoStuff', 2)
Esempio n. 24
0
 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()
Esempio n. 25
0
    def test_buttonpress(self):
        from natcap.ui.inputs import InfoButton
        button = InfoButton('some text')
        self.assertEqual(button.whatsThis(), 'some text')

        # Execute this, for coverage.
        button.show()
        QTest.mouseClick(button, QtCore.Qt.LeftButton)
Esempio n. 26
0
    def test_calculation_1(self):
        okWidget = self.form.pushButton
        QTest.mouseClick(okWidget, Qt.LeftButton)

        self.assertAlmostEqual(self.form.doubleSpinBox_10.value(), 0.7545, places=2)
        self.assertAlmostEqual(self.form.doubleSpinBox_9.value(), 0.1907, places=2)
        self.assertAlmostEqual(self.form.doubleSpinBox_6.value(), 1.0164, places=2)
        self.assertAlmostEqual(self.form.doubleSpinBox_8.value(), 0.0424, places=2)
    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())
 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)
Esempio n. 29
0
 def test_ui_increase_maximum(self):
     low, high = self.stretch.values()
     maximum = self.stretch.maximum()
     delta = 1000 * max(abs(maximum), 1)
     value = maximum + delta
     QTest.keyClicks(self.stretch.maxSpinBox, str(value))
     self.assertEqual(self.stretch.maximum(), value)
     self.assertEqual(low, self.stretch.low())
     self.assertEqual(high, self.stretch.high())
Esempio n. 30
0
 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()
Esempio n. 31
0
 def test_ui_decrease_maximum_below_high(self):
     low, high = self.stretch.values()
     maximum = 0.5 * (low + high)
     self.assertGreater(maximum, low)
     self.assertLess(maximum, high)
     QTest.keyClicks(self.stretch.maxSpinBox, str(maximum))
     self.assertEqual(self.stretch.maximum(), maximum)
     self.assertEqual(low, self.stretch.low())
     self.assertEqual(self.stretch.high(), maximum)
Esempio n. 32
0
 def test_ui_increase_minimum_above_low(self):
     low, high = self.stretch.values()
     minimum = 0.5 * (low + high)
     self.assertGreater(minimum, low)
     self.assertLess(minimum, high)
     QTest.keyClicks(self.stretch.minSpinBox, str(minimum))
     self.assertEqual(self.stretch.minimum(), minimum)
     self.assertEqual(self.stretch.low(), minimum)
     self.assertEqual(high, self.stretch.high())
Esempio n. 33
0
 def test_ui_increase_minimum(self):
     low, high = self.stretch.values()
     minimum = self.stretch.minimum()
     delta = low - minimum
     value = minimum + delta / 2
     QTest.keyClicks(self.stretch.minSpinBox, str(value))
     self.assertEqual(self.stretch.minimum(), value)
     self.assertEqual(low, self.stretch.low())
     self.assertEqual(high, self.stretch.high())
Esempio n. 34
0
 def test_ui_decrease_maximum(self):
     low, high = self.stretch.values()
     maximum = self.stretch.maximum()
     delta = maximum - high
     value = maximum + delta / 2
     QTest.keyClicks(self.stretch.maxSpinBox, str(value))
     self.assertEqual(self.stretch.maximum(), value)
     self.assertEqual(low, self.stretch.low())
     self.assertEqual(high, self.stretch.high())
Esempio n. 35
0
 def test(self):
     window = MainWindow()
     window.show()
     QTest.qWaitForWindowActive(window)
     _click_area(window.button)
     # QTest.mouseClick(window.button, QtCore.Qt.LeftButton)
     QTest.qWait(5000)
     window.overlay.hide()
     window.close()
Esempio n. 36
0
    def selectRow(self, row, modifier):
        # find the middle of the row header
        vertical_header = self.table.verticalHeader()
        x = 0 + vertical_header.length() / 2
        y = vertical_header.sectionPosition(row) \
            + vertical_header.sectionSize(row) / 2

        QTest.mouseClick(vertical_header.viewport(), Qt.LeftButton, modifier,
                         QPoint(x, y))
Esempio n. 37
0
    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())
Esempio n. 38
0
    def selectCell(self, row, column, modifier):
        # find the middle of the cell
        y = self.table.rowViewportPosition(row) \
            + self.table.rowHeight(row) / 2
        x = self.table.columnViewportPosition(column) \
            + self.table.columnWidth(column) / 2

        QTest.mouseClick(self.table.viewport(), Qt.LeftButton, modifier,
                         QPoint(x, y))
Esempio n. 39
0
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)
    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')))
    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)
    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())
    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)
    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)
    def test_shift_cake_azimuth(self):
        shift = 300
        QTest.mouseClick(self.widget.img_mode_btn, QtCore.Qt.LeftButton)
        self.assertEqual(self.widget.cake_shift_azimuth_sl.minimum(), -len(self.model.cake_azi) / 2)
        self.assertEqual(self.widget.cake_shift_azimuth_sl.maximum(), len(self.model.cake_azi) / 2)
        self.assertEqual(self.widget.cake_shift_azimuth_sl.singleStep(), 1)
        self.assertEqual(self.widget.cake_shift_azimuth_sl.value(), 0)
        old_cake_data = np.copy(self.model.cake_data)
        self.widget.cake_shift_azimuth_sl.setValue(shift)

        self.assertEqual(self.widget.cake_shift_azimuth_sl.value(), shift)

        displayed_cake_data = self.widget.img_widget.img_data
        self.assertFalse(np.array_equal(displayed_cake_data, old_cake_data))
        self.assertFalse(np.array_equal(displayed_cake_data[0], old_cake_data[0]))
        self.assertTrue(np.array_equal(displayed_cake_data[shift], old_cake_data[0]))
Esempio n. 46
0
def drag_mouse(widget, from_pos, to_pos):
    QTest.mousePress(widget, Qt.LeftButton, Qt.NoModifier, from_pos)
    yield
    QTest.mouseMove(widget, from_pos)
    yield 0.1
    QTest.mouseMove(widget, to_pos)
    yield 0.1
    QTest.mouseRelease(widget, Qt.LeftButton, Qt.NoModifier, to_pos)
    yield 0.1
    def test_saving_pattern(self):
        # the widget has to be shown to be able to save the image:
        self.integration_widget.show()

        # Tests if the pattern save procedures is are working for all file-endings
        def save_test_for_size_and_delete(self):

            def save_pattern(filename):
                QtWidgets.QFileDialog.getSaveFileName = MagicMock(return_value=filename)
                click_button(self.integration_widget.qa_save_pattern_btn)

            save_pattern(os.path.join(data_path, 'Test_spec.xy'))
            save_pattern(os.path.join(data_path, 'Test_spec.chi'))
            save_pattern(os.path.join(data_path, 'Test_spec.dat'))
            save_pattern(os.path.join(data_path, 'Test_spec.png'))
            save_pattern(os.path.join(data_path, 'Test_spec.svg'))

            self.assertTrue(os.path.exists(os.path.join(data_path, 'Test_spec.xy')))
            self.assertTrue(os.path.exists(os.path.join(data_path, 'Test_spec.chi')))
            self.assertTrue(os.path.exists(os.path.join(data_path, 'Test_spec.dat')))
            self.assertTrue(os.path.exists(os.path.join(data_path, 'Test_spec.png')))
            self.assertTrue(os.path.exists(os.path.join(data_path, 'Test_spec.svg')))

            self.assertGreater(os.stat(os.path.join(data_path, 'Test_spec.xy')).st_size, 1)
            self.assertGreater(os.stat(os.path.join(data_path, 'Test_spec.chi')).st_size, 1)
            self.assertGreater(os.stat(os.path.join(data_path, 'Test_spec.dat')).st_size, 1)
            self.assertGreater(os.stat(os.path.join(data_path, 'Test_spec.png')).st_size, 1)
            self.assertGreater(os.stat(os.path.join(data_path, 'Test_spec.svg')).st_size, 1)

            os.remove(os.path.join(data_path, 'Test_spec.xy'))
            os.remove(os.path.join(data_path, 'Test_spec.chi'))
            os.remove(os.path.join(data_path, 'Test_spec.dat'))
            os.remove(os.path.join(data_path, 'Test_spec.png'))
            os.remove(os.path.join(data_path, 'Test_spec.svg'))

        save_test_for_size_and_delete(self)
        QTest.mouseClick(self.integration_pattern_controller.widget.pattern_q_btn, QtCore.Qt.LeftButton)
        save_test_for_size_and_delete(self)
        QTest.mouseClick(self.integration_pattern_controller.widget.pattern_d_btn, QtCore.Qt.LeftButton)
        save_test_for_size_and_delete(self)
Esempio n. 48
0
def mouse_click(widget, pos, button=Qt.LeftButton):
    QTest.mouseMove(widget, pos)
    yield
    QTest.mousePress(widget, button, Qt.NoModifier, pos)
    yield
    QTest.mouseRelease(widget, button, Qt.NoModifier, pos)
    yield 0.1
Esempio n. 49
0
 def view_set_parameter(self, param_name, value):
     view = self.widget.view()
     rect = view.getVisualRectParameterProperty(param_name)
     pos = rect.center()
     if self.is_multi:
         pos -= QPoint(rect.width() / 5, 0)
     else:
         pos += QPoint(rect.width() / 4, 0)
     tree = view.treeWidget().viewport()
     QTest.mouseMove(tree, pos)
     yield
     QTest.mouseClick(tree, Qt.LeftButton, Qt.NoModifier, pos)
     yield
     editor = QApplication.focusWidget()
     QTest.keyClicks(editor, str(value))
     QTest.keyClick(editor, Qt.Key_Return)
Esempio n. 50
0
 def mouse_trigger_action(self, name, pause=0):
     menu = self.get_active_popup_widget()
     a, m = self.get_action(name, get_menu=True)
     pos = menu.actionGeometry(a).center()
     QTest.mouseMove(menu, pos)
     yield pause
     self.hover_action(name)
     QTest.mousePress(menu, Qt.LeftButton, Qt.NoModifier, pos)
     yield pause
     QTest.mouseRelease(menu, Qt.LeftButton, Qt.NoModifier, pos)
    def test_high_pressure_values_are_shown_in_jcpds_editor(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

        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.phase_controller.widget.phase_tw.selectRow(0)
        QTest.mouseClick(self.phase_controller.widget.phase_edit_btn, QtCore.Qt.LeftButton)
        QtWidgets.QApplication.processEvents()

        # he looks at the jcpds_editor and sees that there are not only hkl and intensity values for each reflection but
        # also d0, d, two_theta0 and two_theta
        # however, the zero values and non-zero values are all the same

        self.assertEqual(8, self.jcpds_widget.reflection_table.columnCount())
        for row_ind in range(13):
            self.assertEqual(self.get_reflection_table_value(row_ind, 4), self.get_reflection_table_value(row_ind, 6))
            self.assertAlmostEqual(self.get_reflection_table_value(row_ind, 5),
                                   self.convert_d_to_twotheta(self.jcpds_phase.reflections[row_ind].d0, 0.31),
                                   delta=0.0001)
            self.assertEqual(self.get_reflection_table_value(row_ind, 5), self.get_reflection_table_value(row_ind, 7))

        # he further realizes that there are two sets of lattice parameters in the display, but both still show the same
        # values...

        self.assertEqual(float(self.jcpds_widget.lattice_eos_a_txt.text()), self.jcpds_widget.lattice_a_sb.value())
        self.assertEqual(float(self.jcpds_widget.lattice_eos_b_txt.text()), self.jcpds_widget.lattice_b_sb.value())
        self.assertEqual(float(self.jcpds_widget.lattice_eos_c_txt.text()), self.jcpds_widget.lattice_c_sb.value())
        self.assertEqual(float(self.jcpds_widget.lattice_eos_volume_txt.text()),
                         float(self.jcpds_widget.lattice_volume_txt.text()))

        # then he decides to increase pressure in the main_view and sees that the non "0" values resemble the high pressure
        # values

        self.phase_controller.widget.phase_pressure_sb.setValue(30)
        for row_ind in range(13):
            self.assertNotEqual(self.get_reflection_table_value(row_ind, 4),
                                self.get_reflection_table_value(row_ind, 5))
            self.assertNotAlmostEqual(self.get_reflection_table_value(row_ind, 6),
                                      self.convert_d_to_twotheta(self.jcpds_phase.reflections[row_ind].d0, 0.31),
                                      delta=0.0001)
            self.assertNotEqual(self.get_reflection_table_value(row_ind, 6),
                                self.get_reflection_table_value(row_ind, 7))

        self.assertNotEqual(float(self.jcpds_widget.lattice_eos_a_txt.text()), self.jcpds_widget.lattice_a_sb.value())
        self.assertNotEqual(float(self.jcpds_widget.lattice_eos_b_txt.text()), self.jcpds_widget.lattice_b_sb.value())
        self.assertNotEqual(float(self.jcpds_widget.lattice_eos_c_txt.text()), self.jcpds_widget.lattice_c_sb.value())
        self.assertNotEqual(float(self.jcpds_widget.lattice_eos_volume_txt.text()),
                            float(self.jcpds_widget.lattice_volume_txt.text()))
    def test_connection_between_main_gui_and_jcpds_editor_reflections(self):
        # Erwin loads Dioptas with a previous calibration and image file then he adds several phases and looks into the
        # jcpds editor for the first phase. He sees that everything seems to be correct

        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'),
                                                            os.path.join(jcpds_path, 'mo.jcpds'),
                                                            os.path.join(jcpds_path, 'ar.jcpds'),
                                                            os.path.join(jcpds_path, 're.jcpds')])

        self.phase_controller = self.main_controller.integration_controller.phase_controller
        click_button(self.phase_controller.widget.phase_add_btn)

        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.phase_controller.widget.phase_tw.selectRow(0)
        QTest.mouseClick(self.phase_controller.widget.phase_edit_btn, QtCore.Qt.LeftButton)
        QtWidgets.QApplication.processEvents()

        self.assertEqual(self.jcpds_widget.reflection_table.rowCount(), 13)
        self.assertEqual(len(self.jcpds_phase.reflections), 13)
        self.assertEqual(len(self.jcpds_in_spec.line_items), 13)
        self.assertEqual(len(self.jcpds_in_spec.line_visible), 13)

        # then he decides to add another reflection to the jcpds file and sees that after changing the parameters it is
        # miraculously connected to the view

        # adding the reflection
        QTest.mouseClick(self.jcpds_widget.reflections_add_btn, QtCore.Qt.LeftButton)

        self.assertEqual(self.jcpds_widget.reflection_table.rowCount(), 14)
        self.assertEqual(len(self.jcpds_phase.reflections), 14)
        self.assertEqual(len(self.jcpds_in_spec.line_items), 14)
        self.assertEqual(len(self.jcpds_in_spec.line_visible), 14)

        # putting reasonable values into the reflection
        self.insert_reflection_table_value(13, 0, 1)
        self.insert_reflection_table_value(13, 3, 90)
        self.assertAlmostEqual(self.get_phase_line_position(0, 13), self.convert_d_to_twotheta(4.0786, 0.31),
                               delta=0.0005)

        # he looks through the reflection and sees that one is actually forbidden. Who has added this reflection to the
        # file? He decides to delete it

        self.jcpds_widget.reflection_table.selectRow(5)

        QTest.mouseClick(self.jcpds_widget.reflections_delete_btn, QtCore.Qt.LeftButton)

        self.assertEqual(self.jcpds_widget.reflection_table.rowCount(), 13)
        self.assertEqual(len(self.jcpds_phase.reflections), 13)
        self.assertEqual(len(self.jcpds_in_spec.line_items), 13)
        self.assertEqual(len(self.jcpds_in_spec.line_visible), 13)

        # then he looks again at all reflection and does not like it so he decides to clear all of them and build them
        # up from sketch...

        QTest.mouseClick(self.jcpds_widget.reflections_clear_btn, QtCore.Qt.LeftButton)
        self.assertEqual(self.jcpds_widget.reflection_table.rowCount(), 0)
        self.assertEqual(len(self.jcpds_phase.reflections), 0)
        self.assertEqual(len(self.jcpds_in_spec.line_items), 0)
        self.assertEqual(len(self.jcpds_in_spec.line_visible), 0)

        # He adds some lines and sees the values change:

        QTest.mouseClick(self.jcpds_widget.reflections_add_btn, QtCore.Qt.LeftButton)
        QTest.mouseClick(self.jcpds_widget.reflections_add_btn, QtCore.Qt.LeftButton)
        QTest.mouseClick(self.jcpds_widget.reflections_add_btn, QtCore.Qt.LeftButton)
        QTest.mouseClick(self.jcpds_widget.reflections_add_btn, QtCore.Qt.LeftButton)

        self.assertEqual(self.jcpds_widget.reflection_table.rowCount(), 4)
        self.assertEqual(len(self.jcpds_phase.reflections), 4)
        self.assertEqual(len(self.jcpds_in_spec.line_items), 4)
        self.assertEqual(len(self.jcpds_in_spec.line_visible), 4)
    def test_connection_between_main_gui_and_jcpds_editor_lattice_and_eos_parameter(self):
        # Erwin opens up the program, loads image and calibration and some phases

        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'),
                                                            os.path.join(jcpds_path, 'mo.jcpds'),
                                                            os.path.join(jcpds_path, 'ar.jcpds'),
                                                            os.path.join(jcpds_path, 're.jcpds')])

        self.phase_controller = self.main_controller.integration_controller.phase_controller
        click_button(self.phase_controller.widget.phase_add_btn)

        self.jcpds_editor_controller = self.phase_controller.jcpds_editor_controller
        self.jcpds_widget = self.jcpds_editor_controller.widget

        self.phase_controller.widget.phase_tw.selectRow(0)
        QTest.mouseClick(self.phase_controller.widget.phase_edit_btn, QtCore.Qt.LeftButton)
        QtWidgets.QApplication.processEvents()

        # He changes some parameter but then realizes that he screwed it up and presses cancel to revert all his changes

        self.enter_value_into_spinbox(self.jcpds_widget.lattice_a_sb, 10.4)

        self.assertAlmostEqual(self.phase_controller.model.phase_model.phases[0].params['a0'], 10.4)
        QTest.mouseClick(self.jcpds_widget.cancel_btn, QtCore.Qt.LeftButton)

        self.assertNotAlmostEqual(self.phase_controller.model.phase_model.phases[0].params['a0'], 10.4)

        # Now he selects one phase in the phase table and starts the JCPDS editor and realizes he wanted to click another
        # phase --  so he just selects it without closing and reopening the editor
        # and magically the new parameters show up

        self.phase_controller.widget.phase_tw.selectRow(1)
        QTest.mouseClick(self.phase_controller.widget.phase_edit_btn, QtCore.Qt.LeftButton)
        QtWidgets.QApplication.processEvents()

        self.phase_controller.widget.phase_tw.selectRow(2)
        self.assertTrue(float(str(self.jcpds_widget.lattice_a_sb.text()).replace(',', '.')),
                        5.51280)  # Argon lattice parameter

        # Now he changes the lattice parameter and wants to see if there is any change in the line position in the graph

        prev_line_pos = self.get_phase_line_position(2, 0)
        self.enter_value_into_spinbox(self.jcpds_widget.lattice_a_sb, 3.4)
        QtWidgets.QApplication.processEvents()
        prev_line_pos = self.compare_line_position(prev_line_pos, 2, 0)

        # now he decides to have full control, changes the structure to TRICLINIC and plays with all parameters:

        self.set_symmetry('triclinic')

        self.enter_value_into_spinbox(self.jcpds_widget.lattice_b_sb, 3.2)
        prev_line_pos = self.compare_line_position(prev_line_pos, 2, 0)

        self.enter_value_into_spinbox(self.jcpds_widget.lattice_c_sb, 3.1)
        prev_line_pos = self.compare_line_position(prev_line_pos, 2, 0)

        self.enter_value_into_spinbox(self.jcpds_widget.lattice_ab_sb, 1.6)
        prev_line_pos = self.compare_line_position(prev_line_pos, 2, 0)

        self.enter_value_into_spinbox(self.jcpds_widget.lattice_ca_sb, 1.9)
        prev_line_pos = self.compare_line_position(prev_line_pos, 2, 0)

        self.enter_value_into_spinbox(self.jcpds_widget.lattice_ab_sb, 0.3)
        prev_line_pos = self.compare_line_position(prev_line_pos, 2, 0)

        self.enter_value_into_spinbox(self.jcpds_widget.lattice_alpha_sb, 70)
        prev_line_pos = self.compare_line_position(prev_line_pos, 2, 0)

        self.enter_value_into_spinbox(self.jcpds_widget.lattice_beta_sb, 70)
        prev_line_pos = self.compare_line_position(prev_line_pos, 2, 0)

        self.enter_value_into_spinbox(self.jcpds_widget.lattice_gamma_sb, 70)
        prev_line_pos = self.compare_line_position(prev_line_pos, 2, 0)

        # then he increases the pressure and sees the line moving, but he realizes that the equation of state may 
        # be wrong so he decides to change the parameters in the jcpds-editor
        self.main_controller.integration_controller.widget.phase_pressure_sb.setValue(10)
        prev_line_pos = self.compare_line_position(prev_line_pos, 2, 0)

        self.enter_value_into_text_field(self.jcpds_widget.eos_K_txt, 120)
        prev_line_pos = self.compare_line_position(prev_line_pos, 2, 0)

        self.enter_value_into_text_field(self.jcpds_widget.eos_Kp_txt, 6)
        prev_line_pos = self.compare_line_position(prev_line_pos, 2, 0)

        # he decides to change temperature value and play with all equation of state parameters
        self.enter_value_into_text_field(self.jcpds_widget.eos_alphaT_txt, 6.234e-5)
        self.assertEqual(self.phase_controller.model.phase_model.phases[2].params['alpha_t0'], 6.234e-5)

        self.main_controller.integration_controller.widget.phase_temperature_sb.setValue(1300)
        prev_line_pos = self.compare_line_position(prev_line_pos, 2, 0)

        self.enter_value_into_text_field(self.jcpds_widget.eos_alphaT_txt, 10.234e-5)
        prev_line_pos = self.compare_line_position(prev_line_pos, 2, 0)

        self.enter_value_into_text_field(self.jcpds_widget.eos_dalphadT_txt, 10.234e-6)
        prev_line_pos = self.compare_line_position(prev_line_pos, 2, 0)

        self.enter_value_into_text_field(self.jcpds_widget.eos_dKdT_txt, 1.2e-4)
        prev_line_pos = self.compare_line_position(prev_line_pos, 2, 0)

        self.enter_value_into_text_field(self.jcpds_widget.eos_dKpdT_txt, 1.3e-6)
        prev_line_pos = self.compare_line_position(prev_line_pos, 2, 0)
def click_button(widget):
    QTest.mouseClick(widget, QtCore.Qt.LeftButton)
Esempio n. 55
0
 def test_empty_removal_does_nothing(self):
     """ Make sure widgets are only removed when selected """
     layer = self.add_layer()
     self.widget.ui.layerTree.clearSelection()
     QTest.mouseClick(self.widget.ui.layerRemoveButton, Qt.LeftButton)
     assert self.layer_present(layer)
def enter_value_into_text_field(text_field, value):
    text_field.setText('')
    QTest.keyClicks(text_field, str(value))
    QTest.keyPress(text_field, QtCore.Qt.Key_Enter)
    QtWidgets.QApplication.processEvents()
Esempio n. 57
0
 def remove_layer(self, layer):
     """ Remove a layer via the widget remove button """
     self.select_layers(layer)
     QTest.mouseClick(self.widget.ui.layerRemoveButton, Qt.LeftButton)
Esempio n. 58
0
def click_on(widget, pos, pause=0):
    QTest.mouseMove(widget, pos)
    yield pause
    QTest.mouseClick(widget, Qt.LeftButton, Qt.NoModifier, pos)
    yield pause
Esempio n. 59
0
def click_checkbox(checkbox_widget):
    QTest.mouseClick(checkbox_widget, QtCore.Qt.LeftButton,
                     pos=QtCore.QPoint(2, checkbox_widget.height() / 2.0))