Skip to content

Commit

Permalink
Fix extruder parsers tests
Browse files Browse the repository at this point in the history
  • Loading branch information
noemifrisina committed Jun 16, 2023
1 parent 32054b5 commit 047b1ed
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def flush_print(text):
sys.stdout.flush()


def initialise_extruderi24(args):
def initialise_extruderi24(args=None):
name = inspect.stack()[0][3]
print("Initialise Parameters for extruder data collection")
logger.info("%s I24 extruder initialisation" % name)
Expand Down Expand Up @@ -202,7 +202,7 @@ def scrape_parameter_file(param_path: Path | str = PARAM_FILE_PATH):
)


def run_extruderi24(args):
def run_extruderi24(args=None):
print("Starting i24")
name = inspect.stack()[0][3]
logger.info("%s" % name)
Expand Down
30 changes: 24 additions & 6 deletions tests/I24/serial/extruder/test_extruder_collect.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import argparse
from unittest.mock import mock_open, patch

import pytest

from mx_bluesky.I24.serial.extruder.i24ssx_Extruder_Collect_py3v2 import (
initialise_extruderi24,
moveto,
Expand All @@ -20,6 +23,18 @@
pump_delay 0"""


@pytest.fixture
def dummy_parser():
parser = argparse.ArgumentParser()
parser.add_argument(
"place",
type=str,
choices=["laseron", "laseroff", "enterhutch"],
help="Requested setting.",
)
yield parser


@patch(
"mx_bluesky.I24.serial.extruder.i24ssx_Extruder_Collect_py3v2.open",
mock_open(read_data=params_file_str),
Expand All @@ -45,26 +60,29 @@ def test_initialise_extruder(fake_det, fake_caput, fake_caget):

@patch("mx_bluesky.I24.serial.extruder.i24ssx_Extruder_Collect_py3v2.caput")
@patch("mx_bluesky.I24.serial.extruder.i24ssx_Extruder_Collect_py3v2.caget")
def test_moveto_enterhutch(fake_caget, fake_caput):
moveto("enterhutch")
def test_moveto_enterhutch(fake_caget, fake_caput, dummy_parser):
fake_args = dummy_parser.parse_args(["enterhutch"])
moveto(fake_args)
assert fake_caget.call_count == 1
assert fake_caput.call_count == 1


@patch("mx_bluesky.I24.serial.extruder.i24ssx_Extruder_Collect_py3v2.caput")
@patch("mx_bluesky.I24.serial.extruder.i24ssx_Extruder_Collect_py3v2.caget")
def test_moveto_laseron_for_eiger(fake_caget, fake_caput):
def test_moveto_laseron_for_eiger(fake_caget, fake_caput, dummy_parser):
fake_caget.return_value = "eiger"
moveto("laseron")
fake_args = dummy_parser.parse_args(["laseron"])
moveto(fake_args)
assert fake_caget.call_count == 1
assert fake_caput.call_count == 2


@patch("mx_bluesky.I24.serial.extruder.i24ssx_Extruder_Collect_py3v2.caput")
@patch("mx_bluesky.I24.serial.extruder.i24ssx_Extruder_Collect_py3v2.caget")
def test_moveto_laseroff_for_pilatus(fake_caget, fake_caput):
def test_moveto_laseroff_for_pilatus(fake_caget, fake_caput, dummy_parser):
fake_caget.return_value = "pilatus"
moveto("laseroff")
fake_args = dummy_parser.parse_args(["laseroff"])
moveto(fake_args)
assert fake_caget.call_count == 1
assert fake_caput.call_count == 2

Expand Down

0 comments on commit 047b1ed

Please sign in to comment.