Files
cleveragents-core/tests/features/steps/common_steps.py
T

28 lines
1002 B
Python

from pathlib import Path
from behave import given
@given('a configuration file named "{filename}" with content')
def step_impl(context, filename):
"""
Creates a temporary configuration file with the given content.
This step handles both regular docstrings and scenario outlines.
"""
filepath = Path(context.temp_dir) / filename
content = context.text
# For scenario outlines, manually substitute placeholders from the docstring
# because behave doesn't do it for docstrings.
if hasattr(context.scenario, "table") and hasattr(context.scenario, "row"):
row = context.scenario.row
for header in row.headings:
placeholder = f"<{header}>"
if placeholder in content:
# The value from the table is a string with literal '\n'
value = row[header].replace("\\n", "\n")
content = content.replace(placeholder, value)
filepath.write_text(content)
context.config_file = filepath