To receive notifications about scheduled maintenance, please subscribe to the mailing-list gitlab-operations@sympa.ethz.ch. You can subscribe to the mailing-list at https://sympa.ethz.ch

Commit aff19928 authored by mikolajr's avatar mikolajr
Browse files

In MBW973 device: refactor config tests, fix type check errors, format...

In MBW973 device: refactor config tests, fix type check errors, format (black), and copyright notice
parent c2ac3d60
Pipeline #53112 failed with stages
in 2 minutes and 57 seconds
# Copyright (c) 2019 ETH Zurich, SIS ID and HVL D-ITET
#
"""
Device class for Newport SMC100PP stepper motor controller with serial communication.
......@@ -17,6 +19,11 @@ from aenum import Enum, IntEnum
from .base import SingleCommDevice
from ..comm import SerialCommunication, SerialCommunicationConfig
from ..comm.serial import (
SerialCommunicationParity,
SerialCommunicationStopbits,
SerialCommunicationBytesize,
)
from ..configuration import configdataclass
from ..utils.enum import NameEnum, AutoNumberNameEnum
......@@ -30,19 +37,15 @@ class NewportSMC100PPSerialCommunicationConfig(SerialCommunicationConfig):
baudrate: int = 57600
#: Heinzinger does not use parity
parity: Union[
str, SerialCommunicationConfig.Parity,
] = SerialCommunicationConfig.Parity.NONE
parity: Union[str, SerialCommunicationParity,] = SerialCommunicationParity.NONE
#: Heinzinger uses one stop bit
stopbits: Union[
int, SerialCommunicationConfig.Stopbits,
] = SerialCommunicationConfig.Stopbits.ONE
stopbits: Union[int, SerialCommunicationStopbits,] = SerialCommunicationStopbits.ONE
#: One byte is eight bits long
bytesize: Union[
int, SerialCommunicationConfig.Bytesize,
] = SerialCommunicationConfig.Bytesize.EIGHTBITS
int, SerialCommunicationBytesize,
] = SerialCommunicationBytesize.EIGHTBITS
#: The terminator is CR/LF
terminator: bytes = b"\r\n"
......@@ -159,7 +162,7 @@ class NewportSMC100PPSerialCommunication(SerialCommunication):
raise NewportSerialCommunicationError(message)
else:
logging.debug(f"Newport com: {answer}")
return answer[len(prefix):].strip()
return answer[len(prefix) :].strip()
def _check_for_error_unsafe(self, add: int) -> None:
"""
......@@ -262,7 +265,7 @@ class NewportSMC100PPSerialCommunication(SerialCommunication):
logging.error(message)
raise NewportSerialCommunicationError(message)
else:
answer.append(line[len(prefix):])
answer.append(line[len(prefix) :])
finally:
self._check_for_error_unsafe(add)
......
# Copyright (c) 2019 ETH Zurich, SIS ID and HVL D-ITET
#
"""
Tests for the dev.newport sub-package.
"""
......@@ -53,33 +55,6 @@ def dev_config():
}
@pytest.fixture(scope="module")
def wrong_dev_config():
return {
"address": -1,
"screw_scaling": -1,
"exit_configuration_wait_sec": -1,
"move_finished_extra_wait_sec": -1,
"acceleration": -1,
"backlash_compensation": -1,
"hysteresis_compensation": -1,
"micro_step_per_full_step_factor": -1,
"motion_distance_per_full_step": -1,
"home_search_type": -1,
"jerk_time": -1,
"home_search_velocity": -1,
"home_search_timeout": -1,
"home_search_polling_interval": -1,
"peak_output_current_limit": -1,
"rs485_address": -1,
"negative_software_limit": 1,
"positive_software_limit": -1,
"velocity": -1,
"base_velocity": -1,
"stage_configuration": -1,
}
@pytest.fixture
def started_newport(com_config, dev_config):
com = NewportLoopSerialCommunication(com_config)
......@@ -233,28 +208,62 @@ def test_com_query_multiple(com_config):
com.query_multiple(add, cmd, prefixes)
def test_newport_instantiation(com_config, dev_config, wrong_dev_config):
mot = dev.NewportSMC100PP(com_config)
assert mot is not None
def test_dev_config(dev_config):
# currently there are no non-default config values
dev.NewportSMC100PPConfig()
# test wrong config values
dict_wrong_dev_config = dict(wrong_dev_config)
for param in dict_wrong_dev_config:
dict_dev_config = dict(dev_config)
dict_dev_config[param] = dict_wrong_dev_config[param]
with pytest.raises(ValueError):
dev.NewportSMC100PP(com_config, dict_dev_config)
config = dev.NewportSMC100PPConfig(**dev_config)
for key, value in dev_config.items():
assert getattr(config, key) == value
# test _motor_config update on force_value
mot = dev.NewportSMC100PP(com_config, dev_config)
fieldname = "acceleration"
value = dict(dev_config)[fieldname]
# first call to motor_config creates cache
assert mot.config.motor_config[fieldname] == value
assert config.motor_config[fieldname] == value
value = value - 1
mot.config.force_value(fieldname, value)
config.force_value(fieldname, value)
# check that cache is updated
assert mot.config.motor_config[fieldname] == value
assert config.motor_config[fieldname] == value
@pytest.mark.parametrize(
"wrong_config_dict",
[
{"address": -1},
{"screw_scaling": -1},
{"exit_configuration_wait_sec": -1},
{"move_finished_extra_wait_sec": -1},
{"acceleration": -1},
{"backlash_compensation": -1},
{"hysteresis_compensation": -1},
{"micro_step_per_full_step_factor": -1},
{"motion_distance_per_full_step": -1},
{"home_search_type": -1},
{"jerk_time": -1},
{"home_search_velocity": -1},
{"home_search_timeout": -1},
{"home_search_polling_interval": -1},
{"peak_output_current_limit": -1},
{"rs485_address": -1},
{"negative_software_limit": 1},
{"positive_software_limit": -1},
{"velocity": -1},
{"base_velocity": -1},
{"stage_configuration": -1},
],
)
def test_dev_config_invalid(wrong_config_dict):
with pytest.raises(ValueError):
dev.NewportSMC100PPConfig(**wrong_config_dict)
def test_newport_instantiation(com_config, dev_config):
mot = dev.NewportSMC100PP(com_config)
assert mot is not None
mot = dev.NewportSMC100PP(com_config, dev_config)
assert mot is not None
def test_newport_com_errors(com_config, dev_config):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment