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,5 @@
|
|||||||
"""pytest-bdd exporter for pytest projects."""
|
"""pytest-bdd exporter for pytest projects."""
|
||||||
|
|
||||||
from typing import Dict, List
|
|
||||||
|
|
||||||
from nl2gherkin.exporters.base import BaseExporter
|
from nl2gherkin.exporters.base import BaseExporter
|
||||||
|
|
||||||
|
|
||||||
@@ -12,12 +10,12 @@ class PytestBDDExporter(BaseExporter):
|
|||||||
"""Initialize the pytest-bdd exporter."""
|
"""Initialize the pytest-bdd exporter."""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def export(self, features: List[str]) -> str:
|
def export(self, features: list[str]) -> str:
|
||||||
"""Export features to pytest-bdd format.
|
"""Export features to pytest-bdd format.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
features: List of Gherkin feature strings.
|
features: List of Gherkin feature strings.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
pytest-bdd-compatible feature file content.
|
pytest-bdd-compatible feature file content.
|
||||||
"""
|
"""
|
||||||
@@ -26,7 +24,7 @@ class PytestBDDExporter(BaseExporter):
|
|||||||
|
|
||||||
def get_step_definitions_template(self) -> str:
|
def get_step_definitions_template(self) -> str:
|
||||||
"""Get pytest-bdd step definitions template.
|
"""Get pytest-bdd step definitions template.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
Step definitions template string.
|
Step definitions template string.
|
||||||
"""
|
"""
|
||||||
@@ -57,9 +55,9 @@ def expected_result():
|
|||||||
pass
|
pass
|
||||||
'''
|
'''
|
||||||
|
|
||||||
def get_configuration_template(self) -> Dict[str, str]:
|
def get_configuration_template(self) -> dict[str, str]:
|
||||||
"""Get pytest-bdd configuration files.
|
"""Get pytest-bdd configuration files.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
Dictionary mapping filenames to content.
|
Dictionary mapping filenames to content.
|
||||||
"""
|
"""
|
||||||
@@ -83,18 +81,20 @@ def pytest_configure(config):
|
|||||||
"""Configure pytest."""
|
"""Configure pytest."""
|
||||||
pass
|
pass
|
||||||
''',
|
''',
|
||||||
"pytest.ini": '''[pytest]
|
"pytest.ini": """[pytest]
|
||||||
bdd_features_base_dir = features/
|
bdd_features_base_dir = features/
|
||||||
''',
|
""",
|
||||||
}
|
}
|
||||||
|
|
||||||
def generate_step_definitions(self, scenarios: List[str], feature_name: str = "features") -> str:
|
def generate_step_definitions(
|
||||||
|
self, scenarios: list[str], feature_name: str = "features"
|
||||||
|
) -> str:
|
||||||
"""Generate step definitions for given scenarios.
|
"""Generate step definitions for given scenarios.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
scenarios: List of scenario texts.
|
scenarios: List of scenario texts.
|
||||||
feature_name: Name of the feature file.
|
feature_name: Name of the feature file.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
Step definitions Python code.
|
Step definitions Python code.
|
||||||
"""
|
"""
|
||||||
@@ -116,10 +116,10 @@ bdd_features_base_dir = features/
|
|||||||
step_def = stripped.split()[0].lower()
|
step_def = stripped.split()[0].lower()
|
||||||
|
|
||||||
params = self._extract_parameters(step_text)
|
params = self._extract_parameters(step_text)
|
||||||
param_str = ", ".join(f'"{p}"' for p in params) if params else ""
|
", ".join(f'"{p}"' for p in params) if params else ""
|
||||||
|
|
||||||
if params:
|
if params:
|
||||||
step_impl = f'''@pytest.{step_def}("{step_text}")
|
step_impl = f'''@{step_def}("{step_text}")
|
||||||
def {step_def}_{scenario_name}({", ".join(params)}):
|
def {step_def}_{scenario_name}({", ".join(params)}):
|
||||||
"""{stripped.split()[0]} step implementation."""
|
"""{stripped.split()[0]} step implementation."""
|
||||||
pass
|
pass
|
||||||
@@ -135,7 +135,8 @@ def {step_def}_{scenario_name}():
|
|||||||
|
|
||||||
return "\n".join(step_defs)
|
return "\n".join(step_defs)
|
||||||
|
|
||||||
def _extract_parameters(self, step_text: str) -> List[str]:
|
def _extract_parameters(self, step_text: str) -> list[str]:
|
||||||
"""Extract parameters from a step text."""
|
"""Extract parameters from a step text."""
|
||||||
import re
|
import re
|
||||||
|
|
||||||
return re.findall(r"<([^>]+)>", step_text)
|
return re.findall(r"<([^>]+)>", step_text)
|
||||||
|
|||||||
Reference in New Issue
Block a user