Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Generate formatted Python step definitions #161

Merged

Conversation

kieran-ryan
Copy link
Member

@kieran-ryan kieran-ryan commented Nov 12, 2023

🤔 What's changed?

The Python step definition snippet has been modified as follows:

  • Outdented the snippet by 2 spaces - so is valid Python
  • Removed the space between the function parentheses and colon - removing redundant whitespace that would fail formatters such as black
  • Removed the comma and white space after the context argument when the step has no parameters - removing redundant characters that would fail formatters such as black

Examples

When generating a Python step definition from a gherkin step...

When I eat "<eat>" cucumbers

...the step definition is indented by 2 spaces - which is invalid Python; and a space is present between the parentheses (()) and the colon (:) of the function declaration.

  @when('I eat {string} cucumbers')
  def step_when(context, string) :
      # This was autogenerated using cucumber syntax.
      # Please convert to use regular expressions, as Behave does not currently support Cucumber Expressions

Additionally, when generating a Python step definition from a gherkin step containing no parameters...

Then I should have many cucumber

...a trailing comma and space appear after context.

  @then('I should have many cucumber')
  def step_then(context, ) :
      # This was autogenerated using cucumber syntax.
      # Please convert to use regular expressions, as Behave does not currently support Cucumber Expressions

⚡️ What's your motivation?

Fixes #160, rendering formatted Python step definitions as follows:

@then('I should have many cucumber')
def step_then(context):
    # This was autogenerated using cucumber syntax.
    # Please convert to use regular expressions, as Behave does not currently support Cucumber Expressions

And with multiple parameters as follows:

Given there is a "string" and an integer of 5
@given('there is a {string} and an integer of {int}')
def step_given(context, string, int):
    # This was autogenerated using cucumber syntax.
    # Please convert to use regular expressions, as Behave does not currently support Cucumber Expressions.

🏷️ What kind of change is this?

  • 🐛 Bug fix (non-breaking change which fixes a defect)

♻️ Anything particular you want feedback on?

NA

📋 Checklist:

  • I agree to respect and uphold the Cucumber Community Code of Conduct
  • I've changed the behaviour of the code
  • Users should know about my change
    • I have added an entry to the "Unreleased" section of the CHANGELOG, linking to this pull request.

Copy link
Contributor

@mpkorstanje mpkorstanje left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. CI failure seems to be unrelated. But I you have any idea why please do feel free to fix that too.

@kieran-ryan kieran-ryan added the 🐛 bug Defect / Bug label Jan 7, 2024
@kieran-ryan kieran-ryan merged commit 99cff62 into cucumber:main Jan 7, 2024
4 of 6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 bug Defect / Bug python
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Step definitions generated in Python require refactoring
2 participants