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
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 ParsedFile.
executor: A callable that takes ParsedFile 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.runner.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.
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.