Skip to content

Commit 09184fc

Browse files
committed
Addresses review comments
1 parent aa72064 commit 09184fc

File tree

7 files changed

+30
-20
lines changed

7 files changed

+30
-20
lines changed

RATapi/examples/convert_rascal_project/convert_rascal.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66

77
# convert R1 project to Project class
8-
def convert_rascal():
8+
def convert_rascal(mat_filename="lipid_bilayer.mat"):
99
project_path = pathlib.Path(__file__).parent / "R1monolayerVolumeModel.mat"
1010
project = RAT.utils.convert.r1_to_project_class(project_path)
1111

@@ -16,7 +16,7 @@ def convert_rascal():
1616

1717
# convert DSPC standard layers example to a struct and save as file
1818
lipid_bilayer_project = RAT.examples.DSPC_standard_layers()[0]
19-
RAT.utils.convert.project_class_to_r1(lipid_bilayer_project, filename="lipid_bilayer.mat")
19+
RAT.utils.convert.project_class_to_r1(lipid_bilayer_project, filename=mat_filename)
2020

2121
# convert and return as a Python dictionary
2222
struct = RAT.utils.convert.project_class_to_r1(lipid_bilayer_project, return_struct=True)

RATapi/examples/normal_reflectivity/DSPC_function_background.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,10 +142,9 @@ def DSPC_function_background():
142142
)
143143
problem.backgrounds.append(name="SMW Background", type="constant", source="Background parameter SMW")
144144

145-
# FIXME: replace this with a Python custom file when Python backgrounds are added!
146145
problem.custom_files.append(
147146
name="D2O Background Function",
148-
filename="backgroundFunction.py",
147+
filename="background_function.py",
149148
language="python",
150149
path=pathlib.Path(__file__).parent.resolve(),
151150
)

RATapi/examples/normal_reflectivity/backgroundFunction.py renamed to RATapi/examples/normal_reflectivity/background_function.py

File renamed without changes.

RATapi/inputs.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -280,10 +280,7 @@ def make_problem(project: RATapi.Project, checks: Checks) -> ProblemDefinition:
280280
resolution = project.resolutions[contrast.resolution]
281281
contrast_resolution_types.append(resolution.type)
282282
contrast_resolution_param = []
283-
if resolution.type == TypeOptions.Data:
284-
# The source field is empty for a data resolution
285-
pass
286-
elif resolution.type == TypeOptions.Function:
283+
if resolution.type == TypeOptions.Function:
287284
contrast_resolution_param.append(project.custom_files.index(resolution.source, True))
288285
contrast_resolution_param.extend(
289286
[
@@ -299,7 +296,7 @@ def make_problem(project: RATapi.Project, checks: Checks) -> ProblemDefinition:
299296
]
300297
)
301298

302-
else:
299+
elif resolution.type == TypeOptions.Constant:
303300
contrast_resolution_param.append(project.resolution_parameters.index(resolution.source, True))
304301

305302
contrast_resolution_params.append(contrast_resolution_param)

tests/conftest.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import shutil
2+
import tempfile
13
from pathlib import Path
24

35
import numpy as np
@@ -9,6 +11,13 @@
911
import RATapi.rat_core
1012

1113

14+
@pytest.fixture
15+
def temp_dir():
16+
path = tempfile.mkdtemp()
17+
yield path
18+
shutil.rmtree(path)
19+
20+
1221
@pytest.fixture
1322
def input_project():
1423
"""A cut-down version of the input Project object for a reflectivity calculation set out in

tests/test_examples.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Test the RAT examples."""
22

33
import importlib
4+
from pathlib import Path
45

56
import pytest
67

@@ -31,12 +32,25 @@ def test_rat_examples(example_name):
3132
"example_name",
3233
[
3334
"DSPC_function_background",
34-
"convert_rascal",
3535
],
3636
)
3737
@pytest.mark.skipif(importlib.util.find_spec("matlab") is None, reason="Matlab not installed")
38-
def test_matlab_examples(example_name):
38+
def test_function_background(example_name):
3939
"""Test examples which rely on MATLAB engine being installed."""
4040
p, r = getattr(examples, example_name)()
4141
assert p is not None
4242
assert r is not None
43+
44+
45+
@pytest.mark.parametrize(
46+
"example_name",
47+
[
48+
"convert_rascal",
49+
],
50+
)
51+
@pytest.mark.skipif(importlib.util.find_spec("matlab") is None, reason="Matlab not installed")
52+
def test_matlab_examples(example_name, temp_dir):
53+
"""Test convert_rascal example, directing the output to a temporary directory."""
54+
p, r = examples.convert_rascal(Path(temp_dir, "lipid_bilayer.mat"))
55+
assert p is not None
56+
assert r is not None

tests/test_project.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
"""Test the project module."""
22

33
import copy
4-
import shutil
5-
import tempfile
64
from pathlib import Path
75
from typing import Callable
86

@@ -136,13 +134,6 @@ def default_project_str():
136134
)
137135

138136

139-
@pytest.fixture
140-
def temp_dir():
141-
path = tempfile.mkdtemp()
142-
yield path
143-
shutil.rmtree(path)
144-
145-
146137
def test_classlists(test_project) -> None:
147138
"""The ClassLists in the "Project" model should contain instances of the models given by the dictionary
148139
"model_in_classlist".

0 commit comments

Comments
 (0)