Skip to main content

Python script for converting a Robot Framework file to a reStructuredText (.rst) file

Project description

Build status Documentation Contributions welcome

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. This functionality is provided for test case documentation only.

# 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]
                            [--enable-bold-headers] [--trailing-continuation]
                            [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.
  --enable-bold-headers
                        Make sure that bold lines are seen as header.
  --trailing-continuation
                        Add a trailing '...' continuation to preserve a blank line at the
                        end of the docstring.

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mlx_robot2rst-3.7.1.tar.gz (36.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mlx_robot2rst-3.7.1-py2.py3-none-any.whl (28.8 kB view details)

Uploaded Python 2Python 3

File details

Details for the file mlx_robot2rst-3.7.1.tar.gz.

File metadata

  • Download URL: mlx_robot2rst-3.7.1.tar.gz
  • Upload date:
  • Size: 36.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for mlx_robot2rst-3.7.1.tar.gz
Algorithm Hash digest
SHA256 e9ed42c8aad52c73f826c6de8051ee88c8b88d90879598acce6104003ac80a68
MD5 e02e5b97f77df88ed8fbb17d8da2d843
BLAKE2b-256 b80429f2f6d1c95fdfb45084cd75fbb07984d24c382a96cbe2eb0a81cb7fab76

See more details on using hashes here.

File details

Details for the file mlx_robot2rst-3.7.1-py2.py3-none-any.whl.

File metadata

  • Download URL: mlx_robot2rst-3.7.1-py2.py3-none-any.whl
  • Upload date:
  • Size: 28.8 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for mlx_robot2rst-3.7.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 a27ca6e2515b92ebd3770f87d42820377047f3209d77e67b8e776dceca432680
MD5 fe67c4d42fe2e7fb78955fe64033658b
BLAKE2b-256 82c6c435d6daa6420fe3220473c4bbe958885858a3045c2a4081e91e5c66ea04

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page