Python script for converting a Robot Framework file to a reStructuredText (.rst) file
Project description
Documentation robot2rst
This script can convert your .robot files from Robot Framework to reStructuredText (.rst) files with traceable items.
Goal
This script allows you to connect your requirements to test cases via the mlx.traceability Sphinx extension. Test cases get converted to traceable items. The documentation of each test gets used to generate the body of the item. Test case names get converted to item IDs with a configurable prefix. Tags can be used to link to other traceable items.
Usage
$ robot2rst --help
usage: robot2rst [-h] {convert,stylecheck} ...
Convert robot test cases to reStructuredText with traceable items.
positional arguments:
{convert,stylecheck} Available commands
convert Converts a Robot Framework file to a reStructuredText (.rst) file (default).
stylecheck Checks and fixes RST style in Robot documentation blocks.
options:
-h, --help show this help message and exit
examples:
# Convert a file (default command)
robot2rst -i input.robot -o output.rst
# Explicitly call convert
robot2rst convert -i input.robot -o output.rst
# Check style of all .robot files in the current directory and subdirectories
robot2rst stylecheck --fix
Conversion (Default)
To convert a Robot file to RST:
robot2rst -i example.robot -o test_plan.rst --prefix ITEST_MY_LIB- \
--tags SWRQT- SYSRQT- --relationships validates ext_toolname --coverage 100 66.66
$ robot2rst convert --help
usage: robot2rst convert [-h] -i ROBOT_FILE -o RST_FILE [--only EXPRESSION] [-p PREFIX]
[-r [RELATIONSHIPS ...]] [-t [TAGS ...]] [--include [INCLUDE ...]]
[-c [COVERAGE ...]] [--type TYPE] [--trim-suffix]
options:
-h, --help show this help message and exit
-i ROBOT_FILE, --robot ROBOT_FILE
Input robot file
-o RST_FILE, --rst RST_FILE
Output RST file, e.g. my_component_qtp.rst
--only EXPRESSION Expression of tags for Sphinx' `only` directive that surrounds all RST content.
-p PREFIX, --prefix PREFIX
Overrides the default 'QTEST-' prefix.
-r [RELATIONSHIPS ...], --relationships [RELATIONSHIPS ...]
Name(s) of the relationship(s) used to link to items in Tags section. Default:
'validates'.
-t [TAGS ...], --tags [TAGS ...]
Python regexes for matching tags to treat as traceable targets. Matches all by
default.
--include [INCLUDE ...]
Python regexes for matching tags to filter test cases.
-c [COVERAGE ...], --coverage [COVERAGE ...]
Minimum coverage percentages for the item-matrix(es); 1 value per tag in --tags.
--type TYPE Type of test ('q' for qualification, 'i' for integration). Default:
'qualification'.
--trim-suffix If the suffix of any prefix or --tags argument ends with '_-' it gets trimmed to
'-'.
Style Checker & Fixer
You can also check and automatically fix the RST syntax and layout within the [Documentation] blocks of your Robot files.
# Check all .robot files in the current directory
robot2rst stylecheck
# Automatically fix issues and set a custom line length
robot2rst stylecheck --fix --line-length 120
$ robot2rst stylecheck --help
usage: robot2rst stylecheck [-h] [--fix] [--fail-on-layout] [--line-length LINE_LENGTH] [paths ...]
positional arguments:
paths One or more paths to files or folders to check. Default: current directory.
options:
-h, --help show this help message and exit
--fix Automatically fix RST formatting inside Robot documentation blocks.
--fail-on-layout Fail on RST layout issues as well as syntax issues.
--line-length LINE_LENGTH
Max line length for RST blocks (note: the line length does not include the length
of the [Documentation] tag for example). Default: 100.
Pre-commit Hook
You can use robot2rst as a pre-commit hook to ensure your Robot documentation stays correctly formatted. Add this to your .pre-commit-config.yaml:
repos:
- repo: https://github.com/melexis/robot2rst
rev: 3.7.0 # Use the latest stable release
hooks:
- id: robot2rst-stylecheck
args: ["--fix", "--line-length", "100"]
Configuration
To include the script’s output in your documentation you want to add the aforementioned extension to your extensions list in your conf.py like so:
extensions = [
'mlx.traceability',
]
Please read the documentation of mlx.traceability for additional configuration steps.
If you use the --only input argument, you should also add 'sphinx_selective_exclude.eager_only' to the extensions list to prevent mlx.traceability from parsing the content and ignoring the effect of the only directive.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mlx_robot2rst-3.7.0.tar.gz.
File metadata
- Download URL: mlx_robot2rst-3.7.0.tar.gz
- Upload date:
- Size: 33.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a33e17f700bcc7d1640e11b855379e2b54687509e8b1717c159df61c2d83c4ee
|
|
| MD5 |
157d544984c543fc8e2a7795927eb000
|
|
| BLAKE2b-256 |
c2c638a4217515630a0e2e6fa0d9bcc586542550f9012fdbb43e976b1ea23a9a
|
File details
Details for the file mlx_robot2rst-3.7.0-py2.py3-none-any.whl.
File metadata
- Download URL: mlx_robot2rst-3.7.0-py2.py3-none-any.whl
- Upload date:
- Size: 26.0 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
09078d993904cb7ea38079acf5a98250d214e7b0af1fb1d99c66ac7a43ff0026
|
|
| MD5 |
37bcd2092095c8c409c780c5c67dccec
|
|
| BLAKE2b-256 |
321babbd3102f4fd0051241a17b97b95a10b163f269267510db9e64e8852de6d
|