def test_reactive_line_edit(qtbot: QtBot): start_text = "Start." edit = line_edit(start_text) qtbot.add_widget(edit) events = [] edit.subscribe(events.append) will_type = "Test." qtbot.keyClicks(edit, will_type) assert events == [ start_text + will_type[:i] for i in range(len(will_type) + 1) ]
def test_ignition_point_dialog_05(qgis_app: QgsApplication, qgis_locale: QSettings, qgis_plugin: Dict[str, Any], qgis_bot: QgisBot, qtbot: QtBot, qgis_new_project: None): """ Tests the labels and data provided is shown (with local TZ) :param qgis_app: QGIS application fixture :type qgis_app: QgsApplication :param qgis_locale: QT settings fixture with a user locale :type qgis_locale: QSettings :param qgis_plugin: QGIS loading and unloading fixture for plugins :type qgis_plugin: dict of Any :param qgis_bot: QGIS Bot to automate GUI tests :type qgis_bot: QgisBot :param qtbot: QT fixture to automate GUI tests :type qtbot: QtBot :param qgis_new_project: Ensures the project instance is clean :type qgis_new_project: None """ assert type(qgis.utils.plugins['gisfire_spread_simulation'] ).__name__ == 'GisFIRESpreadSimulation' dialog: IgnitionDateTimeDialog = IgnitionDateTimeDialog() dialog.show() assert dialog.isVisible() dt: datetime.datetime = datetime.datetime(2022, 1, 1, 0, 0, 0, tzinfo=pytz.timezone('CET')) dt_str: str = dt.strftime("%d/%m/%Y %H:%M:%S") qtbot.keyClicks(dialog._datetime_ignition, dt_str) assert dialog.ignition_datetime == datetime.datetime(2021, 12, 31, 23, 0, 0, tzinfo=pytz.UTC) buttons: QDialogButtonBox = dialog._button_box button_ok: QPushButton = buttons.button(QDialogButtonBox.Ok) qtbot.mouseClick(button_ok, qgis.QtCore.Qt.LeftButton) assert not dialog.isVisible()
def test_submit_gating(qtbot: QtBot): ui = {} with CollectUI(ui): top_level = vertical( "Some reactive inputs", radio_button("Radio button", id="radio"), line_edit("!", id="edit"), button("Submit", id="submit"), ) qtbot.add_widget(top_level) edit_events = [] radio_events = [] ui["radio"].subscribe(radio_events.append) ui["edit"].subscribe(edit_events.append) # collect into a small form form_events = [] submit("submit", ["radio", "edit"], ui=ui).subscribe(form_events.append) ui["radio"].setChecked(True) ui["radio"].setChecked(True) ui["radio"].setChecked(False) qtbot.keyClicks(ui["edit"], "Text") qtbot.mouseClick(ui["submit"], QtCore.Qt.LeftButton) ui["radio"].setChecked(True) qtbot.keyClicks(ui["edit"], "B") qtbot.mouseClick(ui["submit"], QtCore.Qt.LeftButton) assert edit_events == [f"!{'TextB'[:i]}" for i in range(len("TextB") + 1)] assert radio_events == [False, True, False, True] assert form_events == [ { "edit": "!Text", "radio": False }, { "edit": "!TextB", "radio": True }, ]
def test_layer_name_dialog_03(qgis_app: QgsApplication, qgis_locale: QSettings, qgis_plugin: Dict[str, Any], qgis_bot: QgisBot, qtbot: QtBot, qgis_new_project: None): """ Tests the layer name dialog invalidates the input when the user enters an existing layer name :param qgis_app: QGIS application fixture :type qgis_app: QgsApplication :param qgis_locale: QT settings fixture with a user locale :type qgis_locale: QSettings :param qgis_plugin: QGIS loading and unloading fixture for plugins :type qgis_plugin: dict of Any :param qgis_bot: QGIS Bot to automate GUI tests :type qgis_bot: QgisBot :param qtbot: QT fixture to automate GUI tests :type qtbot: QtBot :param qgis_new_project: Ensures the project instance is clean :type qgis_new_project: None """ assert type(qgis.utils.plugins['gisfire_spread_simulation']).__name__ == 'GisFIRESpreadSimulation' project: QgsProject = QgsProject() project_instance: QgsProject = project.instance() vl_a = QgsVectorLayer('Point', 'a', 'memory') vl_b = QgsVectorLayer('Point', 'b', 'memory') vl_c = QgsVectorLayer('Point', 'c', 'memory') project_instance.addMapLayer(vl_a) project_instance.addMapLayer(vl_b) project_instance.addMapLayer(vl_c) dialog: LayerNameDialog = LayerNameDialog(layers=project_instance.mapLayers()) assert len(dialog._layer_names) == 3 qtbot.addWidget(dialog) dialog.show() assert dialog.isVisible() assert dialog._lineedit_layer_name.palette().color(QPalette.WindowText) == QColor(dialog._text_color) qtbot.keyClicks(dialog._lineedit_layer_name, 'a') assert dialog._lineedit_layer_name.palette().color(QPalette.WindowText) == QColor('red') buttons: QDialogButtonBox = dialog._button_box button_ok: QPushButton = buttons.button(QDialogButtonBox.Ok) assert not button_ok.isEnabled() qtbot.keyClicks(dialog._lineedit_layer_name, 'f') assert dialog._lineedit_layer_name.palette().color(QPalette.WindowText) == QColor(dialog._text_color) assert button_ok.isEnabled() qtbot.mouseClick(button_ok, qgis.QtCore.Qt.LeftButton) assert not dialog.isVisible() assert dialog.layer_name == 'af'
def test_settings_dialog_03(qgis_app: QgsApplication, qgis_locale: QSettings, qgis_plugin: Dict[str, Any], qgis_bot: QgisBot, qtbot: QtBot, qgis_new_project: None): """ Tests the settings dialog loads correctly the different layers of the project depending on its type and its selection :param qgis_app: QGIS application fixture :type qgis_app: QgsApplication :param qgis_locale: QT settings fixture with a user locale :type qgis_locale: QSettings :param qgis_plugin: QGIS loading and unloading fixture for plugins :type qgis_plugin: dict of Any :param qgis_bot: QGIS Bot to automate GUI tests :type qgis_bot: QgisBot :param qtbot: QT fixture to automate GUI tests :type qtbot: QtBot :param qgis_new_project: Ensures the project instance is clean :type qgis_new_project: None """ assert type(qgis.utils.plugins['gisfire_spread_simulation']).__name__ == 'GisFIRESpreadSimulation' project: QgsProject = QgsProject() project_instance: QgsProject = project.instance() # Create possible vector layers to choose from vl_a = QgsVectorLayer('Point', 'a', 'memory') vl_b = QgsVectorLayer('Point', 'b', 'memory') vl_c = QgsVectorLayer('Point', 'c', 'memory') project_instance.addMapLayer(vl_a) project_instance.addMapLayer(vl_b) project_instance.addMapLayer(vl_c) vl_d = QgsVectorLayer('Polygon', 'd', 'memory') vl_e = QgsVectorLayer('Polygon', 'e', 'memory') vl_f = QgsVectorLayer('Polygon', 'f', 'memory') vl_g = QgsVectorLayer('Polygon', 'g', 'memory') project_instance.addMapLayer(vl_d) project_instance.addMapLayer(vl_e) project_instance.addMapLayer(vl_f) project_instance.addMapLayer(vl_g) dialog: SettingsDialog = SettingsDialog(layers=project_instance.mapLayers()) assert dialog._combobox_ignition_layer.count() == 3 assert dialog._combobox_perimeter_layer.count() == 4 assert dialog._combobox_land_cover_layer.count() == 4 qtbot.addWidget(dialog) dialog.show() assert dialog.isVisible() # Select the different layers in the combobox qtbot.keyClicks(dialog._combobox_ignition_layer, 'c') qtbot.keyClicks(dialog._combobox_perimeter_layer, 'd') qtbot.keyClicks(dialog._combobox_land_cover_layer, 'g') buttons: QDialogButtonBox = dialog._button_box button_ok: QPushButton = buttons.button(qgis.PyQt.QtWidgets.QDialogButtonBox.Ok) qtbot.mouseClick(button_ok, qgis.QtCore.Qt.LeftButton) assert not dialog.isVisible() # Get the values assert dialog.ignition_layer == vl_c assert dialog.perimeter_layer == vl_d assert dialog.land_cover_layer == vl_g
def the_user_enters_time(hours: str, mins: str, secs: str, window: MainWindow, qtbot: QtBot): qtbot.keyClicks(window.hours_input, hours) qtbot.keyClicks(window.minutes_input, mins) qtbot.keyClicks(window.seconds_input, secs)
def type_the_pin(pin: str, dialog: LoginDialog, model: Model, qtbot: QtBot): """I type "pin".""" qtbot.keyClicks(dialog.pin_line, pin)