示例#1
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)
示例#2
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()))
示例#3
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()
        )
    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_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)
示例#6
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)
    def test_edit_reflection(self):
        col = 0
        row = 1

        previous_d0 = self.phase_model.phases[5].reflections[1].d

        # get x,y position for the cell
        x_pos = self.jcpds_widget.reflection_table_view.columnViewportPosition(col) + 3
        y_pos = self.jcpds_widget.reflection_table_view.rowViewportPosition(row) + 10

        # click then doubleclick  the cell
        self.assertTrue(self.jcpds_widget.reflection_table_view.isVisible())
        viewport = self.jcpds_widget.reflection_table_view.viewport()
        QTest.mouseClick(viewport, QtCore.Qt.LeftButton, pos=QtCore.QPoint(x_pos, y_pos))
        QTest.mouseDClick(viewport, QtCore.Qt.LeftButton, pos=QtCore.QPoint(x_pos, y_pos))

        # type in the new number
        QTest.keyClicks(viewport.focusWidget(), "3")
        QTest.keyPress(viewport.focusWidget(), QtCore.Qt.Key_Enter)
        QtWidgets.QApplication.processEvents()

        self.assertEqual(self.phase_model.phases[5].reflections[1].h, 3)
        print(self.phase_model.phases[5].reflections[1].d)
        self.assertNotEqual(self.phase_model.phases[5].reflections[1].d,
                            previous_d0)
    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)
 def _edit_line_edit(self, key_entry):
     QTest.mouseClick(self.line_edit, Qt.LeftButton)
     self.line_edit.selectAll()
     QTest.keyClick(self.line_edit, Qt.Key_Backspace)
     QTest.keyClicks(self.line_edit, key_entry)
     QTest.keyClick(self.line_edit, Qt.Key_Enter)
     QApplication.sendPostedEvents()
    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)
    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)
示例#12
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 v1']
     }
     visualSettings.update(RundexSettings.VISUAL_SETTINGS["SANS v1"])
     json = {
         'Instrument':
         'D11',
         'AcquisitionMode':
         'SANS v1',
         'VisualSettings':
         visualSettings,
         'GlobalSettings':
         {p.getName(): p.getValue()
          for p in self.model.getParameters()},
         'ExportAlgorithms': [
             algo
             for algo in RundexSettings.EXPORT_ALGORITHMS['SANS v1'].keys()
             if RundexSettings.EXPORT_ALGORITHMS['SANS v1'][algo]
         ]
     }
     self.assertDictEqual(json, mJson.dump.call_args[0][0])
示例#13
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()))
示例#14
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_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)
示例#16
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)
示例#17
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()
示例#18
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
示例#19
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)
示例#20
0
    def test_grow_and_shrinking(self):
        self.model.mask_model.mask_ellipse(100, 100, 20, 20)
        previous_mask = np.copy(self.model.mask_model._mask_data)

        QTest.mouseClick(self.mask_widget.grow_btn, QtCore.Qt.LeftButton)
        self.assertFalse(np.array_equal(previous_mask, self.model.mask_model._mask_data))

        QTest.mouseClick(self.mask_widget.shrink_btn, QtCore.Qt.LeftButton)
        self.assertTrue(np.array_equal(previous_mask, self.model.mask_model._mask_data))
    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())
示例#22
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())
示例#23
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))
示例#24
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))
示例#25
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()
    def _select_table_cell(self, row, column):
        x = int(
            self.view.correction_options_table.columnViewportPosition(column) +
            self.view.correction_options_table.columnWidth(column) / 2)
        y = int(
            self.view.correction_options_table.rowViewportPosition(row) +
            self.view.correction_options_table.rowHeight(row) / 2)

        QTest.mouseClick(self.view.correction_options_table.viewport(),
                         Qt.LeftButton, Qt.NoModifier, QPoint(x, y))
示例#27
0
 def test_loading_and_saving_of_calibration_files(self):
     self.mock_integrate_functions()
     QtWidgets.QFileDialog.getOpenFileName = MagicMock(
         return_value=os.path.join(unittest_data_path, 'LaB6_40keV_MarCCD.poni'))
     QTest.mouseClick(self.widget.load_calibration_btn, QtCore.Qt.LeftButton)
     QtWidgets.QFileDialog.getSaveFileName = MagicMock(
         return_value=os.path.join(unittest_data_path, 'calibration.poni'))
     QTest.mouseClick(self.widget.save_calibration_btn, QtCore.Qt.LeftButton)
     self.assertTrue(os.path.exists(os.path.join(unittest_data_path, 'calibration.poni')))
     os.remove(os.path.join(unittest_data_path, 'calibration.poni'))
    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)
