Skip to content

Commit

Permalink
Make transformer an optional argument
Browse files Browse the repository at this point in the history
  • Loading branch information
kieran-ryan committed Mar 18, 2024
1 parent 7454a42 commit fe0d7b7
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 6 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ color = ParameterType(
name="color",
regexp="red|blue|yellow",
type=str,
transformer=lambda s: s,
)

# Pass the parameter type to the registry instance
Expand Down
6 changes: 6 additions & 0 deletions behave_cucumber_matcher/matcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,20 @@ class ParameterTypeOverrides(cucumber_expressions.parameter_type.ParameterType):
def __init__( # noqa: D107
self,
*args,
type: Callable, # noqa: A002
# Fixes missing defaults in Cucumber Expressions below or equal to 17.0.2
transformer: Optional[Callable] = None,
# Fixes missing defaults in Cucumber Expressions below 17.0.2
# See https://github.com/cucumber/cucumber-expressions/pull/259
use_for_snippets: bool = True,
prefer_for_regexp_match: bool = False,
**kwargs,
):
transformer = transformer or (lambda value: type(value))
super().__init__(
*args,
type=type,
transformer=transformer,
use_for_snippets=use_for_snippets,
prefer_for_regexp_match=prefer_for_regexp_match,
**kwargs,
Expand Down
1 change: 0 additions & 1 deletion features/steps/color.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
name="color",
regexp="red|blue|yellow",
type=str,
transformer=lambda s: s,
)

# Pass the parameter type to the registry instance
Expand Down
7 changes: 3 additions & 4 deletions tests/unit/test_matcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,12 @@ def test_matcher_patched_into_behave():
def test_no_exception_without_parameter_type_defaults():
"""Compatible with earlier Cucumber Expressions versions.
Cucumber Expressions below 17.0.2 do not set expected defaults
for `use_for_snippets` and `prefer_for_regexp_match` in the
parameter type.
Cucumber Expressions below or equal to 17.0.2 do not set
expected defaults for `transformer`, `use_for_snippets`
and `prefer_for_regexp_match` in the parameter type.
"""
ParameterType(
name="color",
regexp="red|blue|yellow",
type=str,
transformer=lambda s: s,
)

0 comments on commit fe0d7b7

Please sign in to comment.