From ce4d57c59736909c8f476a2ce8b21f70eee662eb Mon Sep 17 00:00:00 2001 From: wakonig_k Date: Mon, 22 Apr 2024 19:18:27 +0200 Subject: [PATCH] build: updated to new plugin structure --- bec_plugins/__init__.py | 1 - bec_plugins/bec_client/__init__.py | 1 - bec_plugins/bec_client/hli/spec_hli.py | 245 ------------------ bec_plugins/bec_client/plugins/__init__.py | 1 - bec_plugins/bec_client/startup/pre_startup.py | 25 -- .../bec_client/hli => pxiii_bec}/__init__.py | 0 .../bec_ipython_client}/__init__.py | 0 .../high_level_interface}/__init__.py | 0 .../bec_ipython_client/plugins/__init__.py | 0 .../bec_ipython_client/startup/__init__.py | 0 .../startup/post_startup.py | 23 +- .../bec_ipython_client/startup/pre_startup.py | 14 + pxiii_bec/bec_widgets/__init__.py | 0 pxiii_bec/dap_services/__init__.py | 0 pxiii_bec/deployment/__init__.py | 0 .../deployment/device_server/__init__.py | 0 pxiii_bec/deployment/device_server/startup.py | 11 + pxiii_bec/device_configs/__init__.py | 0 pxiii_bec/devices/__init__.py | 0 pxiii_bec/scans/__init__.py | 0 pyproject.toml | 72 +++++ setup.cfg | 21 -- setup.py | 7 - tests/tests_bec_ipython_client/README.md | 31 +++ tests/tests_bec_widgets/README.md | 31 +++ tests/tests_dap_services/README.md | 31 +++ tests/tests_devices/README.md | 31 +++ tests/tests_scans/README.md | 31 +++ 28 files changed, 263 insertions(+), 313 deletions(-) delete mode 100644 bec_plugins/__init__.py delete mode 100644 bec_plugins/bec_client/__init__.py delete mode 100644 bec_plugins/bec_client/hli/spec_hli.py delete mode 100644 bec_plugins/bec_client/plugins/__init__.py delete mode 100644 bec_plugins/bec_client/startup/pre_startup.py rename {bec_plugins/bec_client/hli => pxiii_bec}/__init__.py (100%) rename {bec_plugins/bec_client/startup => pxiii_bec/bec_ipython_client}/__init__.py (100%) rename {bec_plugins/scan_server => pxiii_bec/bec_ipython_client/high_level_interface}/__init__.py (100%) create mode 100644 pxiii_bec/bec_ipython_client/plugins/__init__.py create mode 100644 pxiii_bec/bec_ipython_client/startup/__init__.py rename {bec_plugins/bec_client => pxiii_bec/bec_ipython_client}/startup/post_startup.py (64%) create mode 100644 pxiii_bec/bec_ipython_client/startup/pre_startup.py create mode 100644 pxiii_bec/bec_widgets/__init__.py create mode 100644 pxiii_bec/dap_services/__init__.py create mode 100644 pxiii_bec/deployment/__init__.py create mode 100644 pxiii_bec/deployment/device_server/__init__.py create mode 100644 pxiii_bec/deployment/device_server/startup.py create mode 100644 pxiii_bec/device_configs/__init__.py create mode 100644 pxiii_bec/devices/__init__.py create mode 100644 pxiii_bec/scans/__init__.py create mode 100644 pyproject.toml delete mode 100644 setup.cfg delete mode 100644 setup.py create mode 100644 tests/tests_bec_ipython_client/README.md create mode 100644 tests/tests_bec_widgets/README.md create mode 100644 tests/tests_dap_services/README.md create mode 100644 tests/tests_devices/README.md create mode 100644 tests/tests_scans/README.md diff --git a/bec_plugins/__init__.py b/bec_plugins/__init__.py deleted file mode 100644 index c8ba5d1..0000000 --- a/bec_plugins/__init__.py +++ /dev/null @@ -1 +0,0 @@ -from .bec_client import * diff --git a/bec_plugins/bec_client/__init__.py b/bec_plugins/bec_client/__init__.py deleted file mode 100644 index ba24808..0000000 --- a/bec_plugins/bec_client/__init__.py +++ /dev/null @@ -1 +0,0 @@ -from .plugins import * diff --git a/bec_plugins/bec_client/hli/spec_hli.py b/bec_plugins/bec_client/hli/spec_hli.py deleted file mode 100644 index 79700b2..0000000 --- a/bec_plugins/bec_client/hli/spec_hli.py +++ /dev/null @@ -1,245 +0,0 @@ -from bec_lib.devicemanager import Device -from bec_lib.scan_report import ScanReport - -# pylint:disable=undefined-variable -# pylint: disable=too-many-arguments - - -def dscan( - motor1: Device, m1_from: float, m1_to: float, steps: int, exp_time: float, **kwargs -) -> ScanReport: - """Relative line scan with one device. - - Args: - motor1 (Device): Device that should be scanned. - m1_from (float): Start position relative to the current position. - m1_to (float): End position relative to the current position. - steps (int): Number of steps. - exp_time (float): Exposure time. - - Returns: - ScanReport: Status object. - - Examples: - >>> dscan(dev.motor1, -5, 5, 10, 0.1) - """ - return scans.line_scan( - motor1, m1_from, m1_to, steps=steps, exp_time=exp_time, relative=True, **kwargs - ) - - -def d2scan( - motor1: Device, - m1_from: float, - m1_to: float, - motor2: Device, - m2_from: float, - m2_to: float, - steps: int, - exp_time: float, - **kwargs -) -> ScanReport: - """Relative line scan with two devices. - - Args: - motor1 (Device): First device that should be scanned. - m1_from (float): Start position of the first device relative to its current position. - m1_to (float): End position of the first device relative to its current position. - motor2 (Device): Second device that should be scanned. - m2_from (float): Start position of the second device relative to its current position. - m2_to (float): End position of the second device relative to its current position. - steps (int): Number of steps. - exp_time (float): Exposure time - - Returns: - ScanReport: Status object. - - Examples: - >>> d2scan(dev.motor1, -5, 5, dev.motor2, -8, 8, 10, 0.1) - """ - return scans.line_scan( - motor1, - m1_from, - m1_to, - motor2, - m2_from, - m2_to, - steps=steps, - exp_time=exp_time, - relative=True, - **kwargs - ) - - -def ascan(motor1, m1_from, m1_to, steps, exp_time, **kwargs): - """Absolute line scan with one device. - - Args: - motor1 (Device): Device that should be scanned. - m1_from (float): Start position. - m1_to (float): End position. - steps (int): Number of steps. - exp_time (float): Exposure time. - - Returns: - ScanReport: Status object. - - Examples: - >>> ascan(dev.motor1, -5, 5, 10, 0.1) - """ - return scans.line_scan( - motor1, m1_from, m1_to, steps=steps, exp_time=exp_time, relative=False, **kwargs - ) - - -def a2scan(motor1, m1_from, m1_to, motor2, m2_from, m2_to, steps, exp_time, **kwargs): - """Absolute line scan with two devices. - - Args: - motor1 (Device): First device that should be scanned. - m1_from (float): Start position of the first device. - m1_to (float): End position of the first device. - motor2 (Device): Second device that should be scanned. - m2_from (float): Start position of the second device. - m2_to (float): End position of the second device. - steps (int): Number of steps. - exp_time (float): Exposure time - - Returns: - ScanReport: Status object. - - Examples: - >>> a2scan(dev.motor1, -5, 5, dev.motor2, -8, 8, 10, 0.1) - """ - return scans.line_scan( - motor1, - m1_from, - m1_to, - motor2, - m2_from, - m2_to, - steps=steps, - exp_time=exp_time, - relative=False, - **kwargs - ) - - -def dmesh(motor1, m1_from, m1_to, m1_steps, motor2, m2_from, m2_to, m2_steps, exp_time, **kwargs): - """Relative mesh scan (grid scan) with two devices. - - Args: - motor1 (Device): First device that should be scanned. - m1_from (float): Start position of the first device relative to its current position. - m1_to (float): End position of the first device relative to its current position. - m1_steps (int): Number of steps for motor1. - motor2 (Device): Second device that should be scanned. - m2_from (float): Start position of the second device relative to its current position. - m2_to (float): End position of the second device relative to its current position. - m2_steps (int): Number of steps for motor2. - exp_time (float): Exposure time - - Returns: - ScanReport: Status object. - - Examples: - >>> dmesh(dev.motor1, -5, 5, 10, dev.motor2, -8, 8, 10, 0.1) - """ - return scans.grid_scan( - motor1, - m1_from, - m1_to, - m1_steps, - motor2, - m2_from, - m2_to, - m2_steps, - exp_time=exp_time, - relative=True, - ) - - -def amesh(motor1, m1_from, m1_to, m1_steps, motor2, m2_from, m2_to, m2_steps, exp_time, **kwargs): - """Absolute mesh scan (grid scan) with two devices. - - Args: - motor1 (Device): First device that should be scanned. - m1_from (float): Start position of the first device. - m1_to (float): End position of the first device. - m1_steps (int): Number of steps for motor1. - motor2 (Device): Second device that should be scanned. - m2_from (float): Start position of the second device. - m2_to (float): End position of the second device. - m2_steps (int): Number of steps for motor2. - exp_time (float): Exposure time - - Returns: - ScanReport: Status object. - - Examples: - >>> amesh(dev.motor1, -5, 5, 10, dev.motor2, -8, 8, 10, 0.1) - """ - return scans.grid_scan( - motor1, - m1_from, - m1_to, - m1_steps, - motor2, - m2_from, - m2_to, - m2_steps, - exp_time=exp_time, - relative=False, - ) - - -def umv(*args) -> ScanReport: - """Updated absolute move (i.e. blocking) for one or more devices. - - Returns: - ScanReport: Status object. - - Examples: - >>> umv(dev.samx, 1) - >>> umv(dev.samx, 1, dev.samy, 2) - """ - return scans.umv(*args, relative=False) - - -def umvr(*args) -> ScanReport: - """Updated relative move (i.e. blocking) for one or more devices. - - Returns: - ScanReport: Status object. - - Examples: - >>> umvr(dev.samx, 1) - >>> umvr(dev.samx, 1, dev.samy, 2) - """ - return scans.umv(*args, relative=True) - - -def mv(*args) -> ScanReport: - """Absolute move for one or more devices. - - Returns: - ScanReport: Status object. - - Examples: - >>> mv(dev.samx, 1) - >>> mv(dev.samx, 1, dev.samy, 2) - """ - return scans.mv(*args, relative=False) - - -def mvr(*args) -> ScanReport: - """Relative move for one or more devices. - - Returns: - ScanReport: Status object. - - Examples: - >>> mvr(dev.samx, 1) - >>> mvr(dev.samx, 1, dev.samy, 2) - """ - return scans.mv(*args, relative=True) diff --git a/bec_plugins/bec_client/plugins/__init__.py b/bec_plugins/bec_client/plugins/__init__.py deleted file mode 100644 index 8b13789..0000000 --- a/bec_plugins/bec_client/plugins/__init__.py +++ /dev/null @@ -1 +0,0 @@ - diff --git a/bec_plugins/bec_client/startup/pre_startup.py b/bec_plugins/bec_client/startup/pre_startup.py deleted file mode 100644 index b39c6eb..0000000 --- a/bec_plugins/bec_client/startup/pre_startup.py +++ /dev/null @@ -1,25 +0,0 @@ -""" -Pre-startup script for BEC client. This script is executed before the BEC client -is started. It can be used to set up the BEC client configuration. The script is -executed in the global namespace of the BEC client. This means that all -variables defined here are available in the BEC client. - -To set up the BEC client configuration, use the ServiceConfig class. For example, -to set the configuration file path, add the following lines to the script: - - import pathlib - from bec_lib import ServiceConfig - - current_path = pathlib.Path(__file__).parent.resolve() - CONFIG_PATH = f"{current_path}/" - - config = ServiceConfig(CONFIG_PATH) - -If this startup script defined a ServiceConfig object, the BEC client will use -it to configure itself. Otherwise, the BEC client will use the default config. -""" - -# example: -# current_path = pathlib.Path(__file__).parent.resolve() -# CONFIG_PATH = f"{current_path}/../../../bec_config.yaml" -# config = ServiceConfig(CONFIG_PATH) diff --git a/bec_plugins/bec_client/hli/__init__.py b/pxiii_bec/__init__.py similarity index 100% rename from bec_plugins/bec_client/hli/__init__.py rename to pxiii_bec/__init__.py diff --git a/bec_plugins/bec_client/startup/__init__.py b/pxiii_bec/bec_ipython_client/__init__.py similarity index 100% rename from bec_plugins/bec_client/startup/__init__.py rename to pxiii_bec/bec_ipython_client/__init__.py diff --git a/bec_plugins/scan_server/__init__.py b/pxiii_bec/bec_ipython_client/high_level_interface/__init__.py similarity index 100% rename from bec_plugins/scan_server/__init__.py rename to pxiii_bec/bec_ipython_client/high_level_interface/__init__.py diff --git a/pxiii_bec/bec_ipython_client/plugins/__init__.py b/pxiii_bec/bec_ipython_client/plugins/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/pxiii_bec/bec_ipython_client/startup/__init__.py b/pxiii_bec/bec_ipython_client/startup/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/bec_plugins/bec_client/startup/post_startup.py b/pxiii_bec/bec_ipython_client/startup/post_startup.py similarity index 64% rename from bec_plugins/bec_client/startup/post_startup.py rename to pxiii_bec/bec_ipython_client/startup/post_startup.py index 5ed97ad..866d691 100644 --- a/bec_plugins/bec_client/startup/post_startup.py +++ b/pxiii_bec/bec_ipython_client/startup/post_startup.py @@ -16,31 +16,30 @@ parse the --session argument, add the following lines to the script: if args.session == "my_session": print("Loading my_session session") - from bec_plugins.bec_client.plugins.my_session import * + from bec_plugins.bec_ipython_client.plugins.my_session import * else: print("Loading default session") - from bec_plugins.bec_client.plugins.default_session import * + from bec_plugins.bec_ipython_client.plugins.default_session import * """ # pylint: disable=invalid-name, unused-import, import-error, undefined-variable, unused-variable, unused-argument, no-name-in-module -import argparse from bec_lib import bec_logger logger = bec_logger.logger -logger.info("Using the PXIII startup script.") +logger.info("Using the PX-III startup script.") -parser = argparse.ArgumentParser() -parser.add_argument("--session", help="Session name", type=str, default="cSAXS") -args = parser.parse_args() +# pylint: disable=import-error +_args = _main_dict["args"] -# SETUP BEAMLINE INFO -from bec_client.plugins.SLS.sls_info import OperatorInfo, SLSInfo +_session_name = "PX-III" +if _args.session.lower() == "alignment": + # load the alignment session + _session_name = "Alignment" + logger.success("Alignment session loaded.") -bec._beamline_mixin._bl_info_register(SLSInfo) -bec._beamline_mixin._bl_info_register(OperatorInfo) # SETUP PROMPTS -bec._ip.prompts.username = "PXIII" +bec._ip.prompts.username = _session_name bec._ip.prompts.status = 1 diff --git a/pxiii_bec/bec_ipython_client/startup/pre_startup.py b/pxiii_bec/bec_ipython_client/startup/pre_startup.py new file mode 100644 index 0000000..1601a7f --- /dev/null +++ b/pxiii_bec/bec_ipython_client/startup/pre_startup.py @@ -0,0 +1,14 @@ +""" +Pre-startup script for BEC client. This script is executed before the BEC client +is started. It can be used to add additional command line arguments. +""" + + +def extend_command_line_args(parser): + """ + Extend the command line arguments of the BEC client. + """ + + parser.add_argument("--session", help="Session name", type=str, default="PX-III") + + return parser diff --git a/pxiii_bec/bec_widgets/__init__.py b/pxiii_bec/bec_widgets/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/pxiii_bec/dap_services/__init__.py b/pxiii_bec/dap_services/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/pxiii_bec/deployment/__init__.py b/pxiii_bec/deployment/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/pxiii_bec/deployment/device_server/__init__.py b/pxiii_bec/deployment/device_server/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/pxiii_bec/deployment/device_server/startup.py b/pxiii_bec/deployment/device_server/startup.py new file mode 100644 index 0000000..1b47efc --- /dev/null +++ b/pxiii_bec/deployment/device_server/startup.py @@ -0,0 +1,11 @@ +import os + + +def setup_epics_ca(): + os.environ["EPICS_CA_AUTO_ADDR_LIST"] = "NO" + os.environ["EPICS_CA_ADDR_LIST"] = "129.129.122.255 sls-x12sa-cagw.psi.ch:5836" + os.environ["PYTHONIOENCODING"] = "latin1" + + +def run(): + setup_epics_ca() diff --git a/pxiii_bec/device_configs/__init__.py b/pxiii_bec/device_configs/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/pxiii_bec/devices/__init__.py b/pxiii_bec/devices/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/pxiii_bec/scans/__init__.py b/pxiii_bec/scans/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..57b4b0a --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,72 @@ +[build-system] +requires = ["hatchling"] +build-backend = "hatchling.build" + +[project] +name = "pxiii_bec" +version = "0.0.0" +description = "Custom device implementations based on the ophyd hardware abstraction layer" +requires-python = ">=3.10" +classifiers = [ + "Development Status :: 3 - Alpha", + "Programming Language :: Python :: 3", + "Topic :: Scientific/Engineering", +] +dependencies = [ + "bec_ipython_client", + "bec_lib", + "bec_server", + "ophyd_devices", + "std_daq_client", + "rich", + "pyepics", +] + +[project.optional-dependencies] +dev = [ + "black", + "isort", + "coverage", + "pylint", + "pytest", + "pytest-random-order", + "pytest-redis", +] + +[project.entry-points."bec"] +plugin_bec = "pxiii_bec" + +[project.entry-points."bec.scans"] +plugin_scans = "pxiii_bec.scans" + +[project.entry-points."bec.ipython_client_startup"] +plugin_ipython_client_pre = "pxiii_bec.bec_ipython_client.startup.pre_startup" +plugin_ipython_client_post = "pxiii_bec.bec_ipython_client.startup" + +[project.entry-points."bec.widgets"] +plugin_widgets = "pxiii_bec.bec_widgets" + +[tool.hatch.build.targets.wheel] +include = ["*"] + +[tool.isort] +profile = "black" +line_length = 100 +multi_line_output = 3 +include_trailing_comma = true + +[tool.black] +line-length = 100 +skip-magic-trailing-comma = true + +[tool.pylint.basic] +# Good variable names regexes, separated by a comma. If names match any regex, +# they will always be accepted +good-names-rgxs = [ + ".*scanID.*", + ".*RID.*", + ".*pointID.*", + ".*ID.*", + ".*_2D.*", + ".*_1D.*", +] diff --git a/setup.cfg b/setup.cfg deleted file mode 100644 index a5ae6c0..0000000 --- a/setup.cfg +++ /dev/null @@ -1,21 +0,0 @@ -[metadata] -name = bec_plugins -description = BEC plugins to modify the behaviour of services within the BEC framework -long_description = file: README.md -long_description_content_type = text/markdown -url = https://gitlab.psi.ch/bec/bec -project_urls = - Bug Tracker = https://gitlab.psi.ch/bec/bec/issues -classifiers = - Programming Language :: Python :: 3 - Development Status :: 3 - Alpha - Topic :: Scientific/Engineering - -[options] -package_dir = - = . -packages = find: -python_requires = >=3.10 - -[options.packages.find] -where = . diff --git a/setup.py b/setup.py deleted file mode 100644 index 4ee4437..0000000 --- a/setup.py +++ /dev/null @@ -1,7 +0,0 @@ -from setuptools import setup - -if __name__ == "__main__": - setup( - install_requires=[], - extras_require={"dev": ["pytest", "pytest-random-order", "coverage"]}, - ) diff --git a/tests/tests_bec_ipython_client/README.md b/tests/tests_bec_ipython_client/README.md new file mode 100644 index 0000000..5762245 --- /dev/null +++ b/tests/tests_bec_ipython_client/README.md @@ -0,0 +1,31 @@ +# Getting Started with Testing using pytest + +BEC is using the [pytest](https://docs.pytest.org/en/8.0.x/) framework. +It can be install via +``` bash +pip install pytest +``` +in your *python environment*. +We note that pytest is part of the optional-dependencies `[dev]` of the plugin package. + +## Introduction + +Tests in this package should be stored in the `tests` directory. +We suggest to sort tests of different submodules, i.e. `scans` or `devices` in the respective folder structure, and to folow a naming convention of ``. + +To run all tests, navigate to the directory of the plugin from the command line, and run the command + +``` bash +pytest -v --random-order ./tests +``` +Note, the python environment needs to be active. +The additional arg `-v` allows pytest to run in verbose mode which provides more detailed information about the tests being run. +The argument `--random-order` instructs pytest to run the tests in random order, which is the default in the CI pipelines. + +## Test examples + +Writing tests can be quite specific for the given function. +We recommend writing tests as isolated as possible, i.e. try to test single functions instead of full classes. +A very useful class to enable isolated testing is [MagicMock](https://docs.python.org/3/library/unittest.mock.html). +In addition, we also recommend to take a look at the [How-to guides from pytest](https://docs.pytest.org/en/8.0.x/how-to/index.html). + diff --git a/tests/tests_bec_widgets/README.md b/tests/tests_bec_widgets/README.md new file mode 100644 index 0000000..5762245 --- /dev/null +++ b/tests/tests_bec_widgets/README.md @@ -0,0 +1,31 @@ +# Getting Started with Testing using pytest + +BEC is using the [pytest](https://docs.pytest.org/en/8.0.x/) framework. +It can be install via +``` bash +pip install pytest +``` +in your *python environment*. +We note that pytest is part of the optional-dependencies `[dev]` of the plugin package. + +## Introduction + +Tests in this package should be stored in the `tests` directory. +We suggest to sort tests of different submodules, i.e. `scans` or `devices` in the respective folder structure, and to folow a naming convention of ``. + +To run all tests, navigate to the directory of the plugin from the command line, and run the command + +``` bash +pytest -v --random-order ./tests +``` +Note, the python environment needs to be active. +The additional arg `-v` allows pytest to run in verbose mode which provides more detailed information about the tests being run. +The argument `--random-order` instructs pytest to run the tests in random order, which is the default in the CI pipelines. + +## Test examples + +Writing tests can be quite specific for the given function. +We recommend writing tests as isolated as possible, i.e. try to test single functions instead of full classes. +A very useful class to enable isolated testing is [MagicMock](https://docs.python.org/3/library/unittest.mock.html). +In addition, we also recommend to take a look at the [How-to guides from pytest](https://docs.pytest.org/en/8.0.x/how-to/index.html). + diff --git a/tests/tests_dap_services/README.md b/tests/tests_dap_services/README.md new file mode 100644 index 0000000..5762245 --- /dev/null +++ b/tests/tests_dap_services/README.md @@ -0,0 +1,31 @@ +# Getting Started with Testing using pytest + +BEC is using the [pytest](https://docs.pytest.org/en/8.0.x/) framework. +It can be install via +``` bash +pip install pytest +``` +in your *python environment*. +We note that pytest is part of the optional-dependencies `[dev]` of the plugin package. + +## Introduction + +Tests in this package should be stored in the `tests` directory. +We suggest to sort tests of different submodules, i.e. `scans` or `devices` in the respective folder structure, and to folow a naming convention of ``. + +To run all tests, navigate to the directory of the plugin from the command line, and run the command + +``` bash +pytest -v --random-order ./tests +``` +Note, the python environment needs to be active. +The additional arg `-v` allows pytest to run in verbose mode which provides more detailed information about the tests being run. +The argument `--random-order` instructs pytest to run the tests in random order, which is the default in the CI pipelines. + +## Test examples + +Writing tests can be quite specific for the given function. +We recommend writing tests as isolated as possible, i.e. try to test single functions instead of full classes. +A very useful class to enable isolated testing is [MagicMock](https://docs.python.org/3/library/unittest.mock.html). +In addition, we also recommend to take a look at the [How-to guides from pytest](https://docs.pytest.org/en/8.0.x/how-to/index.html). + diff --git a/tests/tests_devices/README.md b/tests/tests_devices/README.md new file mode 100644 index 0000000..5762245 --- /dev/null +++ b/tests/tests_devices/README.md @@ -0,0 +1,31 @@ +# Getting Started with Testing using pytest + +BEC is using the [pytest](https://docs.pytest.org/en/8.0.x/) framework. +It can be install via +``` bash +pip install pytest +``` +in your *python environment*. +We note that pytest is part of the optional-dependencies `[dev]` of the plugin package. + +## Introduction + +Tests in this package should be stored in the `tests` directory. +We suggest to sort tests of different submodules, i.e. `scans` or `devices` in the respective folder structure, and to folow a naming convention of ``. + +To run all tests, navigate to the directory of the plugin from the command line, and run the command + +``` bash +pytest -v --random-order ./tests +``` +Note, the python environment needs to be active. +The additional arg `-v` allows pytest to run in verbose mode which provides more detailed information about the tests being run. +The argument `--random-order` instructs pytest to run the tests in random order, which is the default in the CI pipelines. + +## Test examples + +Writing tests can be quite specific for the given function. +We recommend writing tests as isolated as possible, i.e. try to test single functions instead of full classes. +A very useful class to enable isolated testing is [MagicMock](https://docs.python.org/3/library/unittest.mock.html). +In addition, we also recommend to take a look at the [How-to guides from pytest](https://docs.pytest.org/en/8.0.x/how-to/index.html). + diff --git a/tests/tests_scans/README.md b/tests/tests_scans/README.md new file mode 100644 index 0000000..5762245 --- /dev/null +++ b/tests/tests_scans/README.md @@ -0,0 +1,31 @@ +# Getting Started with Testing using pytest + +BEC is using the [pytest](https://docs.pytest.org/en/8.0.x/) framework. +It can be install via +``` bash +pip install pytest +``` +in your *python environment*. +We note that pytest is part of the optional-dependencies `[dev]` of the plugin package. + +## Introduction + +Tests in this package should be stored in the `tests` directory. +We suggest to sort tests of different submodules, i.e. `scans` or `devices` in the respective folder structure, and to folow a naming convention of ``. + +To run all tests, navigate to the directory of the plugin from the command line, and run the command + +``` bash +pytest -v --random-order ./tests +``` +Note, the python environment needs to be active. +The additional arg `-v` allows pytest to run in verbose mode which provides more detailed information about the tests being run. +The argument `--random-order` instructs pytest to run the tests in random order, which is the default in the CI pipelines. + +## Test examples + +Writing tests can be quite specific for the given function. +We recommend writing tests as isolated as possible, i.e. try to test single functions instead of full classes. +A very useful class to enable isolated testing is [MagicMock](https://docs.python.org/3/library/unittest.mock.html). +In addition, we also recommend to take a look at the [How-to guides from pytest](https://docs.pytest.org/en/8.0.x/how-to/index.html). +