示例#29
0
    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)
示例#30
0
    def test_calculation_2(self):
        check_box = self.form.checkBox
        check_box.setCheckState(True)

        okWidget = self.form.pushButton
        QTest.mouseClick(okWidget, Qt.LeftButton)

        self.assertAlmostEqual(self.form.doubleSpinBox_10.value(), 0.6605, places=2)
        self.assertAlmostEqual(self.form.doubleSpinBox_9.value(), 0.1398, places=2)
        self.assertAlmostEqual(self.form.doubleSpinBox_6.value(), 0.9951, places=2)
        self.assertAlmostEqual(self.form.doubleSpinBox_8.value(), 0.0363, places=2)
    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)
示例#32
0
    def test_setting_overlay_as_bkg_and_changing_offset(self):
        self.load_overlays()
        self.model.pattern_model.load_pattern(
            os.path.join(data_path, 'pattern_001.xy'))
        self.widget.select_overlay(0)
        QTest.mouseClick(self.widget.overlay_set_as_bkg_btn,
                         QtCore.Qt.LeftButton)

        self.widget.overlay_offset_sb.setValue(100)
        _, y = self.model.pattern.data
        self.assertEqual(np.sum(y), -100 * y.size)
示例#33
0
    def test_setting_pattern_as_bkg(self):
        self.model.pattern_model.load_pattern(
            os.path.join(data_path, 'pattern_001.xy'))
        QTest.mouseClick(self.widget.qa_set_as_background_btn,
                         QtCore.Qt.LeftButton)
        QtWidgets.QApplication.processEvents()

        self.assertTrue(self.widget.overlay_set_as_bkg_btn.isChecked())

        _, y = self.model.pattern.data
        self.assertEqual(np.sum(y), 0)
    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')))
示例#35
0
 def test_calibrant_with_small_set_of_d_spacings(self):
     self.mock_integrate_functions()
     QtWidgets.QFileDialog.getOpenFileName = MagicMock(
         return_value=os.path.join(unittest_data_path, 'LaB6_40keV_MarCCD.tif'))
     QTest.mouseClick(self.widget.load_img_btn, QtCore.Qt.LeftButton)
     self.controller.search_peaks(1179.6, 1129.4)
     self.controller.search_peaks(1268.5, 1119.8)
     calibrant_index = self.widget.calibrant_cb.findText('CuO')
     self.controller.widget.calibrant_cb.setCurrentIndex(calibrant_index)
     QtWidgets.QMessageBox.critical = MagicMock()
     click_button(self.widget.calibrate_btn)
     QtWidgets.QMessageBox.critical.assert_called_once()
    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_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())
示例#38
0
    def test_overlay_waterfall(self):
        self.load_overlays()
        self.widget.waterfall_separation_txt.setText("10")
        QTest.mouseClick(self.widget.waterfall_btn, QtCore.Qt.LeftButton)

        self.assertEqual(self.model.overlay_model.overlays[5].offset, -10)
        self.assertEqual(self.model.overlay_model.overlays[4].offset, -20)

        QTest.mouseClick(self.widget.reset_waterfall_btn, QtCore.Qt.LeftButton)

        self.assertEqual(self.model.overlay_model.overlays[5].offset, 0)
        self.assertEqual(self.model.overlay_model.overlays[5].offset, 0)
示例#39
0
    def test_run_noerror(self):
        form = FormTest.make_ui()
        form.run(target=lambda: None)
        form._thread.join()
        QT_APP.processEvents()

        # At the end of the run, the button should be visible.
        self.assertTrue(form.run_dialog.openWorkspaceButton.isVisible())

        # close the window by pressing the back button.
        QTest.mouseClick(form.run_dialog.backButton,
                         QtCore.Qt.LeftButton)
