Compare commits
1 Commits
main
...
ci/gitea_t
| Author | SHA1 | Date | |
|---|---|---|---|
| 1d41550de0 |
@@ -1,9 +0,0 @@
|
|||||||
# Do not edit this file!
|
|
||||||
# It is needed to track the repo template version, and editing may break things.
|
|
||||||
# This file will be overwritten by copier on template updates.
|
|
||||||
|
|
||||||
_commit: v1.2.8
|
|
||||||
_src_path: https://github.com/bec-project/plugin_copier_template.git
|
|
||||||
make_commit: false
|
|
||||||
project_name: phoenix_bec
|
|
||||||
widget_plugins_input: []
|
|
||||||
@@ -1,102 +0,0 @@
|
|||||||
name: CI for phoenix_bec
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
pull_request:
|
|
||||||
workflow_dispatch:
|
|
||||||
inputs:
|
|
||||||
BEC_WIDGETS_BRANCH:
|
|
||||||
description: "Branch of BEC Widgets to install"
|
|
||||||
required: false
|
|
||||||
type: string
|
|
||||||
default: "main"
|
|
||||||
BEC_CORE_BRANCH:
|
|
||||||
description: "Branch of BEC Core to install"
|
|
||||||
required: false
|
|
||||||
type: string
|
|
||||||
default: "main"
|
|
||||||
OPHYD_DEVICES_BRANCH:
|
|
||||||
description: "Branch of Ophyd Devices to install"
|
|
||||||
required: false
|
|
||||||
type: string
|
|
||||||
default: "main"
|
|
||||||
BEC_PLUGIN_REPO_BRANCH:
|
|
||||||
description: "Branch of the BEC Plugin Repository to install"
|
|
||||||
required: false
|
|
||||||
type: string
|
|
||||||
default: "main"
|
|
||||||
PYTHON_VERSION:
|
|
||||||
description: "Python version to use"
|
|
||||||
required: false
|
|
||||||
type: string
|
|
||||||
default: "3.12"
|
|
||||||
|
|
||||||
permissions:
|
|
||||||
pull-requests: write
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
test:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
env:
|
|
||||||
QTWEBENGINE_DISABLE_SANDBOX: 1
|
|
||||||
QT_QPA_PLATFORM: "offscreen"
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- name: Setup Python
|
|
||||||
uses: actions/setup-python@v5
|
|
||||||
with:
|
|
||||||
python-version: "${{ inputs.PYTHON_VERSION || '3.12' }}"
|
|
||||||
|
|
||||||
- name: Checkout BEC Plugin Repository
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
with:
|
|
||||||
repository: bec/phoenix_bec
|
|
||||||
ref: "${{ inputs.BEC_PLUGIN_REPO_BRANCH || github.head_ref || github.sha }}"
|
|
||||||
path: ./phoenix_bec
|
|
||||||
|
|
||||||
- name: Lint for merge conflicts from template updates
|
|
||||||
shell: bash
|
|
||||||
# Find all Copier conflicts except this line
|
|
||||||
run: '! grep -r "<<<<<<< before updating" | grep -v "grep -r \"<<<<<<< before updating"'
|
|
||||||
|
|
||||||
- name: Checkout BEC Core
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
with:
|
|
||||||
repository: bec/bec
|
|
||||||
ref: "${{ inputs.BEC_CORE_BRANCH || 'main' }}"
|
|
||||||
path: ./bec
|
|
||||||
|
|
||||||
- name: Checkout Ophyd Devices
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
with:
|
|
||||||
repository: bec/ophyd_devices
|
|
||||||
ref: "${{ inputs.OPHYD_DEVICES_BRANCH || 'main' }}"
|
|
||||||
path: ./ophyd_devices
|
|
||||||
|
|
||||||
- name: Checkout BEC Widgets
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
with:
|
|
||||||
repository: bec/bec_widgets
|
|
||||||
ref: "${{ inputs.BEC_WIDGETS_BRANCH || 'main' }}"
|
|
||||||
path: ./bec_widgets
|
|
||||||
|
|
||||||
- name: Install dependencies
|
|
||||||
shell: bash
|
|
||||||
run: |
|
|
||||||
sudo apt-get update
|
|
||||||
sudo apt-get install -y libgl1 libegl1 x11-utils libxkbcommon-x11-0 libdbus-1-3 xvfb
|
|
||||||
sudo apt-get -y install libnss3 libxdamage1 libasound2t64 libatomic1 libxcursor1
|
|
||||||
|
|
||||||
- name: Install Python dependencies
|
|
||||||
shell: bash
|
|
||||||
run: |
|
|
||||||
pip install uv
|
|
||||||
uv pip install --system -e ./ophyd_devices
|
|
||||||
uv pip install --system -e ./bec/bec_lib[dev]
|
|
||||||
uv pip install --system -e ./bec/bec_ipython_client
|
|
||||||
uv pip install --system -e ./bec/bec_server[dev]
|
|
||||||
uv pip install --system -e ./bec_widgets[dev,pyside6]
|
|
||||||
uv pip install --system -e ./phoenix_bec
|
|
||||||
|
|
||||||
- name: Run Pytest with Coverage
|
|
||||||
id: coverage
|
|
||||||
run: pytest --random-order --cov=./phoenix_bec --cov-config=./phoenix_bec/pyproject.toml --cov-branch --cov-report=xml --no-cov-on-fail ./phoenix_bec/tests/ || test $? -eq 5
|
|
||||||
@@ -1,62 +0,0 @@
|
|||||||
name: Create template upgrade PR for phoenix_bec
|
|
||||||
on:
|
|
||||||
workflow_dispatch:
|
|
||||||
|
|
||||||
permissions:
|
|
||||||
pull-requests: write
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
create_update_branch_and_pr:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
permissions:
|
|
||||||
contents: write
|
|
||||||
pull-requests: write
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- name: Setup Python
|
|
||||||
uses: actions/setup-python@v5
|
|
||||||
with:
|
|
||||||
python-version: '3.12'
|
|
||||||
|
|
||||||
- name: Install tools
|
|
||||||
run: |
|
|
||||||
pip install copier PySide6
|
|
||||||
|
|
||||||
- name: Checkout
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
|
|
||||||
- name: Perform update
|
|
||||||
run: |
|
|
||||||
git config --global user.email "bec_ci_staging@psi.ch"
|
|
||||||
git config --global user.name "BEC automated CI"
|
|
||||||
|
|
||||||
branch="chore/update-template-$(python -m uuid)"
|
|
||||||
echo "switching to branch $branch"
|
|
||||||
git checkout -b $branch
|
|
||||||
|
|
||||||
echo "Running copier update..."
|
|
||||||
output="$(copier update --trust --defaults --conflict inline 2>&1)"
|
|
||||||
echo "$output"
|
|
||||||
msg="$(printf '%s\n' "$output" | head -n 1)"
|
|
||||||
|
|
||||||
if ! grep -q "make_commit: true" .copier-answers.yml ; then
|
|
||||||
echo "Autocommit not made, committing..."
|
|
||||||
git add -A
|
|
||||||
git commit -a -m "$msg"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if diff-index --quiet HEAD ; then
|
|
||||||
echo "No changes detected"
|
|
||||||
exit 0
|
|
||||||
fi
|
|
||||||
|
|
||||||
git push -u origin $branch
|
|
||||||
curl -X POST "https://gitea.psi.ch/api/v1/repos/${{ gitea.repository }}/pulls" \
|
|
||||||
-H "Authorization: token ${{ secrets.CI_REPO_WRITE }}" \
|
|
||||||
-H "Content-Type: application/json" \
|
|
||||||
-d "{
|
|
||||||
\"title\": \"Template: $(echo $msg)\",
|
|
||||||
\"body\": \"This PR was created by Gitea Actions\",
|
|
||||||
\"head\": \"$(echo $branch)\",
|
|
||||||
\"base\": \"main\"
|
|
||||||
}"
|
|
||||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -7,6 +7,7 @@
|
|||||||
**/.vscode
|
**/.vscode
|
||||||
**/.pytest_cache
|
**/.pytest_cache
|
||||||
**/*.egg*
|
**/*.egg*
|
||||||
|
*.gz
|
||||||
|
|
||||||
# recovery_config files
|
# recovery_config files
|
||||||
recovery_config_*
|
recovery_config_*
|
||||||
|
|||||||
6
.gitlab-ci.yml
Normal file
6
.gitlab-ci.yml
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
include:
|
||||||
|
- file: /templates/plugin-repo-template.yml
|
||||||
|
inputs:
|
||||||
|
name: phoenix_bec
|
||||||
|
target: phoenix_bec
|
||||||
|
project: bec/awi_utils
|
||||||
5
LICENSE
5
LICENSE
@@ -1,7 +1,6 @@
|
|||||||
|
|
||||||
BSD 3-Clause License
|
BSD 3-Clause License
|
||||||
|
|
||||||
Copyright (c) 2025, Paul Scherrer Institute
|
Copyright (c) 2024, Paul Scherrer Institute
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without
|
Redistribution and use in source and binary forms, with or without
|
||||||
modification, are permitted provided that the following conditions are met:
|
modification, are permitted provided that the following conditions are met:
|
||||||
@@ -26,4 +25,4 @@ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|||||||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|||||||
1
bin/.gitignore
vendored
1
bin/.gitignore
vendored
@@ -1 +0,0 @@
|
|||||||
# Add anything you don't want to check in to git, e.g. very large files
|
|
||||||
@@ -1,14 +1,10 @@
|
|||||||
"""
|
"""
|
||||||
Pre-startup script for BEC client. This script is executed before the BEC client
|
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.
|
is started. It can be used to add additional command line arguments.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import os
|
|
||||||
|
|
||||||
from bec_lib.service_config import ServiceConfig
|
from bec_lib.service_config import ServiceConfig
|
||||||
|
|
||||||
import phoenix_bec
|
|
||||||
|
|
||||||
|
|
||||||
def extend_command_line_args(parser):
|
def extend_command_line_args(parser):
|
||||||
"""
|
"""
|
||||||
@@ -19,13 +15,9 @@ def extend_command_line_args(parser):
|
|||||||
|
|
||||||
return parser
|
return parser
|
||||||
|
|
||||||
def get_config() -> ServiceConfig:
|
|
||||||
"""
|
# def get_config() -> ServiceConfig:
|
||||||
Create and return the ServiceConfig for the plugin repository
|
# """
|
||||||
"""
|
# Create and return the service configuration.
|
||||||
deployment_path = os.path.dirname(os.path.dirname(os.path.dirname(phoenix_bec.__file__)))
|
# """
|
||||||
files = os.listdir(deployment_path)
|
# return ServiceConfig(redis={"host": "localhost", "port": 6379})
|
||||||
if "bec_config.yaml" in files:
|
|
||||||
return ServiceConfig(config_path=os.path.join(deployment_path, "bec_config.yaml"))
|
|
||||||
else:
|
|
||||||
return ServiceConfig(redis={"host": "localhost", "port": 6379})
|
|
||||||
|
|||||||
@@ -1,6 +0,0 @@
|
|||||||
# Macros
|
|
||||||
|
|
||||||
This directory is intended to store macros which will be loaded automatically when starting BEC.
|
|
||||||
Macros are small functions to make repetitive tasks easier. Functions defined in python files in this directory will be accessible from the BEC console.
|
|
||||||
Please do not put any code outside of function definitions here. If you wish for code to be automatically run when starting BEC, see the startup script at phoenix_bec/bec_ipython_client/startup/post_startup.py
|
|
||||||
For a guide on writing macros, please see: https://bec.readthedocs.io/en/latest/user/command_line_interface.html#how-to-write-a-macro
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
# from .metadata_schema_template import ExampleSchema
|
|
||||||
|
|
||||||
METADATA_SCHEMA_REGISTRY = {
|
|
||||||
# Add models which should be used to validate scan metadata here.
|
|
||||||
# Make a model according to the template, and import it as above
|
|
||||||
# Then associate it with a scan like so:
|
|
||||||
# "example_scan": ExampleSchema
|
|
||||||
}
|
|
||||||
|
|
||||||
# Define a default schema type which should be used as the fallback for everything:
|
|
||||||
|
|
||||||
DEFAULT_SCHEMA = None
|
|
||||||
@@ -1,34 +0,0 @@
|
|||||||
# # By inheriting from BasicScanMetadata you can define a schema by which metadata
|
|
||||||
# # supplied to a scan must be validated.
|
|
||||||
# # This schema is a Pydantic model: https://docs.pydantic.dev/latest/concepts/models/
|
|
||||||
# # but by default it will still allow you to add any arbitrary information to it.
|
|
||||||
# # That is to say, when you run a scan with which such a model has been associated in the
|
|
||||||
# # metadata_schema_registry, you can supply any python dictionary with strings as keys
|
|
||||||
# # and built-in python types (strings, integers, floats) as values, and these will be
|
|
||||||
# # added to the experiment metadata, but it *must* contain the keys and values of the
|
|
||||||
# # types defined in the schema class.
|
|
||||||
# #
|
|
||||||
# #
|
|
||||||
# # For example, say that you would like to enforce recording information about sample
|
|
||||||
# # pretreatment, you could define the following:
|
|
||||||
# #
|
|
||||||
#
|
|
||||||
# from bec_lib.metadata_schema import BasicScanMetadata
|
|
||||||
#
|
|
||||||
#
|
|
||||||
# class ExampleSchema(BasicScanMetadata):
|
|
||||||
# treatment_description: str
|
|
||||||
# treatment_temperature_k: int
|
|
||||||
#
|
|
||||||
#
|
|
||||||
# # If this was used according to the example in metadata_schema_registry.py,
|
|
||||||
# # then when calling the scan, the user would need to write something like:
|
|
||||||
# >>> scans.example_scan(
|
|
||||||
# >>> motor,
|
|
||||||
# >>> 1,
|
|
||||||
# >>> 2,
|
|
||||||
# >>> 3,
|
|
||||||
# >>> metadata={"treatment_description": "oven overnight", "treatment_temperature_k": 575},
|
|
||||||
# >>> )
|
|
||||||
#
|
|
||||||
# # And the additional metadata would be saved in the HDF5 file created for the scan.
|
|
||||||
@@ -32,8 +32,6 @@ logger = bec_logger.logger
|
|||||||
# .. define base path for directory with scripts
|
# .. define base path for directory with scripts
|
||||||
|
|
||||||
|
|
||||||
# next version V2
|
|
||||||
|
|
||||||
class PhoenixBL:
|
class PhoenixBL:
|
||||||
"""
|
"""
|
||||||
#
|
#
|
||||||
|
|||||||
@@ -5,8 +5,8 @@ build-backend = "hatchling.build"
|
|||||||
[project]
|
[project]
|
||||||
name = "phoenix_bec"
|
name = "phoenix_bec"
|
||||||
version = "0.0.0"
|
version = "0.0.0"
|
||||||
description = "A plugin repository for BEC"
|
description = "Custom device implementations based on the ophyd hardware abstraction layer"
|
||||||
requires-python = ">=3.11"
|
requires-python = ">=3.10"
|
||||||
classifiers = [
|
classifiers = [
|
||||||
"Development Status :: 3 - Alpha",
|
"Development Status :: 3 - Alpha",
|
||||||
"Programming Language :: Python :: 3",
|
"Programming Language :: Python :: 3",
|
||||||
@@ -17,7 +17,6 @@ dependencies = []
|
|||||||
[project.optional-dependencies]
|
[project.optional-dependencies]
|
||||||
dev = [
|
dev = [
|
||||||
"black",
|
"black",
|
||||||
"copier",
|
|
||||||
"isort",
|
"isort",
|
||||||
"coverage",
|
"coverage",
|
||||||
"pylint",
|
"pylint",
|
||||||
@@ -39,15 +38,12 @@ plugin_file_writer = "phoenix_bec.file_writer"
|
|||||||
[project.entry-points."bec.scans"]
|
[project.entry-points."bec.scans"]
|
||||||
plugin_scans = "phoenix_bec.scans"
|
plugin_scans = "phoenix_bec.scans"
|
||||||
|
|
||||||
[project.entry-points."bec.scans.metadata_schema"]
|
|
||||||
plugin_metadata_schema = "phoenix_bec.scans.metadata_schema"
|
|
||||||
|
|
||||||
[project.entry-points."bec.ipython_client_startup"]
|
[project.entry-points."bec.ipython_client_startup"]
|
||||||
plugin_ipython_client_pre = "phoenix_bec.bec_ipython_client.startup.pre_startup"
|
plugin_ipython_client_pre = "phoenix_bec.bec_ipython_client.startup.pre_startup"
|
||||||
plugin_ipython_client_post = "phoenix_bec.bec_ipython_client.startup"
|
plugin_ipython_client_post = "phoenix_bec.bec_ipython_client.startup"
|
||||||
|
|
||||||
[project.entry-points."bec.widgets.auto_updates"]
|
[project.entry-points."bec.widgets.auto_updates"]
|
||||||
plugin_widgets_update = "phoenix_bec.bec_widgets.auto_updates"
|
plugin_widgets_update = "phoenix_bec.bec_widgets.auto_updates:PlotUpdate"
|
||||||
|
|
||||||
[project.entry-points."bec.widgets.user_widgets"]
|
[project.entry-points."bec.widgets.user_widgets"]
|
||||||
plugin_widgets = "phoenix_bec.bec_widgets.widgets"
|
plugin_widgets = "phoenix_bec.bec_widgets.widgets"
|
||||||
|
|||||||
@@ -1,34 +1,31 @@
|
|||||||
# Getting Started with Testing using pytest
|
# Getting Started with Testing using pytest
|
||||||
|
|
||||||
BEC is using the [pytest](https://docs.pytest.org/en/latest/) framework.
|
BEC is using the [pytest](https://docs.pytest.org/en/8.0.x/) framework.
|
||||||
It can be installed via
|
It can be install via
|
||||||
|
``` bash
|
||||||
```bash
|
|
||||||
pip install pytest
|
pip install pytest
|
||||||
```
|
```
|
||||||
|
in your *python environment*.
|
||||||
in your _python environment_.
|
|
||||||
We note that pytest is part of the optional-dependencies `[dev]` of the plugin package.
|
We note that pytest is part of the optional-dependencies `[dev]` of the plugin package.
|
||||||
|
|
||||||
## Introduction
|
## Introduction
|
||||||
|
|
||||||
Tests in this package should be stored in the `tests` directory.
|
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 `<test_module_name.py>`.
|
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 `<test_module_name.py>`.
|
||||||
It is mandatory for test files to begin with `test_` for pytest to discover them.
|
|
||||||
|
|
||||||
To run all tests, navigate to the directory of the plugin from the command line, and run the command
|
To run all tests, navigate to the directory of the plugin from the command line, and run the command
|
||||||
|
|
||||||
```bash
|
``` bash
|
||||||
pytest -v --random-order ./tests
|
pytest -v --random-order ./tests
|
||||||
```
|
```
|
||||||
|
|
||||||
Note, the python environment needs to be active.
|
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 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.
|
The argument `--random-order` instructs pytest to run the tests in random order, which is the default in the CI pipelines.
|
||||||
|
|
||||||
## Test examples
|
## Test examples
|
||||||
|
|
||||||
Writing tests can be quite specific for the given function.
|
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.
|
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).
|
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).
|
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).
|
||||||
|
|
||||||
|
|||||||
@@ -1,34 +1,31 @@
|
|||||||
# Getting Started with Testing using pytest
|
# Getting Started with Testing using pytest
|
||||||
|
|
||||||
BEC is using the [pytest](https://docs.pytest.org/en/latest/) framework.
|
BEC is using the [pytest](https://docs.pytest.org/en/8.0.x/) framework.
|
||||||
It can be installed via
|
It can be install via
|
||||||
|
``` bash
|
||||||
```bash
|
|
||||||
pip install pytest
|
pip install pytest
|
||||||
```
|
```
|
||||||
|
in your *python environment*.
|
||||||
in your _python environment_.
|
|
||||||
We note that pytest is part of the optional-dependencies `[dev]` of the plugin package.
|
We note that pytest is part of the optional-dependencies `[dev]` of the plugin package.
|
||||||
|
|
||||||
## Introduction
|
## Introduction
|
||||||
|
|
||||||
Tests in this package should be stored in the `tests` directory.
|
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 `<test_module_name.py>`.
|
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 `<test_module_name.py>`.
|
||||||
It is mandatory for test files to begin with `test_` for pytest to discover them.
|
|
||||||
|
|
||||||
To run all tests, navigate to the directory of the plugin from the command line, and run the command
|
To run all tests, navigate to the directory of the plugin from the command line, and run the command
|
||||||
|
|
||||||
```bash
|
``` bash
|
||||||
pytest -v --random-order ./tests
|
pytest -v --random-order ./tests
|
||||||
```
|
```
|
||||||
|
|
||||||
Note, the python environment needs to be active.
|
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 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.
|
The argument `--random-order` instructs pytest to run the tests in random order, which is the default in the CI pipelines.
|
||||||
|
|
||||||
## Test examples
|
## Test examples
|
||||||
|
|
||||||
Writing tests can be quite specific for the given function.
|
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.
|
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).
|
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).
|
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).
|
||||||
|
|
||||||
|
|||||||
@@ -1,34 +1,31 @@
|
|||||||
# Getting Started with Testing using pytest
|
# Getting Started with Testing using pytest
|
||||||
|
|
||||||
BEC is using the [pytest](https://docs.pytest.org/en/latest/) framework.
|
BEC is using the [pytest](https://docs.pytest.org/en/8.0.x/) framework.
|
||||||
It can be installed via
|
It can be install via
|
||||||
|
``` bash
|
||||||
```bash
|
|
||||||
pip install pytest
|
pip install pytest
|
||||||
```
|
```
|
||||||
|
in your *python environment*.
|
||||||
in your _python environment_.
|
|
||||||
We note that pytest is part of the optional-dependencies `[dev]` of the plugin package.
|
We note that pytest is part of the optional-dependencies `[dev]` of the plugin package.
|
||||||
|
|
||||||
## Introduction
|
## Introduction
|
||||||
|
|
||||||
Tests in this package should be stored in the `tests` directory.
|
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 `<test_module_name.py>`.
|
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 `<test_module_name.py>`.
|
||||||
It is mandatory for test files to begin with `test_` for pytest to discover them.
|
|
||||||
|
|
||||||
To run all tests, navigate to the directory of the plugin from the command line, and run the command
|
To run all tests, navigate to the directory of the plugin from the command line, and run the command
|
||||||
|
|
||||||
```bash
|
``` bash
|
||||||
pytest -v --random-order ./tests
|
pytest -v --random-order ./tests
|
||||||
```
|
```
|
||||||
|
|
||||||
Note, the python environment needs to be active.
|
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 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.
|
The argument `--random-order` instructs pytest to run the tests in random order, which is the default in the CI pipelines.
|
||||||
|
|
||||||
## Test examples
|
## Test examples
|
||||||
|
|
||||||
Writing tests can be quite specific for the given function.
|
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.
|
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).
|
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).
|
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).
|
||||||
|
|
||||||
|
|||||||
@@ -1,34 +1,31 @@
|
|||||||
# Getting Started with Testing using pytest
|
# Getting Started with Testing using pytest
|
||||||
|
|
||||||
BEC is using the [pytest](https://docs.pytest.org/en/latest/) framework.
|
BEC is using the [pytest](https://docs.pytest.org/en/8.0.x/) framework.
|
||||||
It can be installed via
|
It can be install via
|
||||||
|
``` bash
|
||||||
```bash
|
|
||||||
pip install pytest
|
pip install pytest
|
||||||
```
|
```
|
||||||
|
in your *python environment*.
|
||||||
in your _python environment_.
|
|
||||||
We note that pytest is part of the optional-dependencies `[dev]` of the plugin package.
|
We note that pytest is part of the optional-dependencies `[dev]` of the plugin package.
|
||||||
|
|
||||||
## Introduction
|
## Introduction
|
||||||
|
|
||||||
Tests in this package should be stored in the `tests` directory.
|
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 `<test_module_name.py>`.
|
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 `<test_module_name.py>`.
|
||||||
It is mandatory for test files to begin with `test_` for pytest to discover them.
|
|
||||||
|
|
||||||
To run all tests, navigate to the directory of the plugin from the command line, and run the command
|
To run all tests, navigate to the directory of the plugin from the command line, and run the command
|
||||||
|
|
||||||
```bash
|
``` bash
|
||||||
pytest -v --random-order ./tests
|
pytest -v --random-order ./tests
|
||||||
```
|
```
|
||||||
|
|
||||||
Note, the python environment needs to be active.
|
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 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.
|
The argument `--random-order` instructs pytest to run the tests in random order, which is the default in the CI pipelines.
|
||||||
|
|
||||||
## Test examples
|
## Test examples
|
||||||
|
|
||||||
Writing tests can be quite specific for the given function.
|
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.
|
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).
|
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).
|
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).
|
||||||
|
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ def mock_trigger():
|
|||||||
name = "phoenix_trigger"
|
name = "phoenix_trigger"
|
||||||
prefix = "X07MB-OP2:"
|
prefix = "X07MB-OP2:"
|
||||||
dm = DMMock()
|
dm = DMMock()
|
||||||
with mock.patch.object(dm, "connector"):
|
with mock.patch.object(dm, "connecto"):
|
||||||
with (
|
with (
|
||||||
mock.patch(
|
mock.patch(
|
||||||
"ophyd_devices.interfaces.base_classes.bec_device_base.FileWriter"
|
"ophyd_devices.interfaces.base_classes.bec_device_base.FileWriter"
|
||||||
|
|||||||
@@ -1,34 +1,31 @@
|
|||||||
# Getting Started with Testing using pytest
|
# Getting Started with Testing using pytest
|
||||||
|
|
||||||
BEC is using the [pytest](https://docs.pytest.org/en/latest/) framework.
|
BEC is using the [pytest](https://docs.pytest.org/en/8.0.x/) framework.
|
||||||
It can be installed via
|
It can be install via
|
||||||
|
``` bash
|
||||||
```bash
|
|
||||||
pip install pytest
|
pip install pytest
|
||||||
```
|
```
|
||||||
|
in your *python environment*.
|
||||||
in your _python environment_.
|
|
||||||
We note that pytest is part of the optional-dependencies `[dev]` of the plugin package.
|
We note that pytest is part of the optional-dependencies `[dev]` of the plugin package.
|
||||||
|
|
||||||
## Introduction
|
## Introduction
|
||||||
|
|
||||||
Tests in this package should be stored in the `tests` directory.
|
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 `<test_module_name.py>`.
|
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 `<test_module_name.py>`.
|
||||||
It is mandatory for test files to begin with `test_` for pytest to discover them.
|
|
||||||
|
|
||||||
To run all tests, navigate to the directory of the plugin from the command line, and run the command
|
To run all tests, navigate to the directory of the plugin from the command line, and run the command
|
||||||
|
|
||||||
```bash
|
``` bash
|
||||||
pytest -v --random-order ./tests
|
pytest -v --random-order ./tests
|
||||||
```
|
```
|
||||||
|
|
||||||
Note, the python environment needs to be active.
|
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 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.
|
The argument `--random-order` instructs pytest to run the tests in random order, which is the default in the CI pipelines.
|
||||||
|
|
||||||
## Test examples
|
## Test examples
|
||||||
|
|
||||||
Writing tests can be quite specific for the given function.
|
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.
|
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).
|
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).
|
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).
|
||||||
|
|
||||||
|
|||||||
@@ -1,34 +1,31 @@
|
|||||||
# Getting Started with Testing using pytest
|
# Getting Started with Testing using pytest
|
||||||
|
|
||||||
BEC is using the [pytest](https://docs.pytest.org/en/latest/) framework.
|
BEC is using the [pytest](https://docs.pytest.org/en/8.0.x/) framework.
|
||||||
It can be installed via
|
It can be install via
|
||||||
|
``` bash
|
||||||
```bash
|
|
||||||
pip install pytest
|
pip install pytest
|
||||||
```
|
```
|
||||||
|
in your *python environment*.
|
||||||
in your _python environment_.
|
|
||||||
We note that pytest is part of the optional-dependencies `[dev]` of the plugin package.
|
We note that pytest is part of the optional-dependencies `[dev]` of the plugin package.
|
||||||
|
|
||||||
## Introduction
|
## Introduction
|
||||||
|
|
||||||
Tests in this package should be stored in the `tests` directory.
|
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 `<test_module_name.py>`.
|
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 `<test_module_name.py>`.
|
||||||
It is mandatory for test files to begin with `test_` for pytest to discover them.
|
|
||||||
|
|
||||||
To run all tests, navigate to the directory of the plugin from the command line, and run the command
|
To run all tests, navigate to the directory of the plugin from the command line, and run the command
|
||||||
|
|
||||||
```bash
|
``` bash
|
||||||
pytest -v --random-order ./tests
|
pytest -v --random-order ./tests
|
||||||
```
|
```
|
||||||
|
|
||||||
Note, the python environment needs to be active.
|
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 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.
|
The argument `--random-order` instructs pytest to run the tests in random order, which is the default in the CI pipelines.
|
||||||
|
|
||||||
## Test examples
|
## Test examples
|
||||||
|
|
||||||
Writing tests can be quite specific for the given function.
|
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.
|
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).
|
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).
|
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).
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user