Skip to content

Commit

Permalink
Optional transformer argument for parameter types (#16)
Browse files Browse the repository at this point in the history
* Make transformer an optional argument
* Comment Expressions PR introducing optional transformer
  • Loading branch information
kieran-ryan authored Mar 18, 2024
1 parent 954df44 commit a6e8c2e
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

## Unreleased

### Added

- Compatibility with parameter types missing transformer default ([#16](https://github.com/kieran-ryan/behave-cucumber-matcher/pull/16))

## 0.3.0 - 2024-03-17

### Added
Expand Down
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
7 changes: 7 additions & 0 deletions behave_cucumber_matcher/matcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,21 @@ class ParameterTypeOverrides(cucumber_expressions.parameter_type.ParameterType):
def __init__( # noqa: D107
self,
*args,
type: Any, # noqa: A002
# Fixes missing defaults in Cucumber Expressions below or equal to 17.0.2
# See https://github.com/cucumber/cucumber-expressions/pull/288
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 a6e8c2e

Please sign in to comment.