Skip to main content

No project description provided

Project description

Behaviour Driven Development (BDD) testing library.

Rumex is a lightweight library alternative to the behave framework.

Basic example

import rumex

example_file = rumex.InputFile(
    text='''
        Name: Basic example

        Scenario: Simple arithmetics

            Given an integer 1
            And an integer 2
            When addition is performed
            Then the result is 3
    ''',
    uri='in place file, just an example',
)

steps = rumex.StepMapper()


class Context:

    def __init__(self):
        self.integers = []
        self.sum = None


@steps(r'an integer (\d+)')
def store_integer(integer: int, *, context: Context):
    context.integers.append(integer)


@steps(r'addition is performed')
def add(*, context: Context):
    context.sum = sum(context.integers)


@steps(r'the result is (\d+)')
def check_result(expected_result: int, *, context: Context):
    assert expected_result == context.sum


rumex.run(
    files=[example_file],
    steps=steps,
    context_maker=Context,
)

More examples

See docs/examples

API

For complete API documentation see docs/api

rumex.run

rumex.run(
    *,
    files: Iterable[InputFile],
    steps: StepMapperProto,
    context_maker: Callable[[], Any] | None = None,
    parser: ParserProto = rumex.parsing.parser.parse,
    executor: ExecutorProto = rumex.runner.execute_file,
    reporter=rumex.runner.report,
    map_=builtins.map
)

Rumex entry point for running tests.

Parameters

  • files: Files to be parsed and executed.

  • steps: See StepMapper or StepMapperProto for more info.

  • context_maker: A callable that returns an object that can be passed to step functions.

  • parser: A callable that takes InputFile and returns File.

  • executor: A callable that takes File steps and context_maker and returns ExecutedFile.

  • reporter: A callable that takes the collection of all executed files. This can be as simple as raising an exception if any of the executed files is a FailedFile.

  • map_: Must have the same interface as the Python’s built-in map. Custom implementation might be used to speed up file parsing or execution.

rumex.InputFile

Frozen dataclass

rumex.InputFile(
    *,
    uri: str,
    text: str
)

Container for a test file to be parsed.

Does not have to represent an actual file. Could be e.g. an entry in a database.

Parameters

  • uri: A unique identifer. If it’s a file, this could be a path to this file.

  • text: The content of the file.

rumex.StepMapper

Prepare step functions.

Methods

:


before_scenario(
    self,
    callable_: ContextCallable,
    /
)

Register a function to execute at the start of each scenario.

Parameters

  • callable_: The function to be executed.


before_step(
    self,
    callable_: ContextCallable,
    /
)

Register a function to execute before each step.

Parameters

  • callable_: The function to be executed.


__call__(
    self,
    pattern: str
)

Create decorator for registering steps.

For example, to register a function:

def say_hello(person, *, context): ...

to match sentence “Then Bob says hello”, you can do:

steps = StepMapper()

@steps(r'(\w+) says hello')
def say_hello(person, *, context):
    context.get_person(person).say('hello')

Parameters

  • pattern: Regex pattern that will be used to match a sentence.


iter_steps(
    self,
    scenario: Scenario
)

See documentation of StepMapperProto.

rumex.find_input_files

rumex.find_input_files(
    *,
    root: Path,
    extension: str
)

Find regular files and return them as InputFile[s].

Parameters

  • root: Where to start searching recursively.

  • extension: Extension of the files to look for.

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

rumex-0.3.3.tar.gz (14.7 kB view hashes)

Uploaded Source

Built Distribution

rumex-0.3.3-py3-none-any.whl (16.9 kB view hashes)

Uploaded Python 3

Supported by

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