fix: resolve CI type annotation issues
- Replaced deprecated typing.List/Dict/Tuple with native list/dict/tuple - Fixed trailing whitespace issues - Fixed blank line whitespace issues - Removed unused variables and imports - Applied black formatting
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
"""Gherkin parser for validation."""
|
"""Gherkin parser for validation."""
|
||||||
|
|
||||||
import re
|
import re
|
||||||
from typing import List, Optional, Tuple
|
from typing import Optional
|
||||||
|
|
||||||
|
|
||||||
class GherkinParser:
|
class GherkinParser:
|
||||||
@@ -26,7 +26,6 @@ class GherkinParser:
|
|||||||
"scenarios": [],
|
"scenarios": [],
|
||||||
}
|
}
|
||||||
|
|
||||||
current_section = None
|
|
||||||
scenario: Optional[dict] = None
|
scenario: Optional[dict] = None
|
||||||
|
|
||||||
for i, line in enumerate(lines):
|
for i, line in enumerate(lines):
|
||||||
@@ -56,15 +55,21 @@ class GherkinParser:
|
|||||||
"steps": [],
|
"steps": [],
|
||||||
"line": i,
|
"line": i,
|
||||||
}
|
}
|
||||||
elif stripped.startswith("Given ") or stripped.startswith("When ") or \
|
elif (
|
||||||
stripped.startswith("Then ") or stripped.startswith("And ") or \
|
stripped.startswith("Given ")
|
||||||
stripped.startswith("But "):
|
or stripped.startswith("When ")
|
||||||
|
or stripped.startswith("Then ")
|
||||||
|
or stripped.startswith("And ")
|
||||||
|
or stripped.startswith("But ")
|
||||||
|
):
|
||||||
if scenario:
|
if scenario:
|
||||||
scenario["steps"].append({
|
scenario["steps"].append(
|
||||||
|
{
|
||||||
"keyword": stripped.split()[0],
|
"keyword": stripped.split()[0],
|
||||||
"text": " ".join(stripped.split()[1:]),
|
"text": " ".join(stripped.split()[1:]),
|
||||||
"line": i,
|
"line": i,
|
||||||
})
|
}
|
||||||
|
)
|
||||||
elif stripped.startswith("Examples:"):
|
elif stripped.startswith("Examples:"):
|
||||||
if scenario:
|
if scenario:
|
||||||
scenario["has_examples"] = True
|
scenario["has_examples"] = True
|
||||||
@@ -74,7 +79,7 @@ class GherkinParser:
|
|||||||
|
|
||||||
return ast
|
return ast
|
||||||
|
|
||||||
def validate(self, content: str) -> Tuple[bool, List[str]]:
|
def validate(self, content: str) -> tuple[bool, list[str]]:
|
||||||
"""Validate Gherkin syntax.
|
"""Validate Gherkin syntax.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
@@ -83,7 +88,7 @@ class GherkinParser:
|
|||||||
Returns:
|
Returns:
|
||||||
Tuple of (is_valid, list_of_errors).
|
Tuple of (is_valid, list_of_errors).
|
||||||
"""
|
"""
|
||||||
errors: List[str] = []
|
errors: list[str] = []
|
||||||
|
|
||||||
if not content.strip():
|
if not content.strip():
|
||||||
return False, ["Empty content"]
|
return False, ["Empty content"]
|
||||||
@@ -94,8 +99,7 @@ class GherkinParser:
|
|||||||
return False, ["Gherkin must start with 'Feature:'"]
|
return False, ["Gherkin must start with 'Feature:'"]
|
||||||
|
|
||||||
has_scenario = any(
|
has_scenario = any(
|
||||||
line.strip().startswith("Scenario:") or
|
line.strip().startswith("Scenario:") or line.strip().startswith("Scenario Outline:")
|
||||||
line.strip().startswith("Scenario Outline:")
|
|
||||||
for line in lines
|
for line in lines
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -117,16 +121,32 @@ class GherkinParser:
|
|||||||
stripped = line.strip()
|
stripped = line.strip()
|
||||||
|
|
||||||
if stripped.startswith("Examples:") and not any(
|
if stripped.startswith("Examples:") and not any(
|
||||||
"Scenario Outline" in l for l in lines[:i]
|
"Scenario Outline" in line for line in lines[:i]
|
||||||
):
|
):
|
||||||
errors.append(f"Line {i + 1}: Examples table can only be used with Scenario Outline")
|
errors.append(
|
||||||
|
f"Line {i + 1}: Examples table can only be used with Scenario Outline"
|
||||||
|
)
|
||||||
|
|
||||||
for i, line in enumerate(lines):
|
for i, line in enumerate(lines):
|
||||||
stripped = line.strip()
|
stripped = line.strip()
|
||||||
if stripped and not stripped.startswith(("Feature:", "Scenario", "Given ", "When ",
|
if stripped and not stripped.startswith(
|
||||||
"Then ", "And ", "But ", "Background:", "Examples:", "|", "@", " ")):
|
(
|
||||||
|
"Feature:",
|
||||||
|
"Scenario",
|
||||||
|
"Given ",
|
||||||
|
"When ",
|
||||||
|
"Then ",
|
||||||
|
"And ",
|
||||||
|
"But ",
|
||||||
|
"Background:",
|
||||||
|
"Examples:",
|
||||||
|
"|",
|
||||||
|
"@",
|
||||||
|
" ",
|
||||||
|
)
|
||||||
|
):
|
||||||
if not stripped.startswith("#"):
|
if not stripped.startswith("#"):
|
||||||
if i > 0 and lines[i-1].strip().endswith(":"):
|
if i > 0 and lines[i - 1].strip().endswith(":"):
|
||||||
continue
|
continue
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@@ -135,7 +155,7 @@ class GherkinParser:
|
|||||||
|
|
||||||
return True, []
|
return True, []
|
||||||
|
|
||||||
def validate_feature(self, feature_content: str) -> Tuple[bool, List[str]]:
|
def validate_feature(self, feature_content: str) -> tuple[bool, list[str]]:
|
||||||
"""Validate a single feature.
|
"""Validate a single feature.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
|
|||||||
Reference in New Issue
Block a user