Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion packaging/build_exe.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
"PyQt6.QtXml",
"PyQt6.QtXmlPatterns",
"sphinx",
"numpy.array_api",
"pkg_resources",
]
IS_WINDOWS = sys.platform.startswith("win")
Expand Down Expand Up @@ -80,6 +79,12 @@ def build_exe():
str(PACKAGING_PATH / "hooks"),
"--log-level",
"ERROR",
"--collect-submodules",
"numpy",
"--collect-submodules",
"scipy",
"--collect-all",
"matlab",
str(main_path),
]

Expand Down
3 changes: 0 additions & 3 deletions packaging/hooks/hook-matlab.py

This file was deleted.

10 changes: 5 additions & 5 deletions rascal2/dialogs/startup_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
# global variable for required project files
PROJECT_FILES = ["controls.json", "project.json"]
EXAMPLES = {
"absorption": "Shows absorption (imaginary SLD) effect usually seen below the critical edge",
"domains_custom_layers": "Incoherent summing ('domains') from custom layer model",
"domains_custom_XY": "Incoherent summing ('domains') from custom XY model",
"domains_standard_layers": "Incoherent summing ('domains') from standard layer model",
"DSPC_standard_layers": "Reflectivity analysis of a floating bilayer of DSPC using standard layer model",
"DSPC_custom_layers": "Reflectivity analysis of a floating bilayer of DSPC using custom layer model",
"DSPC_custom_XY": "Reflectivity analysis of a floating bilayer of DSPC using custom XY model",
"DSPC_standard_layers": "Reflectivity analysis of a floating bilayer of DSPC using standard layer model",
"domains_standard_layers": "Incoherent summing ('domains') from standard layer model",
"domains_custom_layers": "Incoherent summing ('domains') from custom layer model",
"domains_custom_XY": "Incoherent summing ('domains') from custom XY model",
"absorption": "Shows absorption (imaginary SLD) effect usually seen below the critical edge",
}


Expand Down
17 changes: 16 additions & 1 deletion rascal2/ui/model.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import os
import shutil
import sys
from json import JSONDecodeError
from pathlib import Path

Expand Down Expand Up @@ -63,7 +65,19 @@ def __init__(self):
self.result_log = ""
self.controls = None

self.save_path = ""
self.__save_path = ""

@property
def save_path(self):
return self.__save_path

@save_path.setter
def save_path(self, value):
if self.__save_path in sys.path:
sys.path.remove(self.__save_path)
self.__save_path = value
os.chdir(value)
sys.path.append(value)

def create_project(self, name: str, save_path: str):
"""Create a new RAT project and controls object.
Expand Down Expand Up @@ -125,6 +139,7 @@ def save_project(self, save_path):
if self.results:
self.results.save(Path(save_path, "results.json"))
self.save_path = save_path
os.chdir(save_path)

def is_project_example(self):
return Path(self.save_path).is_relative_to(EXAMPLES_TEMP_PATH)
Expand Down
30 changes: 13 additions & 17 deletions tests/ui/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,14 @@ def empty_results():
return empty_results


def test_create_project():
@pytest.fixture
def model():
with patch("rascal2.ui.model.os.chdir", autospec=True):
yield MainWindowModel()


def test_create_project(model):
"""The project should be set up with the desired name and default objets when a new project is created."""
model = MainWindowModel()
assert model.project is None
assert model.controls is None
assert model.results is None
Expand All @@ -53,8 +58,7 @@ def test_create_project():
assert model.save_path == "C:/test"


def test_save_project(empty_results):
model = MainWindowModel()
def test_save_project(empty_results, model):
model.project = Project(calculation="domains", name="test project")
model.controls = Controls(procedure="dream", resampleMinAngle=0.5)
model.results = empty_results
Expand All @@ -73,9 +77,8 @@ def test_save_project(empty_results):
assert '"fitParams": []' in results


def test_load_project(empty_results):
def test_load_project(empty_results, model):
"""The load function should load the correct controls object from JSON."""
model = MainWindowModel()
project = Project(name="test project", calculation="domains")

with TemporaryDirectory() as tmpdir:
Expand All @@ -91,20 +94,17 @@ def test_load_project(empty_results):


@patch("ratapi.utils.convert.r1_to_project")
def test_load_r1_project(mock_r1_class):
def test_load_r1_project(mock_r1_class, model):
"""load_r1_project should call the conversion function and set the path correctly."""
model = MainWindowModel()
model.load_r1_project("test_path/r1project.mat")

mock_r1_class.assert_called_once()
assert model.save_path == "test_path"


@pytest.mark.parametrize("bad_json", ['{"field1":3', '{"procedure":"fry eggs"}'])
def test_load_controls_error(bad_json):
def test_load_controls_error(bad_json, model):
"""The project load function should raise an error if the controls JSON is invalid or the parameters are invalid."""
model = MainWindowModel()

with pytest.raises( # noqa (for nested with's: pytest.raises breaks if not by itself)
ValueError,
match="The controls.json file for this project is not valid.\n"
Expand All @@ -116,10 +116,8 @@ def test_load_controls_error(bad_json):


@pytest.mark.parametrize("bad_json", ['{"calculation":"Do}', '{i"m not a good project file'])
def test_load_project_decode_error(bad_json):
def test_load_project_decode_error(bad_json, model):
"""The project load function should raise an error if the project JSON is invalid JSON."""
model = MainWindowModel()

with pytest.raises( # noqa (for nested with's: pytest.raises breaks if not by itself)
ValueError, match="The project.json file for this project contains invalid JSON."
):
Expand All @@ -132,10 +130,8 @@ def test_load_project_decode_error(bad_json):
@pytest.mark.parametrize(
"bad_json", ['{"calculation":"guessing"}', '{"parameters":[{"name":"parameter 1","thickness":0.51}]}']
)
def test_load_project_value_error(bad_json):
def test_load_project_value_error(bad_json, model):
"""The project load function should raise an error if the values are not valid."""
model = MainWindowModel()

with pytest.raises( # noqa (for nested with's: pytest.raises breaks if not by itself)
ValueError, match="The project.json file for this project is not valid."
):
Expand Down
5 changes: 4 additions & 1 deletion tests/ui/test_presenter.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ def __init__(self):

@pytest.fixture
def presenter():
with patch("rascal2.ui.presenter.LOGGER", autospec=True) as mock_log:
with (
patch("rascal2.ui.presenter.LOGGER", autospec=True) as mock_log,
patch("rascal2.ui.model.os.chdir", autospec=True),
):
pr = MainWindowPresenter(MockWindowView())
pr.runner = MagicMock()
pr.model.controls = Controls()
Expand Down
Loading