def test_directory_change(self): _rewrite_text(self.dialog.ui.comboBox_directory, os.path.abspath(self._temp_dir)) self.assertTrue( os.path.dirname(self.dialog.get_save_file_name()) == os.path.abspath(self._temp_dir)) # print self.dialog.get_save_file_name() # select from the browse self.dialog._dir_dialog.setDirectory( os.path.normpath(os.path.expanduser("~"))) self.dialog._dir_dialog.exec_ = _fake_exec_reject # path should not change _click_area(self.dialog.ui.pushButton_browse) self.assertTrue( os.path.dirname(self.dialog.get_save_file_name()) == os.path.abspath(self._temp_dir)) self.dialog._dir_dialog.exec_ = _fake_exec_accept _click_area(self.dialog.ui.pushButton_browse) # QTest.qWaitForWindowShown(self.dialog._dir_dialog) # self.dialog._dir_dialog.accept() self.assertTrue( os.path.dirname(os.path.normpath(self.dialog.get_save_file_name())) == os.path.normpath(os.path.expanduser("~")))
def test_github_issue_24(self): # this test recreate the bug reported in issue #24 on github # https://github.com/MTgeophysics/mtpy/issues/24 data_path = os.path.join(TEST_MTPY_ROOT, "examples/data/edi2") # load data under mtpy/examples/data/edi2 self._load_data([ os.path.join(data_path, edi) for edi in os.listdir(data_path) if edi.endswith("edi") ]) # select top 5 stations self._select_data(5) # switch to visualise _click_area(self.smartMT._station_viewer.ui.pushButton_plot ) # trigger plot widget self.assertTrue(self.smartMT.ui.stackedWidget.currentIndex() == 1) # select MT response visualisation index = [ i for i in range( self.smartMT._plot_option.ui.comboBoxSelect_Plot.count()) if self.smartMT._plot_option.ui.comboBoxSelect_Plot.itemText(i) == MTResponse.plot_name() ] self.assertFalse(len(index) == 0, "plot type not found") self.assertFalse(len(index) > 1, "plot type name is not unique") self.smartMT._plot_option.ui.comboBoxSelect_Plot.setCurrentIndex( index[0]) plot_config = self.smartMT._plot_option._current_plot self.assertTrue(isinstance(plot_config, MTResponse)) # click visualise to start self._plot()
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()
def test_get_frequencies(self): _click_area(self.app.freq_slct_from_file.ui.listView_stations.viewport()) QTest.qWait(1000) freqs = self.app.freq_slct_from_file.get_selected_frequencies() self.assertTrue(len(freqs) == self.app.freq_slct_from_file.ui.tableWidget_selected.rowCount()) # check frequency index = self.app.freq_slct_from_file.ui.listView_stations.selectedIndexes()[0] station = self.app.freq_slct_from_file.model_stations.item(index.row()).data(QtCore.Qt.DisplayRole) mtobj = self.app.freq_slct_from_file._mt_obj_dict[station] mt_freqs = sorted(list(set(mtobj.Z.freq))) self.assertTrue(all([freq == mtfreq for freq, mtfreq in zip(freqs, mt_freqs)]))
def test_plot_mt_response_enable_type_1(self): plot_config = self._switch_to_plot(MTResponse) # type:MTResponse _click_area(plot_config._arrow_ui.ui.checkBox_real, pos=self._pos_check_box) _click_area(plot_config._arrow_ui.ui.checkBox_imaginary, pos=self._pos_check_box) _click_area(plot_config._plot_control_ui.ui.checkBox_pt, pos=self._pos_check_box) _click_area(plot_config._rotation_ui.ui.dial_rotation, pos=self._pos_check_box) _click_area(plot_config._plot_control_ui.ui.radioButton_1, pos=self._pos_check_box) self._plot()
def test_plot_type_1(self): plot_gui = self._switch_to_plot(Strike) # type: Strike _click_area(plot_gui._plot_control_ui.ui.radioButton_type_1, pos=self._pos_check_box) _click_area(plot_gui._plot_control_ui.ui.checkBox_plot_tipper, pos=self._pos_check_box) _click_area(plot_gui._rotation_ui.ui.dial_rotation) self._plot(10000) # fold _click_area(plot_gui._plot_control_ui.ui.checkBox_fold, pos=self._pos_check_box) self._plot(10000)
def test_selection(self): self.assertTrue(self.app.freq_slct_from_file.ui.tableWidget_selected.rowCount() == 0) _click_area(self.app.freq_slct_from_file.ui.listView_stations.viewport()) QTest.qWait(1000) _click_area(self.app.freq_slct_from_file.ui.listView_stations.viewport(), modifier=QtCore.Qt.ControlModifier) QTest.qWait(1000) _click_area(self.app.freq_slct_from_file.ui.listView_stations.viewport(), modifier=QtCore.Qt.ControlModifier) QTest.qWait(1000) self.assertTrue(self.app.freq_slct_from_file.ui.tableWidget_selected.rowCount() > 0)
def test_all(self): plot_gui = self._switch_to_plot(Depth2D) # type: Depth2D _click_area(plot_gui._z_component_ui.ui.radioButton_det, self._pos_check_box) self._plot() _click_area(plot_gui._z_component_ui.ui.radioButton_zxy, self._pos_check_box) self._plot() _click_area(plot_gui._z_component_ui.ui.radioButton_zyx, self._pos_check_box) self._plot()
def test_all(self): plot_gui = self._switch_to_plot(Depth1D) # type: Depth1D self._plot() _click_area(plot_gui._z_component_ui.ui.checkBox_det, self._pos_check_box) self._plot() _click_area(plot_gui._z_component_ui.ui.checkBox_zxy, self._pos_check_box) self._plot() # last checked checkbox should be disabled and not unchecked _click_area(plot_gui._z_component_ui.ui.checkBox_zyx, self._pos_check_box) self.assertFalse(plot_gui._z_component_ui.ui.checkBox_zyx.isEnabled()) self.assertTrue(plot_gui._z_component_ui.ui.checkBox_zyx.isChecked())
def _fake_export_dialog_exec_export(self): _click_area(self.dialog.ui.pushButton_export) return QDialog.Accepted
def _fake_export_dialog_exec_cancel(self): _click_area(self.dialog.ui.pushButton_cancel) return QDialog.Rejected
def _fake_msg_dialog_exec_cancel(self): self.dialog._msg_box.show() QTest.qWaitForWindowActive(self.dialog._msg_box) _click_area(self.dialog._msg_box_button_cancel) return QMessageBox.Cancel
def _fake_msg_dialog_exec_save_as(self): self.dialog._msg_box.show() QTest.qWaitForWindowActive(self.dialog._msg_box) _click_area(self.dialog._msg_box_button_save_as) return QMessageBox.Accepted
def test_multiple_mt_response_all_type_1(self): plot_config = self._switch_to_plot(MultipleMTResponses, 2) # type: MultipleMTResponses _click_area(plot_config._plot_control_ui.ui.radioButton_all) _click_area(plot_config._plot_control_ui.ui.radioButton_1, pos=self._pos_check_box) _click_area(plot_config._plot_control_ui.ui.checkBox_skew, pos=self._pos_check_box) _click_area(plot_config._plot_control_ui.ui.checkBox_pt, pos=self._pos_check_box) _click_area(plot_config._plot_control_ui.ui.checkBox_strike_i, pos=self._pos_check_box) _click_area(plot_config._plot_control_ui.ui.checkBox_strike_p, pos=self._pos_check_box) _click_area(plot_config._plot_control_ui.ui.checkBox_strike_t, pos=self._pos_check_box) _click_area(plot_config._arrow_ui.ui.checkBox_real, pos=self._pos_check_box) _click_area(plot_config._arrow_ui.ui.checkBox_imaginary, pos=self._pos_check_box) _click_area(plot_config._rotation_ui.ui.dial_rotation) self._plot( 60000) # this complete image could take very long time to plot
def test_all(self): plot_gui = self._switch_to_plot(Depth3D) # type: Depth3D # select random frequency by randomly click on the frequency selection gui # repeat a few time in case some of the random clicks are not valid for i in range(3): _click_area(plot_gui._frequency_period_ui.histogram, offset=plot_gui._frequency_period_ui.histogram. geometry().topLeft()) _click_area(plot_gui._z_component_ui.ui.radioButton_det, self._pos_check_box) _click_area(plot_gui._z_unit_ui.ui.radioButton_m) self._plot() _click_area(plot_gui._z_unit_ui.ui.radioButton_km) _click_area(plot_gui._z_component_ui.ui.radioButton_zxy, self._pos_check_box) self._plot() _click_area(plot_gui._z_component_ui.ui.radioButton_zyx, self._pos_check_box) self._plot()
def _std_function_tests(self): pos_check_box = QPoint(8, 8) _click_area(self.app.frequency_select.ui.radioButton_period, pos_check_box) self.assertTrue( self.app.frequency_select.ui.radioButton_period.isChecked()) _click_area(self.app.frequency_select.ui.radioButton_frequency, pos_check_box) self.assertTrue( self.app.frequency_select.ui.radioButton_frequency.isChecked()) # test frequency selection _click_area( self.app.frequency_select.histogram, offset=self.app.frequency_select.histogram.geometry().topLeft()) _click_area( self.app.frequency_select.histogram, offset=self.app.frequency_select.histogram.geometry().topLeft()) _click_area( self.app.frequency_select.histogram, offset=self.app.frequency_select.histogram.geometry().topLeft()) _click_area( self.app.frequency_select.histogram, offset=self.app.frequency_select.histogram.geometry().topLeft()) _click_area( self.app.frequency_select.histogram, offset=self.app.frequency_select.histogram.geometry().topLeft()) self.assertTrue( self.app.frequency_select.model_selected.rowCount() > 0) _click_area(self.app.frequency_select.ui.checkBox_existing_only, pos_check_box) self.assertTrue( self.app.frequency_select.ui.checkBox_existing_only.isChecked()) self.assertTrue( self.app.frequency_select.histogram._select_existing_only) self.assertTrue( self.app.frequency_select.model_selected.rowCount() == 0) _click_area(self.app.frequency_select.ui.checkBox_show_existing, pos_check_box) self.assertTrue( self.app.frequency_select.ui.checkBox_show_existing.isChecked()) self.assertTrue(self.app.frequency_select.histogram._show_existing) _click_area(self.app.frequency_select.ui.checkBox_y_log_scale, pos_check_box) self.assertTrue( self.app.frequency_select.ui.checkBox_y_log_scale.isChecked()) self.assertTrue(self.app.frequency_select.histogram._y_log_scale) _click_area(self.app.frequency_select.ui.checkBox_x_log_scale, pos_check_box) self.assertTrue( self.app.frequency_select.ui.checkBox_x_log_scale.isChecked()) self.assertTrue(self.app.frequency_select.histogram._x_log_scale) # test clear _click_area(self.app.frequency_select.ui.pushButton_clear) self.assertTrue( self.app.frequency_select.model_selected.rowCount() == 0) # test delete _click_area( self.app.frequency_select.histogram, offset=self.app.frequency_select.histogram.geometry().topLeft()) _click_area( self.app.frequency_select.histogram, offset=self.app.frequency_select.histogram.geometry().topLeft()) _click_area( self.app.frequency_select.histogram, offset=self.app.frequency_select.histogram.geometry().topLeft()) _click_area( self.app.frequency_select.histogram, offset=self.app.frequency_select.histogram.geometry().topLeft()) _click_area( self.app.frequency_select.histogram, offset=self.app.frequency_select.histogram.geometry().topLeft()) self.assertTrue( self.app.frequency_select.model_selected.rowCount() > 0) self.app.frequency_select.ui.listView_selected.selectAll() _click_area(self.app.frequency_select.ui.pushButton_delete) self.assertTrue( self.app.frequency_select.model_selected.rowCount() == 0)