diff --git a/ratapi/controls.py b/ratapi/controls.py index 06c457b..9dd815b 100644 --- a/ratapi/controls.py +++ b/ratapi/controls.py @@ -206,7 +206,7 @@ def __str__(self) -> str: def initialise_IPC(self): """Set up the inter-process communication file.""" IPC_obj, self._IPCFilePath = tempfile.mkstemp() - os.write(IPC_obj, b"0") + os.write(IPC_obj, b"\x00") os.close(IPC_obj) return None @@ -221,7 +221,7 @@ def sendStopEvent(self): """ if os.path.isfile(self._IPCFilePath): with open(self._IPCFilePath, "wb") as f: - f.write(b"1") + f.write(b"\x01") else: warnings.warn("An IPC file was not initialised.", UserWarning, stacklevel=2) return None @@ -230,6 +230,7 @@ def delete_IPC(self): """Delete the inter-process communication file.""" with contextlib.suppress(FileNotFoundError): os.remove(self._IPCFilePath) + self._IPCFilePath = "" return None def save(self, filepath: str | Path = "./controls.json"): diff --git a/ratapi/utils/convert.py b/ratapi/utils/convert.py index 4e2649a..b957789 100644 --- a/ratapi/utils/convert.py +++ b/ratapi/utils/convert.py @@ -291,7 +291,14 @@ def fix_invalid_constraints(name: str, constrs: tuple[float, float], value: floa if Path(custom_filepath).suffix != ".m": custom_filepath += ".m" model_name = Path(custom_filepath).stem - custom_file = ClassList([CustomFile(name=model_name, filename=custom_filepath, language=Languages.Matlab)]) + # Assume the custom file is in the same directory as the mat file + custom_file = ClassList( + [ + CustomFile( + name=model_name, filename=custom_filepath, language=Languages.Matlab, path=Path(filename).parent + ) + ] + ) layers = ClassList() for contrast in contrasts: contrast.model = [model_name] diff --git a/ratapi/utils/plotting.py b/ratapi/utils/plotting.py index 9293a1a..d4a81e1 100644 --- a/ratapi/utils/plotting.py +++ b/ratapi/utils/plotting.py @@ -492,6 +492,8 @@ def update_plot(self, data): """ if self.figure is not None: self.figure.clf() + + self.figure.tight_layout() plot_ref_sld_helper( data, self.figure, @@ -502,7 +504,6 @@ def update_plot(self, data): show_legend=self.show_legend, animated=True, ) - self.figure.tight_layout(pad=1) self.figure.canvas.draw() self.bg = self.figure.canvas.copy_from_bbox(self.figure.bbox) for line in self.figure.axes[0].lines: diff --git a/tests/conftest.py b/tests/conftest.py index 4d5ecc0..bd35919 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -6858,7 +6858,11 @@ def r1_monolayer(): ), custom_files=ratapi.ClassList( ratapi.models.CustomFile( - name="Model_IIb", filename="Model_IIb.m", function_name="Model_IIb", language="matlab" + name="Model_IIb", + filename="Model_IIb.m", + function_name="Model_IIb", + language="matlab", + path=Path(__file__).parent / "test_data", ) ), ) diff --git a/tests/test_controls.py b/tests/test_controls.py index ec8cb12..5a83bcc 100644 --- a/tests/test_controls.py +++ b/tests/test_controls.py @@ -891,7 +891,7 @@ def test_initialise_IPC() -> None: assert test_controls._IPCFilePath != "" with open(test_controls._IPCFilePath, "rb") as f: file_content = f.read() - assert file_content == b"0" + assert file_content == b"\x00" os.remove(test_controls._IPCFilePath) @@ -900,7 +900,7 @@ def test_sendStopEvent(IPC_controls) -> None: IPC_controls.sendStopEvent() with open(IPC_controls._IPCFilePath, "rb") as f: file_content = f.read() - assert file_content == b"1" + assert file_content == b"\x01" def test_sendStopEvent_empty_file() -> None: diff --git a/tests/test_convert.py b/tests/test_convert.py index 2973834..fc6f440 100644 --- a/tests/test_convert.py +++ b/tests/test_convert.py @@ -93,7 +93,7 @@ def mock_load(ignored_filename, **ignored_settings): monkeypatch.setattr("ratapi.utils.convert.loadmat", mock_load, raising=True) - converted_project = r1_to_project(project) + converted_project = r1_to_project(pathlib.Path(__file__).parent / "test_data" / project) for class_list in ratapi.project.class_lists: assert getattr(converted_project, class_list) == getattr(original_project, class_list)