Skip to content

Commit

Permalink
Switch default parser to cfparse
Browse files Browse the repository at this point in the history
  • Loading branch information
Kostiantyn Goloveshko authored and Kostiantyn Goloveshko committed Jan 3, 2022
1 parent 28bbf66 commit 8ce5dbb
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions pytest_bdd/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,27 @@


import re as base_re
import sys
import typing
from functools import partial
from typing import Union

import parse as base_parse
from parse_type import cfparse as base_cfparse


class StepParserProtocol(typing.Protocol if sys.version_info >= (3, 8) else object):
def parse_arguments(self, name):
...

def is_matching(self, name):
...

@property
def name(self):
...


class StepParser:
"""Parser of the individual step."""

Expand Down Expand Up @@ -98,7 +113,7 @@ def is_matching(self, name):
return self.name == name


def get_parser(step_name):
def get_parser(step_name: Union[str, StepParser, StepParserProtocol]) -> Union[StepParser, StepParserProtocol]:
"""Get parser by given name.
:param step_name: name of the step to parse
Expand All @@ -108,9 +123,9 @@ def get_parser(step_name):
"""

def does_support_parser_interface(obj):
return all(map(partial(hasattr, obj), ["is_matching", "parse_arguments"]))
return all(map(partial(hasattr, obj), ["name", "is_matching", "parse_arguments"]))

if does_support_parser_interface(step_name):
return step_name
else:
return string(step_name)
return cfparse(step_name)

0 comments on commit 8ce5dbb

Please sign in to comment.