Skip to content
Snippets Groups Projects
Unverified Commit d9bbb032 authored by Robert Rosca's avatar Robert Rosca
Browse files

Add user notebook tests

parent 1639338f
No related branches found
No related tags found
No related merge requests found
This commit is part of merge request !466. Comments created here will be created in the context of that merge request.
...@@ -8,6 +8,7 @@ the current test cases, this should be improved later on. ...@@ -8,6 +8,7 @@ the current test cases, this should be improved later on.
import ast import ast
import sys import sys
import shutil
from datetime import date from datetime import date
from pathlib import Path from pathlib import Path
from unittest import mock from unittest import mock
...@@ -243,6 +244,65 @@ class TestIntelliList: ...@@ -243,6 +244,65 @@ class TestIntelliList:
assert parameters["concurrency_parameter"][0] == i + 1 assert parameters["concurrency_parameter"][0] == i + 1
class TestUserNotebooks:
@pytest.fixture(scope="class")
def mock_proposal(self, tmpdir_factory):
return MockProposal(
tmp_path=Path(tmpdir_factory.mktemp("exp")),
instrument="AGIPD",
cycle="202031",
proposal="p900113",
runs=1,
sequences=1,
)
@pytest.fixture(scope="function")
def calibrate_call(self, mock_proposal: MockProposal, capsys, tmp_path: Path):
# The user notebook path template for `TEST`/`TEST-USER-NB` is:
# `"/{instrumen}/{cycle}/p{proposal}/test-cli.ipynb"`
#
# So by setting `instrument` to tmp_path/TEST we set the user notebook
# location to one in our tmp dir
self.user_nb = mock_proposal.path_usr / "test-cli.ipynb"
shutil.copy(
Path("./notebooks/test/test-cli.ipynb").absolute(), str(self.user_nb)
)
return CalibrateCall(
tmp_path,
capsys,
in_folder=mock_proposal.path_raw,
out_folder=mock_proposal.path_proc,
detector="TEST",
cal_type="TEST-USER-NB",
extra_args=[
"--root",
str(mock_proposal.path_usr),
"--number",
"10",
],
)
def test_user_notebook_is_test_notebook(self, calibrate_call: CalibrateCall):
assert (
Path("./notebooks/test/test-cli.ipynb").read_bytes()
== self.user_nb.read_bytes()
)
def test_output_ipynb(self, calibrate_call: CalibrateCall):
notebook_path = calibrate_call.paths.notebooks
assert len(notebook_path) == 1
with notebook_path[0].open() as file:
notebook = nbformat.read(file, as_version=4)
parameters = {p.name: p.value for p in extract_parameters(notebook)}
assert parameters["number"] == 10
class TestAgipdNotebook: class TestAgipdNotebook:
@pytest.fixture(scope="function") @pytest.fixture(scope="function")
def mock_proposal(self, tmpdir_factory): def mock_proposal(self, tmpdir_factory):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment