forked from cleveragents/cleveragents-core
80 lines
3.4 KiB
Python
80 lines
3.4 KiB
Python
"""Step definitions for test_utils coverage tests."""
|
|
|
|
from behave import given, when, then
|
|
from textwrap import dedent
|
|
from cleveragents.test_utils import fix_python_indentation
|
|
|
|
|
|
@given("I import the fix_python_indentation function")
|
|
def step_import_fix_python_indentation(context):
|
|
"""Import the fix_python_indentation function."""
|
|
context.fix_python_indentation = fix_python_indentation
|
|
assert context.fix_python_indentation is not None
|
|
|
|
|
|
@when("I provide a simple function without indentation:")
|
|
@when("I provide code with empty lines:")
|
|
@when("I provide an if-else block without indentation:")
|
|
@when("I provide an if-elif-else block without indentation:")
|
|
@when("I provide a try-except block without indentation:")
|
|
@when("I provide a try-except-finally block without indentation:")
|
|
@when("I provide nested blocks without indentation:")
|
|
@when("I provide code with only empty lines:")
|
|
@when("I provide a while loop without indentation:")
|
|
@when("I provide a for loop without indentation:")
|
|
@when("I provide complex nested code without indentation:")
|
|
@when("I provide a single line without colon:")
|
|
@when("I provide a with statement without indentation:")
|
|
@when("I provide code with mixed empty and non-empty lines:")
|
|
def step_provide_code_without_indentation(context):
|
|
"""Provide code without indentation."""
|
|
# The text is provided in the step itself
|
|
raw_text = context.text
|
|
# Remove leading/trailing quotes and dedent
|
|
if raw_text.startswith('"""') and raw_text.endswith('"""'):
|
|
raw_text = raw_text[3:-3]
|
|
# Remove the first newline if present
|
|
if raw_text.startswith("\n"):
|
|
raw_text = raw_text[1:]
|
|
# Remove the last newline if present
|
|
if raw_text.endswith("\n"):
|
|
raw_text = raw_text[:-1]
|
|
|
|
# Store the unindented code
|
|
context.input_code = raw_text
|
|
# Apply the fix_python_indentation function
|
|
context.output_code = context.fix_python_indentation(context.input_code)
|
|
|
|
|
|
@then("the output should have proper indentation:")
|
|
@then("the output should preserve empty lines:")
|
|
@then("the output should have proper if-else indentation:")
|
|
@then("the output should have proper if-elif-else indentation:")
|
|
@then("the output should have proper try-except indentation:")
|
|
@then("the output should have proper try-except-finally indentation:")
|
|
@then("the output should have proper nested indentation:")
|
|
@then("the output should have proper while loop indentation:")
|
|
@then("the output should have proper for loop indentation:")
|
|
@then("the output should have proper complex nested indentation:")
|
|
@then("the output should have no indentation:")
|
|
@then("the output should have proper with statement indentation:")
|
|
@then("the output should handle mixed lines correctly:")
|
|
def step_check_proper_indentation(context):
|
|
"""Check that the output has proper indentation."""
|
|
expected_text = context.text
|
|
# Remove leading/trailing quotes and dedent
|
|
if expected_text.startswith('"""') and expected_text.endswith('"""'):
|
|
expected_text = expected_text[3:-3]
|
|
# Remove the first newline if present
|
|
if expected_text.startswith("\n"):
|
|
expected_text = expected_text[1:]
|
|
# Remove the last newline if present
|
|
if expected_text.endswith("\n"):
|
|
expected_text = expected_text[:-1]
|
|
|
|
assert context.output_code == expected_text, (
|
|
f"Output does not match expected.\n"
|
|
f"Expected:\n{repr(expected_text)}\n"
|
|
f"Got:\n{repr(context.output_code)}"
|
|
)
|