示例#40
0
    def test_droplist_completer_mousepick(self):
        leftButton = QtCore.Qt.LeftButton

        w = CompletionWidget(self.console)
        w.show_items(self.text_edit.textCursor(), ["item1", "item2", "item3"])

        QTest.mouseClick(w.viewport(), leftButton, pos=QtCore.QPoint(19, 8))
        QTest.mouseRelease(w.viewport(), leftButton, pos=QtCore.QPoint(19, 8))
        QTest.mouseDClick(w.viewport(), leftButton, pos=QtCore.QPoint(19, 8))

        self.assertEqual(self.text_edit.toPlainText(), "item1")
        self.assertFalse(w.isVisible())
    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]))
 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)
    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)
 def test_show_plot_by_pressing_show_button(self):
     QTest.mouseClick(self.view.show_button, Qt.LeftButton)
     self.assertEquals(self.presenter.show_multiple_selected.call_count, 1)
     QTest.mouseClick(self.view.show_button, Qt.LeftButton)
     self.assertEquals(self.presenter.show_multiple_selected.call_count, 2)
示例#46
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)
示例#47
0
def click_on(widget, pos, pause=0):
    QTest.mouseMove(widget, pos)
    yield pause
    QTest.mouseClick(widget, Qt.LeftButton, Qt.NoModifier, pos)
    yield pause
 def test_hide_button_pressed_calls_presenter(self):
     QTest.mouseClick(self.view.hide_button, Qt.LeftButton)
     self.assertEquals(self.presenter.hide_selected_plots.call_count, 1)
 def test_close_button_pressed_calls_presenter(self):
     QTest.mouseClick(self.view.close_button, Qt.LeftButton)
     self.assertEquals(self.presenter.close_action_called.call_count, 1)
     QTest.mouseClick(self.view.close_button, Qt.LeftButton)
     self.assertEquals(self.presenter.close_action_called.call_count, 2)
    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_undocking_and_docking_img_frame(self):
     QTest.mouseClick(self.integration_widget.img_dock_btn, QtCore.Qt.LeftButton)
     QTest.mouseClick(self.integration_widget.img_dock_btn, QtCore.Qt.LeftButton)
    def test_reflection_editing_and_saving_of_files(self):
        # Erwin has selected a gold jcpds in the Dioptas interface with cubic symmetry
        # and wants to look for the reflections entered
        self.jcpds = jcpds()
        self.jcpds.load_file(os.path.join(jcpds_path, 'au_Anderson.jcpds'))

        self.model.configurations[0].calibration_model.pattern_geometry.wavelength = 0.3344

        self.jcpds_controller = JcpdsEditorController(None, self.model, jcpds_phase=self.jcpds)
        self.jcpds_widget = self.jcpds_controller.widget

        # he sees that there are 13 reflections predefined in the table

        self.assertEqual(self.jcpds_widget.reflection_table.rowCount(), 13)

        # he checks if the values are correct:

        self.assertAlmostEqual(self.get_reflection_table_value(0, 4), 2.355, delta=0.001)
        self.assertEqual(self.get_reflection_table_value(1, 1), 0)
        self.assertAlmostEqual(self.get_reflection_table_value(12, 4), 0.6449, delta=0.0001)
        self.assertEqual(self.get_reflection_table_value(12, 3), 10)

        # then he decides to change the lattice parameter and sees that the values in the table are changing:
        self.enter_value_into_spinbox(self.jcpds_widget.lattice_a_sb, 4)
        self.assertEqual(self.jcpds_widget.reflection_table.rowCount(), 13)
        self.assertEqual(self.get_reflection_table_value(1, 4), 2)

        # After playing with the lattice parameter he sets it back to the original value and looks at the reflections
        # He thinks that he doesn't need the sixth reflection because it any way has to low intensity
        self.enter_value_into_spinbox(self.jcpds_widget.lattice_a_sb, 4.0786)
        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(), 12)
        self.assertAlmostEqual(self.get_reflection_table_value(5, 4), 0.9358, delta=0.0002)
        self.assertEqual(len(self.jcpds.reflections), 12)

        # then he changed his mind and wants to add the reflection back:

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

        self.assertEqual(len(self.jcpds.reflections), 13)
        self.assertEqual(self.jcpds_widget.reflection_table.rowCount(), 13)
        self.assertEqual(self.jcpds_widget.get_selected_reflections()[0], 12)

        self.assertEqual(self.get_reflection_table_value(12, 0), 0)  # h
        self.assertEqual(self.get_reflection_table_value(12, 1), 0)  # k
        self.assertEqual(self.get_reflection_table_value(12, 2), 0)  # l
        self.assertEqual(self.get_reflection_table_value(12, 3), 0)  # intensity
        self.assertEqual(self.get_reflection_table_value(12, 4), 0)  # d

        # then he edits he and realizes how the d spacings are magically calculated

        self.insert_reflection_table_value(12, 0, 1)
        self.assertEqual(self.get_reflection_table_value(12, 4), 4.0786)
        self.insert_reflection_table_value(12, 1, 1)
        self.assertAlmostEqual(self.get_reflection_table_value(12, 4),
                               calculate_cubic_d_spacing(1, 1, 0, 4.0786),
                               delta=0.0001)
        self.insert_reflection_table_value(12, 2, 3)
        self.assertAlmostEqual(self.get_reflection_table_value(12, 4),
                               calculate_cubic_d_spacing(1, 1, 3, 4.0786),
                               delta=0.0001)

        # then she decides that everybody should screw with the table and clears it:

        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.reflections), 0)
        self.assertEqual(len(self.jcpds_widget.get_selected_reflections()), 0)

        # he finds this phase much more promising and wants to give it a new name
        self.enter_value_into_text_field(self.jcpds_widget.comments_txt,
                                         'HAHA this is a phase you will never see in your pattern')
        self.assertEqual(self.jcpds.params['comments'][0], 'HAHA this is a phase you will never see in your pattern')

        # then he sees the save_as button and is happy to save his non-sense for later users
        filename = os.path.join(jcpds_path, 'au_mal_anders.jcpds')
        self.jcpds_controller.save_as_btn_clicked(filename)
        self.assertTrue(os.path.exists(filename))

        # he decides to change the lattice parameter and then reload the file to see if everything is ok
        self.enter_value_into_spinbox(self.jcpds_widget.lattice_a_sb, 10)

        self.jcpds.load_file(filename)
        self.jcpds_controller = JcpdsEditorController(None, dioptas_model=self.model,
                                                      jcpds_phase=self.jcpds)
        self.jcpds_widget = self.jcpds_controller.widget
        self.assertEqual(float(str(self.jcpds_widget.lattice_a_sb.text()).replace(',', '.')), 4.0786)
        self.assertEqual(float(str(self.jcpds_widget.lattice_b_sb.text()).replace(',', '.')), 4.0786)
        self.assertEqual(float(str(self.jcpds_widget.lattice_c_sb.text()).replace(',', '.')), 4.0786)

        # then he decides to make this phase it little bit more useful and adds some peaks and saves this as a different
        # version and trys to load it again...

        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.insert_reflection_table_value(0, 0, 1)
        self.insert_reflection_table_value(0, 3, 100)
        self.insert_reflection_table_value(1, 1, 1)
        self.insert_reflection_table_value(1, 3, 50)
        self.insert_reflection_table_value(2, 2, 1)
        self.insert_reflection_table_value(2, 3, 20)

        filename = os.path.join(jcpds_path, 'au_mal_anders_vers2.jcpds')
        self.jcpds_controller.save_as_btn_clicked(filename)

        self.jcpds.load_file(filename)
        self.jcpds_controller = JcpdsEditorController(None, self.model, jcpds_phase=self.jcpds)
示例#53
0
def click_checkbox(checkbox_widget):
    QTest.mouseClick(checkbox_widget, QtCore.Qt.LeftButton,
                     pos=QtCore.QPoint(2, checkbox_widget.height() / 2.0))
    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)
示例#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 click_button(widget):
    QTest.mouseClick(widget, QtCore.Qt.LeftButton)
 def click_to_select_by_row_number(self, row_number):
     widget = self.view.table_widget.cellWidget(row_number, Column.Name)
     QTest.mouseClick(widget, Qt.LeftButton)
 def test_switching_to_cake_mode_without_having_clicked_the_image_before(self):
     QTest.mouseClick(self.widget.img_mode_btn, QtCore.Qt.LeftButton)
     QTest.mouseClick(self.widget.img_mode_btn, QtCore.Qt.LeftButton)
    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()))