Skip to content

Commit

Permalink
Reformating to allow better compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
Tiago Miranda authored and Tiago Miranda committed Jan 16, 2020
1 parent 16c031f commit 87accb9
Showing 1 changed file with 9 additions and 21 deletions.
30 changes: 9 additions & 21 deletions pytest_bdd/feature.py
Expand Up @@ -55,7 +55,6 @@

STEP_PARAM_RE = re.compile(r"\<(.+?)\>")
COMMENT_RE = re.compile(r"(^|(?<=\s))#")
SPLIT_LINE_RE = re.compile(r"(?<!\\)\|")


def get_step_type(line):
Expand Down Expand Up @@ -126,14 +125,6 @@ def get_tags(line):
return set((tag.lstrip("@") for tag in line.strip().split(" @") if len(tag) > 1))


def split_line(line):
"""Split the given Examples line.
:param str|unicode line: Feature file Examples line.
:return: List of strings.
"""
return [cell.replace("\\|", "|").strip() for cell in SPLIT_LINE_RE.split(line[1:-1])]


def get_features(paths, **kwargs):
"""Get features for given paths.
:param list paths: `list` of paths (file or dirs)
Expand Down Expand Up @@ -210,10 +201,7 @@ def get_params(self, converters, builtin=False):
raw_value = example[index]
if converters and param in converters:
value = converters[param](raw_value)
if not builtin or value.__class__.__module__ in {
"__builtin__",
"builtins",
}:
if not builtin or value.__class__.__module__ in {"__builtin__", "builtins"}:
example[index] = value
params.append(example)
return [self.example_params, params]
Expand Down Expand Up @@ -281,17 +269,17 @@ def __init__(self, basedir, filename, encoding="utf-8", strict_gherkin=True):

if not scenario and prev_mode not in allowed_prev_mode and mode in types.STEP_TYPES:
raise exceptions.FeatureError(
"Step definition outside of a Scenario or a Background", line_number, clean_line, filename,
"Step definition outside of a Scenario or a Background", line_number, clean_line, filename
)

if strict_gherkin:
if (
self.background
and not scenario
and mode not in (types.SCENARIO, types.SCENARIO_OUTLINE, types.GIVEN, types.TAG,)
and mode not in (types.SCENARIO, types.SCENARIO_OUTLINE, types.GIVEN, types.TAG)
):
raise exceptions.FeatureError(
"Background section can only contain Given steps", line_number, clean_line, filename,
"Background section can only contain Given steps", line_number, clean_line, filename
)

if mode == types.GIVEN and prev_mode not in (
Expand All @@ -301,7 +289,7 @@ def __init__(self, basedir, filename, encoding="utf-8", strict_gherkin=True):
types.BACKGROUND,
):
raise exceptions.FeatureError(
"Given steps must be the first within the Scenario", line_number, clean_line, filename,
"Given steps must be the first within the Scenario", line_number, clean_line, filename
)

if mode == types.WHEN and prev_mode not in (
Expand All @@ -311,12 +299,12 @@ def __init__(self, basedir, filename, encoding="utf-8", strict_gherkin=True):
types.WHEN,
):
raise exceptions.FeatureError(
"When steps must be the first or follow Given steps", line_number, clean_line, filename,
"When steps must be the first or follow Given steps", line_number, clean_line, filename
)

if not self.background and mode == types.THEN and prev_mode not in types.STEP_TYPES:
raise exceptions.FeatureError(
"Then steps must follow Given or When steps", line_number, clean_line, filename,
"Then steps must follow Given or When steps", line_number, clean_line, filename
)

if mode == types.FEATURE:
Expand Down Expand Up @@ -375,7 +363,7 @@ def __init__(self, basedir, filename, encoding="utf-8", strict_gherkin=True):
)
elif mode and mode not in (types.FEATURE, types.TAG):
step = Step(
name=parsed_line, type=mode, indent=line_indent, line_number=line_number, keyword=keyword,
name=parsed_line, type=mode, indent=line_indent, line_number=line_number, keyword=keyword
)
if self.background and (mode == types.GIVEN or not strict_gherkin) and not scenario:
target = self.background
Expand Down Expand Up @@ -474,7 +462,7 @@ def validate(self):
raise exceptions.ScenarioExamplesNotValidError(
"""Scenario "{0}" in the feature "{1}" has not valid examples. """
"""Set of step parameters {2} should match set of example values {3}.""".format(
self.name, self.feature.filename, sorted(params), sorted(example_params),
self.name, self.feature.filename, sorted(params), sorted(example_params)
)
)

Expand Down

0 comments on commit 87accb9

Please sign in to comment.