Skip to content

Commit

Permalink
Run black
Browse files Browse the repository at this point in the history
  • Loading branch information
ptsavol committed Nov 1, 2024
1 parent 6f35c59 commit b600e5d
Show file tree
Hide file tree
Showing 23 changed files with 456 additions and 378 deletions.
14 changes: 9 additions & 5 deletions spinetoolbox/widgets/add_up_spine_opt_wizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 <b>Next</b> or click <b>Cancel</b> to close "
"the wizard.")
msg = (
"Apologies. Please see the Troubleshoot problems section "
"by clicking <b>Next</b> or click <b>Cancel</b> to close "
"the wizard."
)
layout.addWidget(WrapLabel(msg))
layout.addStretch()
layout.addWidget(check_box)
Expand Down Expand Up @@ -532,8 +534,10 @@ def __init__(self, parent):

def initializePage(self):
self.setTitle("Troubleshooting failed")
msg = ("<p>Please <a href=https://github.com/spine-tools/SpineOpt.jl/issues>open an issue with SpineOpt</a>."
"<br>Copy the log and paste it into the issue description.</p>")
msg = (
"<p>Please <a href=https://github.com/spine-tools/SpineOpt.jl/issues>open an issue with SpineOpt</a>."
"<br>Copy the log and paste it into the issue description.</p>"
)
layout = QVBoxLayout(self)
layout.addWidget(HyperTextLabel(msg))
copy_widget = QWidget()
Expand Down
34 changes: 18 additions & 16 deletions tests/mock_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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
Expand Down
114 changes: 66 additions & 48 deletions tests/mvcmodels/test_FilterCheckboxList.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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))
Expand All @@ -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])
Expand All @@ -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])
Expand All @@ -284,19 +284,25 @@ 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:]))

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)
Expand All @@ -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)
Expand All @@ -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:]))
Expand All @@ -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])

Expand All @@ -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)
Expand Down
Loading

0 comments on commit b600e5d

Please sign in to comment.