|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | +import brightway2 as bw |
| 3 | +from PySide2.QtCore import Qt |
| 4 | +from PySide2.QtWidgets import QMessageBox, QWizard |
| 5 | +import pytest |
| 6 | + |
| 7 | +from activity_browser.app.ui.wizards.settings_wizard import SettingsWizard |
| 8 | + |
| 9 | + |
| 10 | +def test_settings_wizard_simple(qtbot, bw2test): |
| 11 | + """Test some of the default values of the wizard.""" |
| 12 | + wizard = SettingsWizard(None) |
| 13 | + qtbot.addWidget(wizard) |
| 14 | + wizard.show() |
| 15 | + |
| 16 | + # Check that the default fields are default |
| 17 | + assert wizard.field("startup_project") == "default" |
| 18 | + assert wizard.field("custom_bw_dir") == "" |
| 19 | + assert wizard.last_bwdir == bw.projects._base_data_dir |
| 20 | + |
| 21 | + # We can't click 'Save' from the start. |
| 22 | + assert not wizard.button(QWizard.FinishButton).isEnabled() |
| 23 | + |
| 24 | + # cancel out of the wizard. |
| 25 | + qtbot.mouseClick(wizard.button(QWizard.CancelButton), Qt.LeftButton) |
| 26 | + |
| 27 | + |
| 28 | +def test_alter_startup_project(qtbot): |
| 29 | + """Alter the default startup project""" |
| 30 | + wizard = SettingsWizard(None) |
| 31 | + qtbot.addWidget(wizard) |
| 32 | + wizard.show() |
| 33 | + |
| 34 | + # Check we can't Save, alter the startup project and check again. |
| 35 | + assert not wizard.settings_page.isComplete() |
| 36 | + with qtbot.waitSignal(wizard.settings_page.completeChanged, timeout=100): |
| 37 | + index = wizard.settings_page.project_names.index("pytest_project") |
| 38 | + wizard.settings_page.startup_project_combobox.setCurrentIndex(index) |
| 39 | + assert wizard.field("startup_project") == "pytest_project" |
| 40 | + assert wizard.settings_page.isComplete() |
| 41 | + |
| 42 | + with qtbot.waitSignal(wizard.finished, timeout=100): |
| 43 | + qtbot.mouseClick(wizard.button(QWizard.FinishButton), Qt.LeftButton) |
| 44 | + |
| 45 | + |
| 46 | +def test_restore_defaults(qtbot, monkeypatch): |
| 47 | + """Restore the default startup project.""" |
| 48 | + wizard = SettingsWizard(None) |
| 49 | + qtbot.addWidget(wizard) |
| 50 | + wizard.show() |
| 51 | + |
| 52 | + # Follow-up from the last test, restore the startup_project to default |
| 53 | + assert wizard.field("startup_project") == "pytest_project" |
| 54 | + |
| 55 | + with qtbot.waitSignal(wizard.settings_page.startup_project_combobox.currentIndexChanged, timeout=100): |
| 56 | + # No handle the popup about changing the brightway2 directory. |
| 57 | + monkeypatch.setattr(QMessageBox, "question", lambda *args: QMessageBox.No) |
| 58 | + qtbot.mouseClick( |
| 59 | + wizard.settings_page.restore_defaults_button, |
| 60 | + Qt.LeftButton |
| 61 | + ) |
| 62 | + |
| 63 | + assert wizard.field("startup_project") == "default" |
| 64 | + |
| 65 | + with qtbot.waitSignal(wizard.finished, timeout=100): |
| 66 | + qtbot.mouseClick(wizard.button(QWizard.FinishButton), Qt.LeftButton) |
0 commit comments