Skip to content

Commit

Permalink
Fix bug in Install Julia Wizard (#2996)
Browse files Browse the repository at this point in the history
- Use jill's "julia" symlink ("julia.cmd" on Windows) as the default Julia executable after a Julia has been installed
- Skip a test that was probably broken by commit ed3e6fe
- Run black
  • Loading branch information
ptsavol authored Nov 1, 2024
1 parent ed3e6fe commit 18814fa
Show file tree
Hide file tree
Showing 25 changed files with 465 additions and 383 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
13 changes: 8 additions & 5 deletions spinetoolbox/widgets/install_julia_wizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
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 18814fa

Please sign in to comment.