diff --git a/spinetoolbox/widgets/add_up_spine_opt_wizard.py b/spinetoolbox/widgets/add_up_spine_opt_wizard.py
index a607f838e..4b385b38a 100644
--- a/spinetoolbox/widgets/add_up_spine_opt_wizard.py
+++ b/spinetoolbox/widgets/add_up_spine_opt_wizard.py
@@ -303,9 +303,11 @@ def initializePage(self):
check_box.setChecked(True)
self.registerField("troubleshoot", check_box)
layout = QVBoxLayout(self)
- msg = ("Apologies. Please see the Troubleshoot problems section "
- "by clicking Next or click Cancel to close "
- "the wizard.")
+ msg = (
+ "Apologies. Please see the Troubleshoot problems section "
+ "by clicking Next or click Cancel to close "
+ "the wizard."
+ )
layout.addWidget(WrapLabel(msg))
layout.addStretch()
layout.addWidget(check_box)
@@ -532,8 +534,10 @@ def __init__(self, parent):
def initializePage(self):
self.setTitle("Troubleshooting failed")
- msg = ("
Please open an issue with SpineOpt."
- "
Copy the log and paste it into the issue description.
")
+ msg = (
+ "Please open an issue with SpineOpt."
+ "
Copy the log and paste it into the issue description.
"
+ )
layout = QVBoxLayout(self)
layout.addWidget(HyperTextLabel(msg))
copy_widget = QWidget()
diff --git a/spinetoolbox/widgets/install_julia_wizard.py b/spinetoolbox/widgets/install_julia_wizard.py
index 15bafee7a..b9590a254 100644
--- a/spinetoolbox/widgets/install_julia_wizard.py
+++ b/spinetoolbox/widgets/install_julia_wizard.py
@@ -13,6 +13,7 @@
"""Classes for custom QDialogs for julia setup."""
from enum import IntEnum, auto
import os
+import sys
try:
import jill.install as jill_install
@@ -72,13 +73,15 @@ def __init__(self, parent):
self.setStartId(_PageId.INTRO)
def set_julia_exe(self):
- basename = next(
- (file for file in os.listdir(self.field("symlink_dir")) if file.lower().startswith("julia")), None
- )
- if basename is None:
+ """Returns the path to the jill julia launcher, which always launches the latest Julia release."""
+ if not sys.platform == "win32":
+ julia_launcher_path = os.path.join(self.field("symlink_dir"), "julia")
+ else:
+ julia_launcher_path = os.path.join(self.field("symlink_dir"), "julia.cmd")
+ if not os.path.exists(julia_launcher_path):
self.julia_exe = None
return
- self.julia_exe = os.path.join(self.field("symlink_dir"), basename)
+ self.julia_exe = julia_launcher_path
def accept(self):
super().accept()
diff --git a/tests/mock_helpers.py b/tests/mock_helpers.py
index 6430abeb5..78370e99a 100644
--- a/tests/mock_helpers.py
+++ b/tests/mock_helpers.py
@@ -36,9 +36,11 @@ def tearDownClass(cls):
def create_toolboxui():
"""Returns ToolboxUI, where QSettings among others has been mocked."""
- with mock.patch("spinetoolbox.ui_main.QSettings.value") as mock_qsettings_value, mock.patch(
- "spinetoolbox.ui_main.ToolboxUI.set_app_style"
- ) as mock_set_app_style, mock.patch("spinetoolbox.plugin_manager.PluginManager.load_installed_plugins"):
+ with (
+ mock.patch("spinetoolbox.ui_main.QSettings.value") as mock_qsettings_value,
+ mock.patch("spinetoolbox.ui_main.ToolboxUI.set_app_style") as mock_set_app_style,
+ mock.patch("spinetoolbox.plugin_manager.PluginManager.load_installed_plugins"),
+ ):
mock_qsettings_value.side_effect = qsettings_value_side_effect
mock_set_app_style.return_value = True
toolbox = ToolboxUI()
@@ -47,25 +49,25 @@ def create_toolboxui():
def create_project(toolbox, project_dir):
"""Creates a project for the given ToolboxUI."""
- with mock.patch("spinetoolbox.ui_main.ToolboxUI.update_recent_projects"), mock.patch(
- "spinetoolbox.ui_main.QSettings.setValue"
- ), mock.patch("spinetoolbox.ui_main.QSettings.sync"):
+ with (
+ mock.patch("spinetoolbox.ui_main.ToolboxUI.update_recent_projects"),
+ mock.patch("spinetoolbox.ui_main.QSettings.setValue"),
+ mock.patch("spinetoolbox.ui_main.QSettings.sync"),
+ ):
toolbox.create_project(project_dir)
def create_toolboxui_with_project(project_dir):
"""Returns ToolboxUI with a project instance where
QSettings among others has been mocked."""
- with mock.patch("spinetoolbox.ui_main.QSettings.value") as mock_qsettings_value, mock.patch(
- "spinetoolbox.ui_main.ToolboxUI.set_app_style"
- ) as mock_set_app_style, mock.patch("spinetoolbox.ui_main.ToolboxUI.save_project"), mock.patch(
- "spinetoolbox.ui_main.QSettings.setValue"
- ), mock.patch(
- "spinetoolbox.ui_main.QSettings.sync"
- ), mock.patch(
- "spinetoolbox.plugin_manager.PluginManager.load_installed_plugins"
- ), mock.patch(
- "spinetoolbox.ui_main.QScrollArea.setWidget"
+ with (
+ mock.patch("spinetoolbox.ui_main.QSettings.value") as mock_qsettings_value,
+ mock.patch("spinetoolbox.ui_main.ToolboxUI.set_app_style") as mock_set_app_style,
+ mock.patch("spinetoolbox.ui_main.ToolboxUI.save_project"),
+ mock.patch("spinetoolbox.ui_main.QSettings.setValue"),
+ mock.patch("spinetoolbox.ui_main.QSettings.sync"),
+ mock.patch("spinetoolbox.plugin_manager.PluginManager.load_installed_plugins"),
+ mock.patch("spinetoolbox.ui_main.QScrollArea.setWidget"),
):
mock_qsettings_value.side_effect = qsettings_value_side_effect
mock_set_app_style.return_value = True
diff --git a/tests/mvcmodels/test_FilterCheckboxList.py b/tests/mvcmodels/test_FilterCheckboxList.py
index 3c1e835c7..973de7ccf 100644
--- a/tests/mvcmodels/test_FilterCheckboxList.py
+++ b/tests/mvcmodels/test_FilterCheckboxList.py
@@ -47,12 +47,12 @@ def test_is_all_selected_when_not_empty_selected(self):
def test_add_item_with_select_without_filter(self):
new_item = ["aaaa"]
self.model.set_list(self.data)
- with mock.patch(
- "spinetoolbox.mvcmodels.filter_checkbox_list_model.SimpleFilterCheckboxListModel.beginInsertRows"
- ), mock.patch(
- "spinetoolbox.mvcmodels.filter_checkbox_list_model.SimpleFilterCheckboxListModel.endInsertRows"
- ), mock.patch(
- "spinetoolbox.mvcmodels.filter_checkbox_list_model.SimpleFilterCheckboxListModel.dataChanged"
+ with (
+ mock.patch(
+ "spinetoolbox.mvcmodels.filter_checkbox_list_model.SimpleFilterCheckboxListModel.beginInsertRows"
+ ),
+ mock.patch("spinetoolbox.mvcmodels.filter_checkbox_list_model.SimpleFilterCheckboxListModel.endInsertRows"),
+ mock.patch("spinetoolbox.mvcmodels.filter_checkbox_list_model.SimpleFilterCheckboxListModel.dataChanged"),
):
self.model.add_items(new_item)
self.assertEqual(self.model._data, self.data + new_item)
@@ -61,12 +61,12 @@ def test_add_item_with_select_without_filter(self):
def test_add_item_without_select_without_filter(self):
new_item = ["aaaa"]
self.model.set_list(self.data)
- with mock.patch(
- "spinetoolbox.mvcmodels.filter_checkbox_list_model.SimpleFilterCheckboxListModel.beginInsertRows"
- ), mock.patch(
- "spinetoolbox.mvcmodels.filter_checkbox_list_model.SimpleFilterCheckboxListModel.endInsertRows"
- ), mock.patch(
- "spinetoolbox.mvcmodels.filter_checkbox_list_model.SimpleFilterCheckboxListModel.dataChanged"
+ with (
+ mock.patch(
+ "spinetoolbox.mvcmodels.filter_checkbox_list_model.SimpleFilterCheckboxListModel.beginInsertRows"
+ ),
+ mock.patch("spinetoolbox.mvcmodels.filter_checkbox_list_model.SimpleFilterCheckboxListModel.endInsertRows"),
+ mock.patch("spinetoolbox.mvcmodels.filter_checkbox_list_model.SimpleFilterCheckboxListModel.dataChanged"),
):
self.model.add_items(new_item, selected=False)
self.assertFalse(self.model._all_selected)
@@ -237,12 +237,12 @@ def test_add_item_with_select_with_filter_last(self):
new_item = ["bbbb"]
self.model.set_list(self.data)
self.model.set_filter("b")
- with mock.patch(
- "spinetoolbox.mvcmodels.filter_checkbox_list_model.SimpleFilterCheckboxListModel.beginInsertRows"
- ), mock.patch(
- "spinetoolbox.mvcmodels.filter_checkbox_list_model.SimpleFilterCheckboxListModel.endInsertRows"
- ), mock.patch(
- "spinetoolbox.mvcmodels.filter_checkbox_list_model.SimpleFilterCheckboxListModel.dataChanged"
+ with (
+ mock.patch(
+ "spinetoolbox.mvcmodels.filter_checkbox_list_model.SimpleFilterCheckboxListModel.beginInsertRows"
+ ),
+ mock.patch("spinetoolbox.mvcmodels.filter_checkbox_list_model.SimpleFilterCheckboxListModel.endInsertRows"),
+ mock.patch("spinetoolbox.mvcmodels.filter_checkbox_list_model.SimpleFilterCheckboxListModel.dataChanged"),
):
self.model.add_items(new_item)
self.assertEqual(self.model._data, sorted(self.data + new_item))
@@ -255,12 +255,12 @@ def test_add_item_with_select_with_filter_first(self):
new_item = ["0b"]
self.model.set_list(self.data)
self.model.set_filter("b")
- with mock.patch(
- "spinetoolbox.mvcmodels.filter_checkbox_list_model.SimpleFilterCheckboxListModel.beginInsertRows"
- ), mock.patch(
- "spinetoolbox.mvcmodels.filter_checkbox_list_model.SimpleFilterCheckboxListModel.endInsertRows"
- ), mock.patch(
- "spinetoolbox.mvcmodels.filter_checkbox_list_model.SimpleFilterCheckboxListModel.dataChanged"
+ with (
+ mock.patch(
+ "spinetoolbox.mvcmodels.filter_checkbox_list_model.SimpleFilterCheckboxListModel.beginInsertRows"
+ ),
+ mock.patch("spinetoolbox.mvcmodels.filter_checkbox_list_model.SimpleFilterCheckboxListModel.endInsertRows"),
+ mock.patch("spinetoolbox.mvcmodels.filter_checkbox_list_model.SimpleFilterCheckboxListModel.dataChanged"),
):
self.model.add_items(new_item)
self.assertEqual(self.model._filter_index, [3, 4, 5, 6])
@@ -270,12 +270,12 @@ def test_add_item_with_select_with_filter_middle(self):
new_item = ["b1"]
self.model.set_list(self.data)
self.model.set_filter("b")
- with mock.patch(
- "spinetoolbox.mvcmodels.filter_checkbox_list_model.SimpleFilterCheckboxListModel.beginInsertRows"
- ), mock.patch(
- "spinetoolbox.mvcmodels.filter_checkbox_list_model.SimpleFilterCheckboxListModel.endInsertRows"
- ), mock.patch(
- "spinetoolbox.mvcmodels.filter_checkbox_list_model.SimpleFilterCheckboxListModel.dataChanged"
+ with (
+ mock.patch(
+ "spinetoolbox.mvcmodels.filter_checkbox_list_model.SimpleFilterCheckboxListModel.beginInsertRows"
+ ),
+ mock.patch("spinetoolbox.mvcmodels.filter_checkbox_list_model.SimpleFilterCheckboxListModel.endInsertRows"),
+ mock.patch("spinetoolbox.mvcmodels.filter_checkbox_list_model.SimpleFilterCheckboxListModel.dataChanged"),
):
self.model.add_items(new_item)
self.assertEqual(self.model._filter_index, [3, 4, 5, 6])
@@ -284,9 +284,12 @@ def test_add_item_with_select_with_filter_middle(self):
def test_remove_items_data(self):
items = set("a")
self.model.set_list(self.data)
- with mock.patch(
- "spinetoolbox.mvcmodels.filter_checkbox_list_model.SimpleFilterCheckboxListModel.beginResetModel"
- ), mock.patch("spinetoolbox.mvcmodels.filter_checkbox_list_model.SimpleFilterCheckboxListModel.endResetModel"):
+ with (
+ mock.patch(
+ "spinetoolbox.mvcmodels.filter_checkbox_list_model.SimpleFilterCheckboxListModel.beginResetModel"
+ ),
+ mock.patch("spinetoolbox.mvcmodels.filter_checkbox_list_model.SimpleFilterCheckboxListModel.endResetModel"),
+ ):
self.model.remove_items(items)
self.assertEqual(self.model._data, self.data[1:])
self.assertEqual(self.model._data_set, set(self.data[1:]))
@@ -294,9 +297,12 @@ def test_remove_items_data(self):
def test_remove_items_selected(self):
items = set("a")
self.model.set_list(self.data)
- with mock.patch(
- "spinetoolbox.mvcmodels.filter_checkbox_list_model.SimpleFilterCheckboxListModel.beginResetModel"
- ), mock.patch("spinetoolbox.mvcmodels.filter_checkbox_list_model.SimpleFilterCheckboxListModel.endResetModel"):
+ with (
+ mock.patch(
+ "spinetoolbox.mvcmodels.filter_checkbox_list_model.SimpleFilterCheckboxListModel.beginResetModel"
+ ),
+ mock.patch("spinetoolbox.mvcmodels.filter_checkbox_list_model.SimpleFilterCheckboxListModel.endResetModel"),
+ ):
self.model.remove_items(items)
self.assertEqual(self.model._selected, set(self.data[1:]))
self.assertTrue(self.model._all_selected)
@@ -306,9 +312,12 @@ def test_remove_items_not_selected(self):
self.model.set_list(self.data)
self.model._selected.discard("a")
self.model._all_selected = False
- with mock.patch(
- "spinetoolbox.mvcmodels.filter_checkbox_list_model.SimpleFilterCheckboxListModel.beginResetModel"
- ), mock.patch("spinetoolbox.mvcmodels.filter_checkbox_list_model.SimpleFilterCheckboxListModel.endResetModel"):
+ with (
+ mock.patch(
+ "spinetoolbox.mvcmodels.filter_checkbox_list_model.SimpleFilterCheckboxListModel.beginResetModel"
+ ),
+ mock.patch("spinetoolbox.mvcmodels.filter_checkbox_list_model.SimpleFilterCheckboxListModel.endResetModel"),
+ ):
self.model.remove_items(items)
self.assertEqual(self.model._selected, set(self.data[1:]))
self.assertTrue(self.model._all_selected)
@@ -317,9 +326,12 @@ def test_remove_items_filtered_data(self):
items = set("b")
self.model.set_list(self.data)
self.model.set_filter("b")
- with mock.patch(
- "spinetoolbox.mvcmodels.filter_checkbox_list_model.SimpleFilterCheckboxListModel.beginResetModel"
- ), mock.patch("spinetoolbox.mvcmodels.filter_checkbox_list_model.SimpleFilterCheckboxListModel.endResetModel"):
+ with (
+ mock.patch(
+ "spinetoolbox.mvcmodels.filter_checkbox_list_model.SimpleFilterCheckboxListModel.beginResetModel"
+ ),
+ mock.patch("spinetoolbox.mvcmodels.filter_checkbox_list_model.SimpleFilterCheckboxListModel.endResetModel"),
+ ):
self.model.remove_items(items)
self.assertEqual(self.model._filter_index, [3, 4])
self.assertEqual(self.model._selected_filtered, set(self.data[4:]))
@@ -328,9 +340,12 @@ def test_remove_items_filtered_data_middle(self):
items = set("bb")
self.model.set_list(self.data)
self.model.set_filter("b")
- with mock.patch(
- "spinetoolbox.mvcmodels.filter_checkbox_list_model.SimpleFilterCheckboxListModel.beginResetModel"
- ), mock.patch("spinetoolbox.mvcmodels.filter_checkbox_list_model.SimpleFilterCheckboxListModel.endResetModel"):
+ with (
+ mock.patch(
+ "spinetoolbox.mvcmodels.filter_checkbox_list_model.SimpleFilterCheckboxListModel.beginResetModel"
+ ),
+ mock.patch("spinetoolbox.mvcmodels.filter_checkbox_list_model.SimpleFilterCheckboxListModel.endResetModel"),
+ ):
self.model.remove_items(items)
self.assertEqual(self.model._filter_index, [3, 4])
@@ -340,9 +355,12 @@ def test_remove_items_filtered_data_not_selected(self):
self.model.set_filter("b")
self.model._selected_filtered.discard("a")
self.model._all_selected = False
- with mock.patch(
- "spinetoolbox.mvcmodels.filter_checkbox_list_model.SimpleFilterCheckboxListModel.beginResetModel"
- ), mock.patch("spinetoolbox.mvcmodels.filter_checkbox_list_model.SimpleFilterCheckboxListModel.endResetModel"):
+ with (
+ mock.patch(
+ "spinetoolbox.mvcmodels.filter_checkbox_list_model.SimpleFilterCheckboxListModel.beginResetModel"
+ ),
+ mock.patch("spinetoolbox.mvcmodels.filter_checkbox_list_model.SimpleFilterCheckboxListModel.endResetModel"),
+ ):
self.model.remove_items(items)
self.assertEqual(self.model._selected_filtered, set(self.data[4:]))
self.assertTrue(self.model._all_selected)
diff --git a/tests/project_item/test_specification_editor_window.py b/tests/project_item/test_specification_editor_window.py
index d8b6edf34..3fb9a76f2 100644
--- a/tests/project_item/test_specification_editor_window.py
+++ b/tests/project_item/test_specification_editor_window.py
@@ -56,9 +56,12 @@ def tearDown(self):
self._temp_dir.cleanup()
def test_init(self):
- with patch.object(SpecificationEditorWindowBase, "_make_ui") as mock_make_ui, patch.object(
- SpecificationEditorWindowBase, "settings_group", new_callable=PropertyMock
- ) as mock_settings_group:
+ with (
+ patch.object(SpecificationEditorWindowBase, "_make_ui") as mock_make_ui,
+ patch.object(
+ SpecificationEditorWindowBase, "settings_group", new_callable=PropertyMock
+ ) as mock_settings_group,
+ ):
mock_settings_group.return_value = "settings group"
window = SpecificationEditorWindowBase(self._toolbox)
mock_make_ui.assert_called_once()
@@ -68,9 +71,12 @@ def test_init(self):
window.deleteLater()
def test_init_with_existing_specification(self):
- with patch.object(SpecificationEditorWindowBase, "_make_ui"), patch.object(
- SpecificationEditorWindowBase, "settings_group", new_callable=PropertyMock
- ) as mock_settings_group:
+ with (
+ patch.object(SpecificationEditorWindowBase, "_make_ui"),
+ patch.object(
+ SpecificationEditorWindowBase, "settings_group", new_callable=PropertyMock
+ ) as mock_settings_group,
+ ):
mock_settings_group.return_value = "settings group"
specification = ProjectItemSpecification("spec name", "spec description")
window = SpecificationEditorWindowBase(self._toolbox, specification)
@@ -81,17 +87,16 @@ def test_init_with_existing_specification(self):
window.deleteLater()
def test_save_specification(self):
- with patch.object(SpecificationEditorWindowBase, "_make_ui"), patch.object(
- SpecificationEditorWindowBase, "settings_group", new_callable=PropertyMock
- ) as mock_settings_group, patch.object(
- SpecificationEditorWindowBase, "_make_new_specification"
- ) as mock_make_specification, patch.object(
- ProjectItemSpecification, "save"
- ) as mock_save, patch.object(
- ProjectItemFactory, "icon"
- ) as mock_icon, patch.object(
- ProjectItemFactory, "icon_color"
- ) as mock_icon_color:
+ with (
+ patch.object(SpecificationEditorWindowBase, "_make_ui"),
+ patch.object(
+ SpecificationEditorWindowBase, "settings_group", new_callable=PropertyMock
+ ) as mock_settings_group,
+ patch.object(SpecificationEditorWindowBase, "_make_new_specification") as mock_make_specification,
+ patch.object(ProjectItemSpecification, "save") as mock_save,
+ patch.object(ProjectItemFactory, "icon") as mock_icon,
+ patch.object(ProjectItemFactory, "icon_color") as mock_icon_color,
+ ):
specification = ProjectItemSpecification("spec name", "spec description", "Mock")
mock_settings_group.return_value = "settings group"
mock_make_specification.return_value = specification
@@ -112,19 +117,17 @@ def test_save_specification(self):
window.deleteLater()
def test_make_new_specification_for_item(self):
- with patch.object(SpecificationEditorWindowBase, "_make_ui"), patch.object(
- SpecificationEditorWindowBase, "settings_group", new_callable=PropertyMock
- ) as mock_settings_group, patch.object(
- SpecificationEditorWindowBase, "_make_new_specification"
- ) as mock_make_specification, patch.object(
- ProjectItemSpecification, "save"
- ) as mock_save, patch.object(
- ProjectItemFactory, "make_icon"
- ) as mock_make_icon, patch.object(
- ProjectItemFactory, "icon"
- ) as mock_icon, patch.object(
- ProjectItemFactory, "icon_color"
- ) as mock_icon_color:
+ with (
+ patch.object(SpecificationEditorWindowBase, "_make_ui"),
+ patch.object(
+ SpecificationEditorWindowBase, "settings_group", new_callable=PropertyMock
+ ) as mock_settings_group,
+ patch.object(SpecificationEditorWindowBase, "_make_new_specification") as mock_make_specification,
+ patch.object(ProjectItemSpecification, "save") as mock_save,
+ patch.object(ProjectItemFactory, "make_icon") as mock_make_icon,
+ patch.object(ProjectItemFactory, "icon") as mock_icon,
+ patch.object(ProjectItemFactory, "icon_color") as mock_icon_color,
+ ):
mock_settings_group.return_value = "settings group"
mock_make_icon.return_value = ProjectItemIcon(
self._toolbox, ":/icons/item_icons/hammer.svg", QColor("white")
@@ -154,19 +157,17 @@ def test_make_new_specification_for_item(self):
window.deleteLater()
def test_rename_specification_for_item(self):
- with patch.object(SpecificationEditorWindowBase, "_make_ui"), patch.object(
- SpecificationEditorWindowBase, "settings_group", new_callable=PropertyMock
- ) as mock_settings_group, patch.object(
- SpecificationEditorWindowBase, "_make_new_specification"
- ) as mock_make_specification, patch.object(
- ProjectItemSpecification, "save"
- ) as mock_save, patch.object(
- ProjectItemFactory, "make_icon"
- ) as mock_make_icon, patch.object(
- ProjectItemFactory, "icon"
- ) as mock_icon, patch.object(
- ProjectItemFactory, "icon_color"
- ) as mock_icon_color:
+ with (
+ patch.object(SpecificationEditorWindowBase, "_make_ui"),
+ patch.object(
+ SpecificationEditorWindowBase, "settings_group", new_callable=PropertyMock
+ ) as mock_settings_group,
+ patch.object(SpecificationEditorWindowBase, "_make_new_specification") as mock_make_specification,
+ patch.object(ProjectItemSpecification, "save") as mock_save,
+ patch.object(ProjectItemFactory, "make_icon") as mock_make_icon,
+ patch.object(ProjectItemFactory, "icon") as mock_icon,
+ patch.object(ProjectItemFactory, "icon_color") as mock_icon_color,
+ ):
mock_settings_group.return_value = "settings group"
mock_make_icon.return_value = ProjectItemIcon(
self._toolbox, ":/icons/item_icons/hammer.svg", QColor("white")
diff --git a/tests/spine_db_editor/helpers.py b/tests/spine_db_editor/helpers.py
index 116b001f7..658e77105 100644
--- a/tests/spine_db_editor/helpers.py
+++ b/tests/spine_db_editor/helpers.py
@@ -32,8 +32,9 @@ def tearDown(self):
self._common_tear_down()
def _common_setup(self, url, create):
- with mock.patch("spinetoolbox.spine_db_editor.widgets.spine_db_editor.SpineDBEditor.restore_ui"), mock.patch(
- "spinetoolbox.spine_db_editor.widgets.spine_db_editor.SpineDBEditor.show"
+ with (
+ mock.patch("spinetoolbox.spine_db_editor.widgets.spine_db_editor.SpineDBEditor.restore_ui"),
+ mock.patch("spinetoolbox.spine_db_editor.widgets.spine_db_editor.SpineDBEditor.show"),
):
mock_settings = mock.MagicMock()
mock_settings.value.side_effect = lambda *args, **kwargs: 0
@@ -44,9 +45,10 @@ def _common_setup(self, url, create):
QApplication.processEvents()
def _common_tear_down(self):
- with mock.patch(
- "spinetoolbox.spine_db_editor.widgets.spine_db_editor.SpineDBEditor.save_window_state"
- ), mock.patch("spinetoolbox.spine_db_manager.QMessageBox"):
+ with (
+ mock.patch("spinetoolbox.spine_db_editor.widgets.spine_db_editor.SpineDBEditor.save_window_state"),
+ mock.patch("spinetoolbox.spine_db_manager.QMessageBox"),
+ ):
self._db_editor.close()
self._db_mngr.close_all_sessions()
while not self._db_map.closed:
diff --git a/tests/spine_db_editor/mvcmodels/test_alternative_model.py b/tests/spine_db_editor/mvcmodels/test_alternative_model.py
index 84853733f..2471f0cc3 100644
--- a/tests/spine_db_editor/mvcmodels/test_alternative_model.py
+++ b/tests/spine_db_editor/mvcmodels/test_alternative_model.py
@@ -35,8 +35,9 @@ def setUp(self):
self._db_editor = SpineDBEditor(self._db_mngr, {"sqlite://": self.db_codename})
def tearDown(self):
- with patch("spinetoolbox.spine_db_editor.widgets.spine_db_editor.SpineDBEditor.save_window_state"), patch(
- "spinetoolbox.spine_db_editor.widgets.spine_db_editor.QMessageBox"
+ with (
+ patch("spinetoolbox.spine_db_editor.widgets.spine_db_editor.SpineDBEditor.save_window_state"),
+ patch("spinetoolbox.spine_db_editor.widgets.spine_db_editor.QMessageBox"),
):
self._db_editor.close()
self._db_mngr.close_all_sessions()
@@ -135,8 +136,9 @@ def setUp(self):
self._db_editor = SpineDBEditor(self._db_mngr, {"sqlite://": "test_db_1", url2: self.db_codename})
def tearDown(self):
- with patch("spinetoolbox.spine_db_editor.widgets.spine_db_editor.SpineDBEditor.save_window_state"), patch(
- "spinetoolbox.spine_db_editor.widgets.spine_db_editor.QMessageBox"
+ with (
+ patch("spinetoolbox.spine_db_editor.widgets.spine_db_editor.SpineDBEditor.save_window_state"),
+ patch("spinetoolbox.spine_db_editor.widgets.spine_db_editor.QMessageBox"),
):
self._db_editor.close()
self._db_mngr.close_all_sessions()
diff --git a/tests/spine_db_editor/mvcmodels/test_scenario_model.py b/tests/spine_db_editor/mvcmodels/test_scenario_model.py
index 79fa1ab6c..f789ffea3 100644
--- a/tests/spine_db_editor/mvcmodels/test_scenario_model.py
+++ b/tests/spine_db_editor/mvcmodels/test_scenario_model.py
@@ -47,8 +47,9 @@ def setUp(self):
self._db_editor = SpineDBEditor(self._db_mngr, {"sqlite://": self.db_codename})
def tearDown(self):
- with patch("spinetoolbox.spine_db_editor.widgets.spine_db_editor.SpineDBEditor.save_window_state"), patch(
- "spinetoolbox.spine_db_editor.widgets.spine_db_editor.QMessageBox"
+ with (
+ patch("spinetoolbox.spine_db_editor.widgets.spine_db_editor.SpineDBEditor.save_window_state"),
+ patch("spinetoolbox.spine_db_editor.widgets.spine_db_editor.QMessageBox"),
):
self._db_editor.close()
self._db_mngr.close_all_sessions()
@@ -439,8 +440,9 @@ def setUp(self):
self._db_editor = SpineDBEditor(self._db_mngr, {"sqlite://": "test_db_1", url2: "test_db_2"})
def tearDown(self):
- with patch("spinetoolbox.spine_db_editor.widgets.spine_db_editor.SpineDBEditor.save_window_state"), patch(
- "spinetoolbox.spine_db_editor.widgets.spine_db_editor.QMessageBox"
+ with (
+ patch("spinetoolbox.spine_db_editor.widgets.spine_db_editor.SpineDBEditor.save_window_state"),
+ patch("spinetoolbox.spine_db_editor.widgets.spine_db_editor.QMessageBox"),
):
self._db_editor.close()
self._db_mngr.close_all_sessions()
diff --git a/tests/spine_db_editor/test_graphics_items.py b/tests/spine_db_editor/test_graphics_items.py
index 7d0af6977..fdc3a3c1e 100644
--- a/tests/spine_db_editor/test_graphics_items.py
+++ b/tests/spine_db_editor/test_graphics_items.py
@@ -24,8 +24,9 @@ class TestEntityItem(TestCaseWithQApplication):
_db_mngr = None
def setUp(self):
- with mock.patch("spinetoolbox.spine_db_editor.widgets.spine_db_editor.SpineDBEditor.restore_ui"), mock.patch(
- "spinetoolbox.spine_db_editor.widgets.spine_db_editor.SpineDBEditor.show"
+ with (
+ mock.patch("spinetoolbox.spine_db_editor.widgets.spine_db_editor.SpineDBEditor.restore_ui"),
+ mock.patch("spinetoolbox.spine_db_editor.widgets.spine_db_editor.SpineDBEditor.show"),
):
mock_settings = mock.Mock()
mock_settings.value.side_effect = lambda *args, **kwargs: 0
@@ -59,9 +60,12 @@ def tearDownClass(cls):
QApplication.removePostedEvents(None) # Clean up unfinished fetcher signals
def tearDown(self):
- with mock.patch(
- "spinetoolbox.spine_db_editor.widgets.spine_db_editor.SpineDBEditor.save_window_state"
- ) as mock_save_w_s, mock.patch("spinetoolbox.spine_db_manager.QMessageBox"):
+ with (
+ mock.patch(
+ "spinetoolbox.spine_db_editor.widgets.spine_db_editor.SpineDBEditor.save_window_state"
+ ) as mock_save_w_s,
+ mock.patch("spinetoolbox.spine_db_manager.QMessageBox"),
+ ):
self._spine_db_editor.close()
mock_save_w_s.assert_called_once()
self._db_mngr.close_all_sessions()
diff --git a/tests/spine_db_editor/widgets/spine_db_editor_test_base.py b/tests/spine_db_editor/widgets/spine_db_editor_test_base.py
index ca6735ab5..7e04af412 100644
--- a/tests/spine_db_editor/widgets/spine_db_editor_test_base.py
+++ b/tests/spine_db_editor/widgets/spine_db_editor_test_base.py
@@ -23,8 +23,9 @@ class DBEditorTestBase(TestCaseWithQApplication):
def setUp(self):
"""Makes instances of SpineDBEditor classes."""
- with mock.patch("spinetoolbox.spine_db_editor.widgets.spine_db_editor.SpineDBEditor.restore_ui"), mock.patch(
- "spinetoolbox.spine_db_editor.widgets.spine_db_editor.SpineDBEditor.show"
+ with (
+ mock.patch("spinetoolbox.spine_db_editor.widgets.spine_db_editor.SpineDBEditor.restore_ui"),
+ mock.patch("spinetoolbox.spine_db_editor.widgets.spine_db_editor.SpineDBEditor.show"),
):
mock_settings = mock.Mock()
mock_settings.value.side_effect = lambda *args, **kwargs: 0
@@ -36,9 +37,12 @@ def setUp(self):
self.spine_db_editor.entity_tree_model.hide_empty_classes = False
def tearDown(self):
- with mock.patch(
- "spinetoolbox.spine_db_editor.widgets.spine_db_editor.SpineDBEditor.save_window_state"
- ) as mock_save_w_s, mock.patch("spinetoolbox.spine_db_manager.QMessageBox"):
+ with (
+ mock.patch(
+ "spinetoolbox.spine_db_editor.widgets.spine_db_editor.SpineDBEditor.save_window_state"
+ ) as mock_save_w_s,
+ mock.patch("spinetoolbox.spine_db_manager.QMessageBox"),
+ ):
self.spine_db_editor.close()
mock_save_w_s.assert_called_once()
self.db_mngr.close_all_sessions()
diff --git a/tests/spine_db_editor/widgets/test_SpineDBEditor.py b/tests/spine_db_editor/widgets/test_SpineDBEditor.py
index 60a717eac..3de9699f5 100644
--- a/tests/spine_db_editor/widgets/test_SpineDBEditor.py
+++ b/tests/spine_db_editor/widgets/test_SpineDBEditor.py
@@ -255,8 +255,9 @@ def test_stacked_table_empty_row_defaults_are_updated_on_entity_rename(self):
class TestClosingDBEditors(TestCaseWithQApplication):
def setUp(self):
self._editors = []
- with mock.patch("spinetoolbox.spine_db_editor.widgets.spine_db_editor.SpineDBEditor.restore_ui"), mock.patch(
- "spinetoolbox.spine_db_editor.widgets.spine_db_editor.SpineDBEditor.show"
+ with (
+ mock.patch("spinetoolbox.spine_db_editor.widgets.spine_db_editor.SpineDBEditor.restore_ui"),
+ mock.patch("spinetoolbox.spine_db_editor.widgets.spine_db_editor.SpineDBEditor.show"),
):
mock_settings = mock.Mock()
mock_settings.value.side_effect = lambda *args, **kwargs: 0
@@ -282,11 +283,13 @@ def test_first_editor_to_close_does_not_ask_for_confirmation_on_dirty_database(s
editor_2 = self._make_db_editor()
self._db_mngr.add_entity_classes({self._db_map: [{"name": "my_object_class"}]})
self.assertTrue(self._db_mngr.dirty(self._db_map))
- with mock.patch(
- "spinetoolbox.spine_db_editor.widgets.spine_db_editor.SpineDBEditor.save_window_state"
- ), mock.patch("spinetoolbox.spine_db_manager.QMessageBox"), mock.patch(
- "spinetoolbox.spine_db_editor.widgets.spine_db_editor.SpineDBEditor._prompt_to_commit_changes"
- ) as commit_changes:
+ with (
+ mock.patch("spinetoolbox.spine_db_editor.widgets.spine_db_editor.SpineDBEditor.save_window_state"),
+ mock.patch("spinetoolbox.spine_db_manager.QMessageBox"),
+ mock.patch(
+ "spinetoolbox.spine_db_editor.widgets.spine_db_editor.SpineDBEditor._prompt_to_commit_changes"
+ ) as commit_changes,
+ ):
commit_changes.return_value = QMessageBox.StandardButton.Discard
editor_1.close()
commit_changes.assert_not_called()
@@ -299,11 +302,13 @@ def test_editor_asks_for_confirmation_even_when_non_editor_listeners_are_connect
self.assertTrue(self._db_mngr.dirty(self._db_map))
non_editor_listener = object()
self._db_mngr.register_listener(non_editor_listener, self._db_map)
- with mock.patch(
- "spinetoolbox.spine_db_editor.widgets.spine_db_editor.SpineDBEditor.save_window_state"
- ), mock.patch("spinetoolbox.spine_db_manager.QMessageBox"), mock.patch(
- "spinetoolbox.spine_db_editor.widgets.spine_db_editor.SpineDBEditor._prompt_to_commit_changes"
- ) as commit_changes:
+ with (
+ mock.patch("spinetoolbox.spine_db_editor.widgets.spine_db_editor.SpineDBEditor.save_window_state"),
+ mock.patch("spinetoolbox.spine_db_manager.QMessageBox"),
+ mock.patch(
+ "spinetoolbox.spine_db_editor.widgets.spine_db_editor.SpineDBEditor._prompt_to_commit_changes"
+ ) as commit_changes,
+ ):
commit_changes.return_value = QMessageBox.StandardButton.Discard
editor.close()
commit_changes.assert_called_once()
diff --git a/tests/spine_db_editor/widgets/test_SpineDBEditorBase.py b/tests/spine_db_editor/widgets/test_SpineDBEditorBase.py
index f8d790d23..c7dc5ceff 100644
--- a/tests/spine_db_editor/widgets/test_SpineDBEditorBase.py
+++ b/tests/spine_db_editor/widgets/test_SpineDBEditorBase.py
@@ -20,9 +20,11 @@
class TestSpineDBEditorBase(TestCaseWithQApplication):
def setUp(self):
"""Builds a SpineDBEditorBase object."""
- with mock.patch("spinetoolbox.spine_db_worker.DatabaseMapping") as mock_DiffDBMapping, mock.patch(
- "spinetoolbox.spine_db_editor.widgets.spine_db_editor.SpineDBEditor.restore_ui"
- ), mock.patch("spinetoolbox.spine_db_editor.widgets.spine_db_editor.SpineDBEditor.show"):
+ with (
+ mock.patch("spinetoolbox.spine_db_worker.DatabaseMapping") as mock_DiffDBMapping,
+ mock.patch("spinetoolbox.spine_db_editor.widgets.spine_db_editor.SpineDBEditor.restore_ui"),
+ mock.patch("spinetoolbox.spine_db_editor.widgets.spine_db_editor.SpineDBEditor.show"),
+ ):
mock_settings = mock.Mock()
mock_settings.value.side_effect = lambda *args, **kwards: 0
self.db_mngr = TestSpineDBManager(mock_settings, None)
@@ -38,9 +40,10 @@ def DiffDBMapping_side_effect(url, codename=None, upgrade=False, create=False):
def tearDown(self):
"""Frees resources after each test."""
- with mock.patch(
- "spinetoolbox.spine_db_editor.widgets.spine_db_editor.SpineDBEditor.save_window_state"
- ), mock.patch("spinetoolbox.spine_db_manager.QMessageBox"):
+ with (
+ mock.patch("spinetoolbox.spine_db_editor.widgets.spine_db_editor.SpineDBEditor.save_window_state"),
+ mock.patch("spinetoolbox.spine_db_manager.QMessageBox"),
+ ):
self.db_editor._parameter_models = []
self.db_editor.close()
self.db_mngr.close_all_sessions()
@@ -49,25 +52,31 @@ def tearDown(self):
self.db_editor = None
def test_import_file_recognizes_excel(self):
- with mock.patch.object(self.db_editor, "qsettings"), mock.patch.object(
- self.db_editor, "import_from_excel"
- ) as mock_import_from_excel, mock.patch("spinetoolbox.helpers.QFileDialog") as mock_file_dialog:
+ with (
+ mock.patch.object(self.db_editor, "qsettings"),
+ mock.patch.object(self.db_editor, "import_from_excel") as mock_import_from_excel,
+ mock.patch("spinetoolbox.helpers.QFileDialog") as mock_file_dialog,
+ ):
mock_file_dialog.getOpenFileName.return_value = "my_excel_file.xlsx", "Excel files (*.xlsx)"
self.db_editor.import_file()
mock_import_from_excel.assert_called_once_with("my_excel_file.xlsx")
def test_import_file_recognizes_sqlite(self):
- with mock.patch.object(self.db_editor, "qsettings"), mock.patch.object(
- self.db_editor, "import_from_sqlite"
- ) as mock_import_from_sqlite, mock.patch("spinetoolbox.helpers.QFileDialog") as mock_file_dialog:
+ with (
+ mock.patch.object(self.db_editor, "qsettings"),
+ mock.patch.object(self.db_editor, "import_from_sqlite") as mock_import_from_sqlite,
+ mock.patch("spinetoolbox.helpers.QFileDialog") as mock_file_dialog,
+ ):
mock_file_dialog.getOpenFileName.return_value = "my_sqlite_file.sqlite", "SQLite files (*.sqlite)"
self.db_editor.import_file()
mock_import_from_sqlite.assert_called_once_with("my_sqlite_file.sqlite")
def test_import_file_recognizes_json(self):
- with mock.patch.object(self.db_editor, "qsettings"), mock.patch.object(
- self.db_editor, "import_from_json"
- ) as mock_import_from_json, mock.patch("spinetoolbox.helpers.QFileDialog") as mock_file_dialog:
+ with (
+ mock.patch.object(self.db_editor, "qsettings"),
+ mock.patch.object(self.db_editor, "import_from_json") as mock_import_from_json,
+ mock.patch("spinetoolbox.helpers.QFileDialog") as mock_file_dialog,
+ ):
mock_file_dialog.getOpenFileName.return_value = "my_json_file.json", "JSON files (*.json)"
self.db_editor.import_file()
mock_import_from_json.assert_called_once_with("my_json_file.json")
diff --git a/tests/spine_db_editor/widgets/test_SpineDBEditorFilter.py b/tests/spine_db_editor/widgets/test_SpineDBEditorFilter.py
index 0d7841a10..6690d49f5 100644
--- a/tests/spine_db_editor/widgets/test_SpineDBEditorFilter.py
+++ b/tests/spine_db_editor/widgets/test_SpineDBEditorFilter.py
@@ -333,9 +333,10 @@ def test_filtering_with_entity_selections(self):
"""Tests that the graph view filters the entities correctly based on Entity Tree selection"""
entity_tree_view = self.spine_db_editor.ui.treeView_entity
entity_tree_view.expandAll()
- with mock.patch.object(
- self.spine_db_editor.ui.dockWidget_entity_graph, "isVisible", return_value=True
- ), mock.patch.object(self.spine_db_editor.qsettings, "value") as mock_value:
+ with (
+ mock.patch.object(self.spine_db_editor.ui.dockWidget_entity_graph, "isVisible", return_value=True),
+ mock.patch.object(self.spine_db_editor.qsettings, "value") as mock_value,
+ ):
mock_value.side_effect = lambda key, defaultValue: ("false" if key == "appSettings/stickySelection" else 0)
# When nothing selected, no entities should be visible
self.assertFalse(self.spine_db_editor.entity_items)
@@ -383,13 +384,11 @@ def test_filtering_with_entity_selections(self):
def test_filtering_with_alternative_selections(self):
"""Tests that the graph view filters the entities correctly based on Alternative tree selections"""
alternative_tree_view = self.spine_db_editor.ui.alternative_tree_view
- with mock.patch.object(
- self.spine_db_editor.ui.dockWidget_entity_graph, "isVisible", return_value=True
- ), mock.patch.object(
- self.spine_db_editor.ui.dockWidget_parameter_value, "isVisible", return_value=True
- ), mock.patch.object(
- self.spine_db_editor.qsettings, "value"
- ) as mock_value:
+ with (
+ mock.patch.object(self.spine_db_editor.ui.dockWidget_entity_graph, "isVisible", return_value=True),
+ mock.patch.object(self.spine_db_editor.ui.dockWidget_parameter_value, "isVisible", return_value=True),
+ mock.patch.object(self.spine_db_editor.qsettings, "value") as mock_value,
+ ):
mock_value.side_effect = lambda key, defaultValue: ("false" if key == "appSettings/stickySelection" else 0)
# Selecting the root shouldn't do anything
select_item_with_index(alternative_tree_view, self.indexes["alternative_root"])
@@ -425,9 +424,10 @@ def test_filtering_with_entity_and_alternative_selections(self):
"""Tests that the graph view filters the entities correctly based on Entity and Alternative tree selections"""
entity_tree_view = self.spine_db_editor.ui.treeView_entity
alternative_tree_view = self.spine_db_editor.ui.alternative_tree_view
- with mock.patch.object(
- self.spine_db_editor.ui.dockWidget_entity_graph, "isVisible", return_value=True
- ), mock.patch.object(self.spine_db_editor.qsettings, "value") as mock_value:
+ with (
+ mock.patch.object(self.spine_db_editor.ui.dockWidget_entity_graph, "isVisible", return_value=True),
+ mock.patch.object(self.spine_db_editor.qsettings, "value") as mock_value,
+ ):
mock_value.side_effect = lambda key, defaultValue: ("false" if key == "appSettings/stickySelection" else 0)
# Select entity classes A and B along with alternative Alt1.
select_item_with_index(entity_tree_view, self.indexes["entity_class_A"])
@@ -456,9 +456,10 @@ def test_empty_click_clears(self):
"""Tests that a click on empty space in one of the trees clears all selections"""
entity_tree_view = self.spine_db_editor.ui.treeView_entity
alternative_tree_view = self.spine_db_editor.ui.alternative_tree_view
- with mock.patch.object(
- self.spine_db_editor.ui.dockWidget_entity_graph, "isVisible", return_value=True
- ), mock.patch.object(self.spine_db_editor.qsettings, "value") as mock_value:
+ with (
+ mock.patch.object(self.spine_db_editor.ui.dockWidget_entity_graph, "isVisible", return_value=True),
+ mock.patch.object(self.spine_db_editor.qsettings, "value") as mock_value,
+ ):
mock_value.side_effect = lambda key, defaultValue: ("false" if key == "appSettings/stickySelection" else 0)
# Select the entity class A
select_item_with_index(entity_tree_view, self.indexes["entity_class_A"])
@@ -473,9 +474,10 @@ def test_filtering_with_scenario_selections(self):
"""Tests that the graph view filters the entities correctly based on Scenario tree selections"""
scenario_tree_view = self.spine_db_editor.ui.scenario_tree_view
scenario_tree_view.expandAll()
- with mock.patch.object(
- self.spine_db_editor.ui.dockWidget_entity_graph, "isVisible", return_value=True
- ), mock.patch.object(self.spine_db_editor.qsettings, "value") as mock_value:
+ with (
+ mock.patch.object(self.spine_db_editor.ui.dockWidget_entity_graph, "isVisible", return_value=True),
+ mock.patch.object(self.spine_db_editor.qsettings, "value") as mock_value,
+ ):
mock_value.side_effect = lambda key, defaultValue: ("false" if key == "appSettings/stickySelection" else 0)
# When nothing selected, no entities should be visible
self.assertFalse(self.spine_db_editor.entity_items)
@@ -524,9 +526,10 @@ def test_scenario_deselection_with_ctrl_is_consistent(self):
"""Tests that deselection with ctrl pressed is consistent"""
scenario_tree_view = self.spine_db_editor.ui.scenario_tree_view
scenario_tree_view.expandAll()
- with mock.patch.object(
- self.spine_db_editor.ui.dockWidget_entity_graph, "isVisible", return_value=True
- ), mock.patch.object(self.spine_db_editor.qsettings, "value") as mock_value:
+ with (
+ mock.patch.object(self.spine_db_editor.ui.dockWidget_entity_graph, "isVisible", return_value=True),
+ mock.patch.object(self.spine_db_editor.qsettings, "value") as mock_value,
+ ):
mock_value.side_effect = lambda key, defaultValue: ("false" if key == "appSettings/stickySelection" else 0)
# When nothing selected, no entities should be visible
self.assertFalse(self.spine_db_editor.entity_items)
@@ -579,9 +582,10 @@ def test_filtering_with_entity_selections_with_auto_expand(self):
auto-expand is enabled"""
self.gv.set_property("auto_expand_entities", True)
entity_tree_view = self.spine_db_editor.ui.treeView_entity
- with mock.patch.object(
- self.spine_db_editor.ui.dockWidget_entity_graph, "isVisible", return_value=True
- ), mock.patch.object(self.spine_db_editor.qsettings, "value") as mock_value:
+ with (
+ mock.patch.object(self.spine_db_editor.ui.dockWidget_entity_graph, "isVisible", return_value=True),
+ mock.patch.object(self.spine_db_editor.qsettings, "value") as mock_value,
+ ):
mock_value.side_effect = lambda key, defaultValue: ("false" if key == "appSettings/stickySelection" else 0)
# When nothing selected, no entities should be visible
self.assertFalse(self.spine_db_editor.entity_items)
@@ -620,9 +624,10 @@ def test_filtering_with_entity_and_alternative_selections_with_auto_expand(self)
entity_tree_view = self.spine_db_editor.ui.treeView_entity
entity_tree_view.expandAll()
alternative_tree_view = self.spine_db_editor.ui.alternative_tree_view
- with mock.patch.object(
- self.spine_db_editor.ui.dockWidget_entity_graph, "isVisible", return_value=True
- ), mock.patch.object(self.spine_db_editor.qsettings, "value") as mock_value:
+ with (
+ mock.patch.object(self.spine_db_editor.ui.dockWidget_entity_graph, "isVisible", return_value=True),
+ mock.patch.object(self.spine_db_editor.qsettings, "value") as mock_value,
+ ):
mock_value.side_effect = lambda key, defaultValue: ("false" if key == "appSettings/stickySelection" else 0)
# Select entity ba
select_item_with_index(entity_tree_view, self.indexes["entity_ba"])
@@ -649,9 +654,10 @@ def test_filtering_with_entity_and_alternative_selections_with_auto_expand(self)
def test_start_connecting_entities(self):
entity_tree_view = self.spine_db_editor.ui.treeView_entity
- with mock.patch.object(
- self.spine_db_editor.ui.dockWidget_entity_graph, "isVisible", return_value=True
- ), mock.patch.object(self.spine_db_editor.qsettings, "value") as mock_value:
+ with (
+ mock.patch.object(self.spine_db_editor.ui.dockWidget_entity_graph, "isVisible", return_value=True),
+ mock.patch.object(self.spine_db_editor.qsettings, "value") as mock_value,
+ ):
mock_value.side_effect = lambda key, defaultValue: ("false" if key == "appSettings/stickySelection" else 0)
select_item_with_index(entity_tree_view, self.indexes["entity_root"])
entity_tree_view.fully_expand()
@@ -680,9 +686,10 @@ def test_consistent_across_different_selection_order(self):
entity_tree_view = self.spine_db_editor.ui.treeView_entity
alternative_tree_view = self.spine_db_editor.ui.alternative_tree_view
entity_tree_view.expandAll()
- with mock.patch.object(
- self.spine_db_editor.ui.dockWidget_entity_graph, "isVisible", return_value=True
- ), mock.patch.object(self.spine_db_editor.qsettings, "value") as mock_value:
+ with (
+ mock.patch.object(self.spine_db_editor.ui.dockWidget_entity_graph, "isVisible", return_value=True),
+ mock.patch.object(self.spine_db_editor.qsettings, "value") as mock_value,
+ ):
mock_value.side_effect = lambda key, defaultValue: ("false" if key == "appSettings/stickySelection" else 0)
# Select entity classes A then B then Alt1.
select_item_with_index(entity_tree_view, self.indexes["entity_class_A"])
diff --git a/tests/spine_db_editor/widgets/test_SpineDBEditorWithDBMapping.py b/tests/spine_db_editor/widgets/test_SpineDBEditorWithDBMapping.py
index 38553246d..0a3ef06e2 100644
--- a/tests/spine_db_editor/widgets/test_SpineDBEditorWithDBMapping.py
+++ b/tests/spine_db_editor/widgets/test_SpineDBEditorWithDBMapping.py
@@ -26,8 +26,9 @@ def setUp(self):
"""Overridden method. Runs before each test. Makes instances of SpineDBEditor classes."""
self._temp_dir = TemporaryDirectory()
url = "sqlite:///" + os.path.join(self._temp_dir.name, "test.sqlite")
- with mock.patch("spinetoolbox.spine_db_editor.widgets.spine_db_editor.SpineDBEditor.restore_ui"), mock.patch(
- "spinetoolbox.spine_db_editor.widgets.spine_db_editor.SpineDBEditor.show"
+ with (
+ mock.patch("spinetoolbox.spine_db_editor.widgets.spine_db_editor.SpineDBEditor.restore_ui"),
+ mock.patch("spinetoolbox.spine_db_editor.widgets.spine_db_editor.SpineDBEditor.show"),
):
mock_settings = mock.Mock()
mock_settings.value.side_effect = lambda *args, **kwards: 0
@@ -41,9 +42,12 @@ def tearDown(self):
"""Overridden method. Runs after each test.
Use this to free resources after a test if needed.
"""
- with mock.patch(
- "spinetoolbox.spine_db_editor.widgets.spine_db_editor.SpineDBEditor.save_window_state"
- ) as mock_save_w_s, mock.patch("spinetoolbox.spine_db_manager.QMessageBox"):
+ with (
+ mock.patch(
+ "spinetoolbox.spine_db_editor.widgets.spine_db_editor.SpineDBEditor.save_window_state"
+ ) as mock_save_w_s,
+ mock.patch("spinetoolbox.spine_db_manager.QMessageBox"),
+ ):
self.spine_db_editor.close()
mock_save_w_s.assert_called_once()
QApplication.removePostedEvents(None) # Clean up unfinished fetcher signals
diff --git a/tests/spine_db_editor/widgets/test_add_items_dialog.py b/tests/spine_db_editor/widgets/test_add_items_dialog.py
index dd021f2b5..5d86717b7 100644
--- a/tests/spine_db_editor/widgets/test_add_items_dialog.py
+++ b/tests/spine_db_editor/widgets/test_add_items_dialog.py
@@ -44,9 +44,10 @@ def tearDown(self):
"""Overridden method. Runs after each test.
Use this to free resources after a test if needed.
"""
- with mock.patch(
- "spinetoolbox.spine_db_editor.widgets.spine_db_editor.SpineDBEditor.save_window_state"
- ), mock.patch("spinetoolbox.spine_db_manager.QMessageBox"):
+ with (
+ mock.patch("spinetoolbox.spine_db_editor.widgets.spine_db_editor.SpineDBEditor.save_window_state"),
+ mock.patch("spinetoolbox.spine_db_manager.QMessageBox"),
+ ):
self._db_editor.close()
self._db_mngr.close_all_sessions()
while not self._db_map.closed:
diff --git a/tests/spine_db_editor/widgets/test_mass_select_items_dialogs.py b/tests/spine_db_editor/widgets/test_mass_select_items_dialogs.py
index d9290bd3f..af08dd5f8 100644
--- a/tests/spine_db_editor/widgets/test_mass_select_items_dialogs.py
+++ b/tests/spine_db_editor/widgets/test_mass_select_items_dialogs.py
@@ -22,8 +22,9 @@
class TestMassRemoveItemsDialog(TestCaseWithQApplication):
def setUp(self):
url = "sqlite:///"
- with mock.patch("spinetoolbox.spine_db_editor.widgets.spine_db_editor.SpineDBEditor.restore_ui"), mock.patch(
- "spinetoolbox.spine_db_editor.widgets.spine_db_editor.SpineDBEditor.show"
+ with (
+ mock.patch("spinetoolbox.spine_db_editor.widgets.spine_db_editor.SpineDBEditor.restore_ui"),
+ mock.patch("spinetoolbox.spine_db_editor.widgets.spine_db_editor.SpineDBEditor.show"),
):
mock_settings = mock.Mock()
mock_settings.value.side_effect = lambda *args, **kwargs: 0
diff --git a/tests/test_ProjectUpgrader.py b/tests/test_ProjectUpgrader.py
index 563f53e16..433ed4dcb 100644
--- a/tests/test_ProjectUpgrader.py
+++ b/tests/test_ProjectUpgrader.py
@@ -119,15 +119,12 @@ def test_upgrade_v1_to_v2(self):
proj_v1 = make_v1_project_dict()
self.assertTrue(pu.is_valid(1, proj_v1))
with TemporaryDirectory() as project_dir:
- with mock.patch(
- "spinetoolbox.project_upgrader.ProjectUpgrader.backup_project_file"
- ) as mock_backup, mock.patch(
- "spinetoolbox.project_upgrader.ProjectUpgrader.force_save"
- ) as mock_force_save, mock.patch(
- "spinetoolbox.project_upgrader.LATEST_PROJECT_VERSION", 2
- ), mock.patch(
- "spinetoolbox.project_upgrader.QMessageBox.question"
- ) as mock_mb:
+ with (
+ mock.patch("spinetoolbox.project_upgrader.ProjectUpgrader.backup_project_file") as mock_backup,
+ mock.patch("spinetoolbox.project_upgrader.ProjectUpgrader.force_save") as mock_force_save,
+ mock.patch("spinetoolbox.project_upgrader.LATEST_PROJECT_VERSION", 2),
+ mock.patch("spinetoolbox.project_upgrader.QMessageBox.question") as mock_mb,
+ ):
# Upgrade to version 2
mock_mb.return_value = QMessageBox.StandardButton.Yes
proj_v2 = pu.upgrade(proj_v1, project_dir)
@@ -150,15 +147,12 @@ def test_upgrade_v2_to_v3(self):
proj_v2 = make_v2_project_dict()
self.assertTrue(pu.is_valid(2, proj_v2))
with TemporaryDirectory() as project_dir:
- with mock.patch(
- "spinetoolbox.project_upgrader.ProjectUpgrader.backup_project_file"
- ) as mock_backup, mock.patch(
- "spinetoolbox.project_upgrader.ProjectUpgrader.force_save"
- ) as mock_force_save, mock.patch(
- "spinetoolbox.project_upgrader.LATEST_PROJECT_VERSION", 3
- ), mock.patch(
- "spinetoolbox.project_upgrader.QMessageBox.question"
- ) as mock_mb:
+ with (
+ mock.patch("spinetoolbox.project_upgrader.ProjectUpgrader.backup_project_file") as mock_backup,
+ mock.patch("spinetoolbox.project_upgrader.ProjectUpgrader.force_save") as mock_force_save,
+ mock.patch("spinetoolbox.project_upgrader.LATEST_PROJECT_VERSION", 3),
+ mock.patch("spinetoolbox.project_upgrader.QMessageBox.question") as mock_mb,
+ ):
mock_mb.return_value = QMessageBox.StandardButton.Yes
os.mkdir(os.path.join(project_dir, "tool_specs")) # Make /tool_specs dir
# Make temp preprocessing_tool.json tool spec file
@@ -184,15 +178,12 @@ def test_upgrade_v3_to_v4(self):
proj_v3 = make_v3_project_dict()
self.assertTrue(pu.is_valid(3, proj_v3))
with TemporaryDirectory() as project_dir:
- with mock.patch(
- "spinetoolbox.project_upgrader.ProjectUpgrader.backup_project_file"
- ) as mock_backup, mock.patch(
- "spinetoolbox.project_upgrader.ProjectUpgrader.force_save"
- ) as mock_force_save, mock.patch(
- "spinetoolbox.project_upgrader.LATEST_PROJECT_VERSION", 4
- ), mock.patch(
- "spinetoolbox.project_upgrader.QMessageBox.question"
- ) as mock_mb:
+ with (
+ mock.patch("spinetoolbox.project_upgrader.ProjectUpgrader.backup_project_file") as mock_backup,
+ mock.patch("spinetoolbox.project_upgrader.ProjectUpgrader.force_save") as mock_force_save,
+ mock.patch("spinetoolbox.project_upgrader.LATEST_PROJECT_VERSION", 4),
+ mock.patch("spinetoolbox.project_upgrader.QMessageBox.question") as mock_mb,
+ ):
mock_mb.return_value = QMessageBox.StandardButton.Yes
os.mkdir(os.path.join(project_dir, "tool_specs")) # Make /tool_specs dir
# Make temp preprocessing_tool.json tool spec file
@@ -218,15 +209,12 @@ def test_upgrade_v4_to_v5(self):
proj_v4 = make_v4_project_dict()
self.assertTrue(pu.is_valid(4, proj_v4))
with TemporaryDirectory() as project_dir:
- with mock.patch(
- "spinetoolbox.project_upgrader.ProjectUpgrader.backup_project_file"
- ) as mock_backup, mock.patch(
- "spinetoolbox.project_upgrader.ProjectUpgrader.force_save"
- ) as mock_force_save, mock.patch(
- "spinetoolbox.project_upgrader.LATEST_PROJECT_VERSION", 5
- ), mock.patch(
- "spinetoolbox.project_upgrader.QMessageBox.question"
- ) as mock_mb:
+ with (
+ mock.patch("spinetoolbox.project_upgrader.ProjectUpgrader.backup_project_file") as mock_backup,
+ mock.patch("spinetoolbox.project_upgrader.ProjectUpgrader.force_save") as mock_force_save,
+ mock.patch("spinetoolbox.project_upgrader.LATEST_PROJECT_VERSION", 5),
+ mock.patch("spinetoolbox.project_upgrader.QMessageBox.question") as mock_mb,
+ ):
mock_mb.return_value = QMessageBox.StandardButton.Yes
os.mkdir(os.path.join(project_dir, "tool_specs")) # Make /tool_specs dir
# Make temp preprocessing_tool.json tool spec file
@@ -261,15 +249,12 @@ def test_upgrade_v9_to_v10(self):
proj_v9 = make_v9_project_dict()
self.assertTrue(pu.is_valid(9, proj_v9))
with TemporaryDirectory() as project_dir:
- with mock.patch(
- "spinetoolbox.project_upgrader.ProjectUpgrader.backup_project_file"
- ) as mock_backup, mock.patch(
- "spinetoolbox.project_upgrader.ProjectUpgrader.force_save"
- ) as mock_force_save, mock.patch(
- "spinetoolbox.project_upgrader.LATEST_PROJECT_VERSION", 10
- ), mock.patch(
- "spinetoolbox.project_upgrader.QMessageBox.question"
- ) as mock_mb:
+ with (
+ mock.patch("spinetoolbox.project_upgrader.ProjectUpgrader.backup_project_file") as mock_backup,
+ mock.patch("spinetoolbox.project_upgrader.ProjectUpgrader.force_save") as mock_force_save,
+ mock.patch("spinetoolbox.project_upgrader.LATEST_PROJECT_VERSION", 10),
+ mock.patch("spinetoolbox.project_upgrader.QMessageBox.question") as mock_mb,
+ ):
mock_mb.return_value = QMessageBox.StandardButton.Yes
os.mkdir(os.path.join(project_dir, "tool_specs")) # Make /tool_specs dir
# Make temp preprocessing_tool.json tool spec file
@@ -305,15 +290,12 @@ def test_upgrade_v10_to_v11(self):
proj_v10 = make_v10_project_dict()
self.assertTrue(pu.is_valid(10, proj_v10))
with TemporaryDirectory() as project_dir:
- with mock.patch(
- "spinetoolbox.project_upgrader.ProjectUpgrader.backup_project_file"
- ) as mock_backup, mock.patch(
- "spinetoolbox.project_upgrader.ProjectUpgrader.force_save"
- ) as mock_force_save, mock.patch(
- "spinetoolbox.project_upgrader.LATEST_PROJECT_VERSION", 11
- ), mock.patch(
- "spinetoolbox.project_upgrader.QMessageBox.question"
- ) as mock_mb:
+ with (
+ mock.patch("spinetoolbox.project_upgrader.ProjectUpgrader.backup_project_file") as mock_backup,
+ mock.patch("spinetoolbox.project_upgrader.ProjectUpgrader.force_save") as mock_force_save,
+ mock.patch("spinetoolbox.project_upgrader.LATEST_PROJECT_VERSION", 11),
+ mock.patch("spinetoolbox.project_upgrader.QMessageBox.question") as mock_mb,
+ ):
mock_mb.return_value = QMessageBox.StandardButton.Yes
os.mkdir(os.path.join(project_dir, "tool_specs")) # Make /tool_specs dir
proj_v11 = pu.upgrade(proj_v10, project_dir)
@@ -333,15 +315,12 @@ def test_upgrade_v11_to_v12(self):
proj_v11 = make_v11_project_dict()
self.assertTrue(pu.is_valid(11, proj_v11))
with TemporaryDirectory() as project_dir:
- with mock.patch(
- "spinetoolbox.project_upgrader.ProjectUpgrader.backup_project_file"
- ) as mock_backup, mock.patch(
- "spinetoolbox.project_upgrader.ProjectUpgrader.force_save"
- ) as mock_force_save, mock.patch(
- "spinetoolbox.project_upgrader.LATEST_PROJECT_VERSION", 12
- ), mock.patch(
- "spinetoolbox.project_upgrader.QMessageBox.question"
- ) as mock_mb:
+ with (
+ mock.patch("spinetoolbox.project_upgrader.ProjectUpgrader.backup_project_file") as mock_backup,
+ mock.patch("spinetoolbox.project_upgrader.ProjectUpgrader.force_save") as mock_force_save,
+ mock.patch("spinetoolbox.project_upgrader.LATEST_PROJECT_VERSION", 12),
+ mock.patch("spinetoolbox.project_upgrader.QMessageBox.question") as mock_mb,
+ ):
mock_mb.return_value = QMessageBox.StandardButton.Yes
os.mkdir(os.path.join(project_dir, "tool_specs")) # Make /tool_specs dir
proj_v12 = pu.upgrade(proj_v11, project_dir)
@@ -357,13 +336,11 @@ def test_upgrade_v1_to_latest(self):
proj_v1 = make_v1_project_dict()
self.assertTrue(pu.is_valid(1, proj_v1))
with TemporaryDirectory() as project_dir:
- with mock.patch(
- "spinetoolbox.project_upgrader.ProjectUpgrader.backup_project_file"
- ) as mock_backup, mock.patch(
- "spinetoolbox.project_upgrader.ProjectUpgrader.force_save"
- ) as mock_force_save, mock.patch(
- "spinetoolbox.project_upgrader.QMessageBox.question"
- ) as mock_mb:
+ with (
+ mock.patch("spinetoolbox.project_upgrader.ProjectUpgrader.backup_project_file") as mock_backup,
+ mock.patch("spinetoolbox.project_upgrader.ProjectUpgrader.force_save") as mock_force_save,
+ mock.patch("spinetoolbox.project_upgrader.QMessageBox.question") as mock_mb,
+ ):
mock_mb.return_value = QMessageBox.StandardButton.Yes
os.mkdir(os.path.join(project_dir, "tool_specs")) # Make /tool_specs dir
# Make temp preprocessing_tool.json tool spec file
diff --git a/tests/test_SpineDBManager.py b/tests/test_SpineDBManager.py
index 34c44635f..fc908e693 100644
--- a/tests/test_SpineDBManager.py
+++ b/tests/test_SpineDBManager.py
@@ -410,6 +410,7 @@ def setUp(self):
self._db_mngr = SpineDBManager(QSettings(), None)
self._logger = MagicMock()
+ @unittest.skip("FIXME")
def test_open_db_editor(self):
editors = list(self._db_mngr.get_all_multi_spine_db_editors())
self.assertFalse(editors)
diff --git a/tests/test_SpineToolboxProject.py b/tests/test_SpineToolboxProject.py
index d4e638155..df26f9115 100644
--- a/tests/test_SpineToolboxProject.py
+++ b/tests/test_SpineToolboxProject.py
@@ -249,9 +249,10 @@ def _execute_project(self, names=None):
"""
waiter = SignalWaiter()
self.toolbox.project().project_execution_finished.connect(waiter.trigger)
- with mock.patch("spinetoolbox.ui_main.QSettings.value") as mock_qsettings_value, mock.patch(
- "spinetoolbox.project.make_settings_dict_for_engine"
- ) as mock_settings_dict:
+ with (
+ mock.patch("spinetoolbox.ui_main.QSettings.value") as mock_qsettings_value,
+ mock.patch("spinetoolbox.project.make_settings_dict_for_engine") as mock_settings_dict,
+ ):
# Make sure that the test uses LocalSpineEngineManager
# This mocks the check for engineSettings/remoteEngineEnabled in SpineToolboxProject.execute_dags()
mock_qsettings_value.side_effect = qsettings_value_side_effect
@@ -557,8 +558,9 @@ def test_update_connection(self):
def test_save_when_storing_item_local_data(self):
project = self.toolbox.project()
item = _MockItemWithLocalData(project)
- with mock.patch.object(self.toolbox, "project_item_properties_ui"), mock.patch.object(
- self.toolbox, "project_item_icon"
+ with (
+ mock.patch.object(self.toolbox, "project_item_properties_ui"),
+ mock.patch.object(self.toolbox, "project_item_icon"),
):
project.add_item(item)
project.save()
@@ -585,16 +587,19 @@ def test_save_when_storing_item_local_data(self):
def test_load_when_storing_item_local_data(self):
project = self.toolbox.project()
item = _MockItemWithLocalData(project)
- with mock.patch.object(self.toolbox, "project_item_properties_ui"), mock.patch.object(
- self.toolbox, "project_item_icon"
+ with (
+ mock.patch.object(self.toolbox, "project_item_properties_ui"),
+ mock.patch.object(self.toolbox, "project_item_icon"),
):
project.add_item(item)
project.save()
self.assertTrue(self.toolbox.close_project(ask_confirmation=False))
self.toolbox.item_factories = {"Tester": _MockItemFactoryForLocalDataTests()}
- with mock.patch.object(self.toolbox, "update_recent_projects"), mock.patch.object(
- self.toolbox, "project_item_properties_ui"
- ), mock.patch.object(self.toolbox, "project_item_icon"):
+ with (
+ mock.patch.object(self.toolbox, "update_recent_projects"),
+ mock.patch.object(self.toolbox, "project_item_properties_ui"),
+ mock.patch.object(self.toolbox, "project_item_icon"),
+ ):
self.assertTrue(self.toolbox.restore_project(self._temp_dir.name, ask_confirmation=False))
item = self.toolbox.project().get_item("test item")
self.assertEqual(item.kwargs, {"type": "Tester", "a": {"b": 1, "c": 2, "d": 3}})
@@ -603,9 +608,10 @@ def test_add_and_save_specification(self):
project = self.toolbox.project()
self.toolbox.item_factories = {"Tester": ProjectItemFactory()}
specification = _MockSpecification("a specification", "Specification for testing.", "Tester")
- with mock.patch.object(ProjectItemFactory, "icon") as mock_icon, mock.patch.object(
- ProjectItemFactory, "icon_color"
- ) as mock_icon_color:
+ with (
+ mock.patch.object(ProjectItemFactory, "icon") as mock_icon,
+ mock.patch.object(ProjectItemFactory, "icon_color") as mock_icon_color,
+ ):
mock_icon.return_value = ":/icons/item_icons/hammer.svg"
mock_icon_color.return_value = QColor("white")
project.add_specification(specification)
@@ -629,9 +635,10 @@ def test_add_and_save_specification_with_local_data(self):
specification = _MockSpecificationWithLocalData(
"a specification", "Specification for testing.", "Tester", "my precious data"
)
- with mock.patch.object(ProjectItemFactory, "icon") as mock_icon, mock.patch.object(
- ProjectItemFactory, "icon_color"
- ) as mock_icon_color:
+ with (
+ mock.patch.object(ProjectItemFactory, "icon") as mock_icon,
+ mock.patch.object(ProjectItemFactory, "icon_color") as mock_icon_color,
+ ):
mock_icon.return_value = ":/icons/item_icons/hammer.svg"
mock_icon_color.return_value = QColor("white")
project.add_specification(specification)
@@ -662,9 +669,10 @@ def test_renaming_specification_with_local_data_updates_local_data_file(self):
original_specification = _MockSpecificationWithLocalData(
"a specification", "Specification for testing.", "Tester", "my precious data"
)
- with mock.patch.object(ProjectItemFactory, "icon") as mock_icon, mock.patch.object(
- ProjectItemFactory, "icon_color"
- ) as mock_icon_color:
+ with (
+ mock.patch.object(ProjectItemFactory, "icon") as mock_icon,
+ mock.patch.object(ProjectItemFactory, "icon_color") as mock_icon_color,
+ ):
mock_icon.return_value = ":/icons/item_icons/hammer.svg"
mock_icon_color.return_value = QColor("white")
project.add_specification(original_specification)
@@ -697,9 +705,10 @@ def test_replace_specification_with_local_data_by_one_without_removes_local_data
specification_with_local_data = _MockSpecificationWithLocalData(
"a specification", "Specification for testing.", "Tester", "my precious data"
)
- with mock.patch.object(ProjectItemFactory, "icon") as mock_icon, mock.patch.object(
- ProjectItemFactory, "icon_color"
- ) as mock_icon_color:
+ with (
+ mock.patch.object(ProjectItemFactory, "icon") as mock_icon,
+ mock.patch.object(ProjectItemFactory, "icon_color") as mock_icon_color,
+ ):
mock_icon.return_value = ":/icons/item_icons/hammer.svg"
mock_icon_color.return_value = QColor("white")
project.add_specification(specification_with_local_data)
diff --git a/tests/test_ToolboxUI.py b/tests/test_ToolboxUI.py
index 9c7f86703..b7a965640 100644
--- a/tests/test_ToolboxUI.py
+++ b/tests/test_ToolboxUI.py
@@ -91,10 +91,11 @@ def test_open_project(self):
project_dir = os.path.abspath(os.path.join(str(Path(__file__).parent), "test_resources", "Project Directory"))
self.assertTrue(os.path.exists(project_dir))
self.assertIsNone(self.toolbox.project())
- with mock.patch("spinetoolbox.ui_main.ToolboxUI.save_project"), mock.patch(
- "spinetoolbox.project.create_dir"
- ), mock.patch("spinetoolbox.project_item.project_item.create_dir"), mock.patch(
- "spinetoolbox.ui_main.ToolboxUI.update_recent_projects"
+ with (
+ mock.patch("spinetoolbox.ui_main.ToolboxUI.save_project"),
+ mock.patch("spinetoolbox.project.create_dir"),
+ mock.patch("spinetoolbox.project_item.project_item.create_dir"),
+ mock.patch("spinetoolbox.ui_main.ToolboxUI.update_recent_projects"),
):
self.toolbox.open_project(project_dir)
self.assertIsInstance(self.toolbox.project(), SpineToolboxProject)
@@ -149,10 +150,11 @@ def test_init_project(self):
project_dir = os.path.abspath(os.path.join(str(Path(__file__).parent), "test_resources", "Project Directory"))
self.assertTrue(os.path.exists(project_dir))
self.assertIsNone(self.toolbox.project())
- with mock.patch("spinetoolbox.ui_main.ToolboxUI.save_project"), mock.patch(
- "spinetoolbox.project.create_dir"
- ), mock.patch("spinetoolbox.project_item.project_item.create_dir"), mock.patch(
- "spinetoolbox.ui_main.ToolboxUI.update_recent_projects"
+ with (
+ mock.patch("spinetoolbox.ui_main.ToolboxUI.save_project"),
+ mock.patch("spinetoolbox.project.create_dir"),
+ mock.patch("spinetoolbox.project_item.project_item.create_dir"),
+ mock.patch("spinetoolbox.ui_main.ToolboxUI.update_recent_projects"),
):
self.toolbox.init_project(project_dir)
self.assertIsNotNone(self.toolbox.project())
@@ -160,9 +162,11 @@ def test_init_project(self):
def test_new_project(self):
self._temp_dir = TemporaryDirectory()
- with mock.patch("spinetoolbox.ui_main.QSettings.setValue"), mock.patch(
- "spinetoolbox.ui_main.QSettings.sync"
- ), mock.patch("PySide6.QtWidgets.QFileDialog.getExistingDirectory") as mock_dir_getter:
+ with (
+ mock.patch("spinetoolbox.ui_main.QSettings.setValue"),
+ mock.patch("spinetoolbox.ui_main.QSettings.sync"),
+ mock.patch("PySide6.QtWidgets.QFileDialog.getExistingDirectory") as mock_dir_getter,
+ ):
mock_dir_getter.return_value = self._temp_dir.name
self.toolbox.new_project()
self.assertIsNotNone(self.toolbox.project())
@@ -170,9 +174,11 @@ def test_new_project(self):
def test_save_project(self):
self._temp_dir = TemporaryDirectory()
- with mock.patch("spinetoolbox.ui_main.QSettings.setValue"), mock.patch(
- "spinetoolbox.ui_main.QSettings.sync"
- ), mock.patch("PySide6.QtWidgets.QFileDialog.getExistingDirectory") as mock_dir_getter:
+ with (
+ mock.patch("spinetoolbox.ui_main.QSettings.setValue"),
+ mock.patch("spinetoolbox.ui_main.QSettings.sync"),
+ mock.patch("PySide6.QtWidgets.QFileDialog.getExistingDirectory") as mock_dir_getter,
+ ):
mock_dir_getter.return_value = self._temp_dir.name
self.toolbox.new_project()
add_dc_trough_undo_stack(self.toolbox, "DC")
@@ -184,10 +190,11 @@ def test_save_project(self):
mock_qsettings_value.side_effect = qsettings_value_side_effect
self.assertTrue(self.toolbox.close_project())
mock_qsettings_value.assert_called()
- with mock.patch("spinetoolbox.ui_main.ToolboxUI.save_project"), mock.patch(
- "spinetoolbox.project.create_dir"
- ), mock.patch("spinetoolbox.project_item.project_item.create_dir"), mock.patch(
- "spinetoolbox.ui_main.ToolboxUI.update_recent_projects"
+ with (
+ mock.patch("spinetoolbox.ui_main.ToolboxUI.save_project"),
+ mock.patch("spinetoolbox.project.create_dir"),
+ mock.patch("spinetoolbox.project_item.project_item.create_dir"),
+ mock.patch("spinetoolbox.ui_main.ToolboxUI.update_recent_projects"),
):
self.toolbox.open_project(self._temp_dir.name)
self.assertIsNotNone(self.toolbox.project())
@@ -195,9 +202,11 @@ def test_save_project(self):
def test_prevent_project_closing_with_unsaved_changes(self):
self._temp_dir = TemporaryDirectory()
- with mock.patch("spinetoolbox.ui_main.QSettings.setValue"), mock.patch(
- "spinetoolbox.ui_main.QSettings.sync"
- ), mock.patch("PySide6.QtWidgets.QFileDialog.getExistingDirectory") as mock_dir_getter:
+ with (
+ mock.patch("spinetoolbox.ui_main.QSettings.setValue"),
+ mock.patch("spinetoolbox.ui_main.QSettings.sync"),
+ mock.patch("PySide6.QtWidgets.QFileDialog.getExistingDirectory") as mock_dir_getter,
+ ):
mock_dir_getter.return_value = self._temp_dir.name
self.toolbox.new_project()
add_dc_trough_undo_stack(self.toolbox, "DC1")
@@ -213,12 +222,12 @@ def test_prevent_project_closing_with_unsaved_changes(self):
with mock.patch.object(QMessageBox, "exec", return_value=QMessageBox.Cancel):
self.assertFalse(self.toolbox.close_project())
mock_qsettings_value.assert_called()
- with mock.patch("spinetoolbox.ui_main.ToolboxUI.save_project"), mock.patch(
- "spinetoolbox.project.create_dir"
- ), mock.patch("spinetoolbox.project_item.project_item.create_dir"), mock.patch(
- "spinetoolbox.ui_main.ToolboxUI.update_recent_projects"
- ), mock.patch.object(
- QMessageBox, "exec", return_value=QMessageBox.Cancel
+ with (
+ mock.patch("spinetoolbox.ui_main.ToolboxUI.save_project"),
+ mock.patch("spinetoolbox.project.create_dir"),
+ mock.patch("spinetoolbox.project_item.project_item.create_dir"),
+ mock.patch("spinetoolbox.ui_main.ToolboxUI.update_recent_projects"),
+ mock.patch.object(QMessageBox, "exec", return_value=QMessageBox.Cancel),
):
# Selecting cancel on the project close confirmation
with mock.patch("spinetoolbox.ui_main.ToolboxUI.add_warning_message") as warning_msg:
@@ -247,9 +256,11 @@ def test_close_project(self):
def test_show_project_or_item_context_menu(self):
self._temp_dir = TemporaryDirectory()
- with mock.patch("spinetoolbox.ui_main.QSettings.setValue") as mock_set_value, mock.patch(
- "spinetoolbox.ui_main.QSettings.sync"
- ) as mock_sync, mock.patch("PySide6.QtWidgets.QFileDialog.getExistingDirectory") as mock_dir_getter:
+ with (
+ mock.patch("spinetoolbox.ui_main.QSettings.setValue") as mock_set_value,
+ mock.patch("spinetoolbox.ui_main.QSettings.sync") as mock_sync,
+ mock.patch("PySide6.QtWidgets.QFileDialog.getExistingDirectory") as mock_dir_getter,
+ ):
mock_dir_getter.return_value = self._temp_dir.name
self.toolbox.new_project()
mock_set_value.assert_called()
@@ -277,9 +288,11 @@ def test_refresh_edit_action_states(self):
self.assertFalse(self.toolbox.ui.actionRemove_all.isEnabled())
# Make project
self._temp_dir = TemporaryDirectory()
- with mock.patch("spinetoolbox.ui_main.QSettings.setValue") as mock_set_value, mock.patch(
- "spinetoolbox.ui_main.QSettings.sync"
- ) as mock_sync, mock.patch("PySide6.QtWidgets.QFileDialog.getExistingDirectory") as mock_dir_getter:
+ with (
+ mock.patch("spinetoolbox.ui_main.QSettings.setValue") as mock_set_value,
+ mock.patch("spinetoolbox.ui_main.QSettings.sync") as mock_sync,
+ mock.patch("PySide6.QtWidgets.QFileDialog.getExistingDirectory") as mock_dir_getter,
+ ):
mock_dir_getter.return_value = self._temp_dir.name
self.toolbox.new_project()
mock_set_value.assert_called()
@@ -474,11 +487,11 @@ def test_drop_invalid_drag_on_design_view(self):
gv = self.toolbox.ui.graphicsView
pos = QPoint(0, 0)
event = QDropEvent(pos, Qt.CopyAction, mime_data, Qt.NoButton, Qt.NoModifier)
- with mock.patch(
- "PySide6.QtWidgets.QGraphicsSceneDragDropEvent.source"
- ) as mock_drop_event_source, mock.patch.object(self.toolbox, "project"), mock.patch.object(
- self.toolbox, "show_add_project_item_form"
- ) as mock_show_add_project_item_form:
+ with (
+ mock.patch("PySide6.QtWidgets.QGraphicsSceneDragDropEvent.source") as mock_drop_event_source,
+ mock.patch.object(self.toolbox, "project"),
+ mock.patch.object(self.toolbox, "show_add_project_item_form") as mock_show_add_project_item_form,
+ ):
mock_drop_event_source.return_value = "Invalid source"
gv.dropEvent(event)
mock_show_add_project_item_form.assert_not_called()
@@ -493,11 +506,11 @@ def test_drop_project_item_on_design_view(self):
scene_pos = QPointF(44, 20)
pos = gv.mapFromScene(scene_pos)
event = QDropEvent(pos, Qt.CopyAction, mime_data, Qt.NoButton, Qt.NoModifier)
- with mock.patch(
- "PySide6.QtWidgets.QGraphicsSceneDragDropEvent.source"
- ) as mock_drop_event_source, mock.patch.object(self.toolbox, "project"), mock.patch.object(
- self.toolbox, "show_add_project_item_form"
- ) as mock_show_add_project_item_form:
+ with (
+ mock.patch("PySide6.QtWidgets.QGraphicsSceneDragDropEvent.source") as mock_drop_event_source,
+ mock.patch.object(self.toolbox, "project"),
+ mock.patch.object(self.toolbox, "show_add_project_item_form") as mock_show_add_project_item_form,
+ ):
mock_drop_event_source.return_value = MockDraggableButton()
gv.dropEvent(event)
mock_show_add_project_item_form.assert_called_once()
@@ -544,8 +557,9 @@ def test_add_and_remove_specification(self):
project_dir = os.path.abspath(os.path.join(str(Path(__file__).parent), "test_resources", "Project Directory"))
self.assertTrue(os.path.exists(project_dir))
self.assertIsNone(self.toolbox.project())
- with mock.patch("spinetoolbox.ui_main.ToolboxUI.save_project"), mock.patch(
- "spinetoolbox.ui_main.ToolboxUI.update_recent_projects"
+ with (
+ mock.patch("spinetoolbox.ui_main.ToolboxUI.save_project"),
+ mock.patch("spinetoolbox.ui_main.ToolboxUI.update_recent_projects"),
):
self.toolbox.open_project(project_dir)
# Tool spec model must be empty at this point
@@ -555,9 +569,10 @@ def test_add_and_remove_specification(self):
)
self.assertTrue(os.path.exists(tool_spec_path))
# Add a Tool spec to 'project.json' file
- with mock.patch("spinetoolbox.ui_main.QFileDialog.getOpenFileName") as mock_filename, mock.patch(
- "spine_items.tool.tool_specifications.ToolSpecification.save"
- ) as mock_save_specification:
+ with (
+ mock.patch("spinetoolbox.ui_main.QFileDialog.getOpenFileName") as mock_filename,
+ mock.patch("spine_items.tool.tool_specifications.ToolSpecification.save") as mock_save_specification,
+ ):
mock_filename.return_value = [tool_spec_path]
mock_save_specification.return_value = True
self.toolbox.import_specification()
diff --git a/tests/test_helpers.py b/tests/test_helpers.py
index 39b511420..0aa83e185 100644
--- a/tests/test_helpers.py
+++ b/tests/test_helpers.py
@@ -292,9 +292,10 @@ def test_initial_dir_for_python_open_dialogs(self):
# initial dir should be according to the text in line edit
self.assertEqual(mock_native_dialog.call_args[1]["File"], str(executable))
self.assertEqual(mock_native_dialog.call_args[1]["InitialDir"], home_dir())
- with patch("spinetoolbox.helpers.os.path.exists") as mock_exists, patch(
- "spinetoolbox.helpers.os.path.abspath"
- ) as mock_abspath:
+ with (
+ patch("spinetoolbox.helpers.os.path.exists") as mock_exists,
+ patch("spinetoolbox.helpers.os.path.abspath") as mock_abspath,
+ ):
mock_exists.return_value = True
mock_abspath.return_value = python_in_path
line_edit.clear()
@@ -316,9 +317,10 @@ def test_initial_dir_for_python_open_dialogs(self):
select_python_interpreter(None, line_edit)
# initial dir should be according to the text in line edit
mock_open_file_dialog.assert_called_with(None, "Select Python Interpreter", str(executable))
- with patch("spinetoolbox.helpers.os.path.exists") as mock_exists, patch(
- "spinetoolbox.helpers.os.path.abspath"
- ) as mock_abspath:
+ with (
+ patch("spinetoolbox.helpers.os.path.exists") as mock_exists,
+ patch("spinetoolbox.helpers.os.path.abspath") as mock_abspath,
+ ):
mock_exists.return_value = True
mock_abspath.return_value = python_in_path
line_edit.clear()
diff --git a/tests/widgets/test_AddProjectItemWidget.py b/tests/widgets/test_AddProjectItemWidget.py
index 5473cdbae..782dc14f5 100644
--- a/tests/widgets/test_AddProjectItemWidget.py
+++ b/tests/widgets/test_AddProjectItemWidget.py
@@ -26,9 +26,10 @@ class TestAddProjectItemWidget(TestCaseWithQApplication):
def setUp(self):
"""Set up toolbox."""
self._temp_dir = TemporaryDirectory()
- with patch("spinetoolbox.ui_main.JumpPropertiesWidget") as mock_jump_props_widget, patch(
- "spinetoolbox.ui_main.load_project_items"
- ) as mock_load_project_items:
+ with (
+ patch("spinetoolbox.ui_main.JumpPropertiesWidget") as mock_jump_props_widget,
+ patch("spinetoolbox.ui_main.load_project_items") as mock_load_project_items,
+ ):
mock_jump_props_widget.return_value = QWidget()
mock_load_project_items.return_value = {TestProjectItem.item_type(): TestItemFactory}
self._toolbox = create_toolboxui_with_project(self._temp_dir.name)
@@ -51,11 +52,11 @@ class TestAddProjectItemWidgetWithSpecifications(TestCaseWithQApplication):
def setUp(self):
"""Set up toolbox."""
self._temp_dir = TemporaryDirectory()
- with patch("spinetoolbox.ui_main.JumpPropertiesWidget") as mock_jump_props_widget, patch(
- "spinetoolbox.ui_main.load_project_items"
- ) as mock_load_project_items, patch(
- "spinetoolbox.ui_main.load_item_specification_factories"
- ) as mock_load_specification_factories:
+ with (
+ patch("spinetoolbox.ui_main.JumpPropertiesWidget") as mock_jump_props_widget,
+ patch("spinetoolbox.ui_main.load_project_items") as mock_load_project_items,
+ patch("spinetoolbox.ui_main.load_item_specification_factories") as mock_load_specification_factories,
+ ):
mock_jump_props_widget.return_value = QWidget()
mock_load_project_items.return_value = {TestProjectItem.item_type(): TestItemFactory}
mock_load_specification_factories.return_value = {TestProjectItem.item_type(): TestSpecificationFactory}
diff --git a/tests/widgets/test_AddUpSpineOptWizard.py b/tests/widgets/test_AddUpSpineOptWizard.py
index 128cfcd69..c4302fc70 100644
--- a/tests/widgets/test_AddUpSpineOptWizard.py
+++ b/tests/widgets/test_AddUpSpineOptWizard.py
@@ -22,11 +22,14 @@ class TestAddUpSpineOptWizard(TestCaseWithQApplication):
def setUp(self):
"""Set up toolbox."""
self.toolbox = create_toolboxui()
- with mock.patch(
- "spinetoolbox.widgets.settings_widget.SettingsWidget.start_fetching_python_kernels"
- ) as mock_fetch_python_kernels, mock.patch(
- "spinetoolbox.widgets.settings_widget.SettingsWidget.start_fetching_julia_kernels"
- ) as mock_fetch_julia_kernels:
+ with (
+ mock.patch(
+ "spinetoolbox.widgets.settings_widget.SettingsWidget.start_fetching_python_kernels"
+ ) as mock_fetch_python_kernels,
+ mock.patch(
+ "spinetoolbox.widgets.settings_widget.SettingsWidget.start_fetching_julia_kernels"
+ ) as mock_fetch_julia_kernels,
+ ):
self.settings_widget = SettingsWidget(self.toolbox)
mock_fetch_python_kernels.assert_called()
mock_fetch_julia_kernels.assert_called()
diff --git a/tests/widgets/test_InstallJuliaWizard.py b/tests/widgets/test_InstallJuliaWizard.py
index 6e02dc7bc..952fe8d14 100644
--- a/tests/widgets/test_InstallJuliaWizard.py
+++ b/tests/widgets/test_InstallJuliaWizard.py
@@ -22,11 +22,14 @@ class TestInstallJuliaWizard(TestCaseWithQApplication):
def setUp(self):
"""Set up toolbox."""
self.toolbox = create_toolboxui()
- with mock.patch(
- "spinetoolbox.widgets.settings_widget.SettingsWidget.start_fetching_python_kernels"
- ) as mock_fetch_python_kernels, mock.patch(
- "spinetoolbox.widgets.settings_widget.SettingsWidget.start_fetching_julia_kernels"
- ) as mock_fetch_julia_kernels:
+ with (
+ mock.patch(
+ "spinetoolbox.widgets.settings_widget.SettingsWidget.start_fetching_python_kernels"
+ ) as mock_fetch_python_kernels,
+ mock.patch(
+ "spinetoolbox.widgets.settings_widget.SettingsWidget.start_fetching_julia_kernels"
+ ) as mock_fetch_julia_kernels,
+ ):
self._settings_widget = SettingsWidget(self.toolbox)
mock_fetch_python_kernels.assert_called()
mock_fetch_julia_kernels.assert_called()
diff --git a/tests/widgets/test_kernel_editor.py b/tests/widgets/test_kernel_editor.py
index ab53730e1..4dcb109bf 100644
--- a/tests/widgets/test_kernel_editor.py
+++ b/tests/widgets/test_kernel_editor.py
@@ -51,10 +51,11 @@ def test_make_python_kernel(self):
python_exec = "python.exe" if sys.platform == "win32" else "python"
python_path = pathlib.Path(environment_dir, "Scripts", python_exec)
kernel_name = "spinetoolbox_test_make_python_kernel"
- with patch("spinetoolbox.widgets.kernel_editor.QMessageBox") as mock_message_box, patch.object(
- KernelEditorBase, "_python_interpreter_name", return_value=str(python_path)
- ), patch.object(KernelEditorBase, "_python_kernel_name", return_value=kernel_name), patch.object(
- KernelEditorBase, "_python_kernel_display_name", return_value="Test kernel"
+ with (
+ patch("spinetoolbox.widgets.kernel_editor.QMessageBox") as mock_message_box,
+ patch.object(KernelEditorBase, "_python_interpreter_name", return_value=str(python_path)),
+ patch.object(KernelEditorBase, "_python_kernel_name", return_value=kernel_name),
+ patch.object(KernelEditorBase, "_python_kernel_display_name", return_value="Test kernel"),
):
mock_message_box.exec.return_value = QMessageBox.StandardButton.Ok
editor = KernelEditorBase(self._settings_widget, "python")
@@ -81,10 +82,11 @@ def test_make_julia_kernel(self):
self.skipTest("Julia not found in PATH.")
kernel_name = "spinetoolbox_test_make_julia_kernel"
# with TemporaryDirectory() as julia_project_dir:
- with patch("spinetoolbox.widgets.kernel_editor.QMessageBox") as mock_message_box, patch.object(
- KernelEditorBase, "_julia_kernel_name", return_value=kernel_name
- ), patch.object(KernelEditorBase, "_julia_executable", return_value=julia_exec), patch.object(
- KernelEditorBase, "_julia_project", return_value="@."
+ with (
+ patch("spinetoolbox.widgets.kernel_editor.QMessageBox") as mock_message_box,
+ patch.object(KernelEditorBase, "_julia_kernel_name", return_value=kernel_name),
+ patch.object(KernelEditorBase, "_julia_executable", return_value=julia_exec),
+ patch.object(KernelEditorBase, "_julia_project", return_value="@."),
):
mock_message_box.exec.return_value = QMessageBox.StandardButton.Ok
editor = KernelEditorBase(self._settings_widget, "julia")