Skip to content
Snippets Groups Projects

Feat/user notebooks

Merged Robert Rosca requested to merge feat/user-notebooks into master
1 file
+ 60
0
Compare changes
  • Side-by-side
  • Inline
@@ -8,6 +8,7 @@ the current test cases, this should be improved later on.
import ast
import sys
import shutil
from datetime import date
from pathlib import Path
from unittest import mock
@@ -243,6 +244,65 @@ class TestIntelliList:
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:
@pytest.fixture(scope="function")
def mock_proposal(self, tmpdir_factory):
Loading