fix(tests): correct PyYAML BDD test assertions and remove prohibited type: ignore comments
CI / benchmark-publish (pull_request) Has been skipped
CI / lint (pull_request) Failing after 1m51s
CI / helm (pull_request) Successful in 39s
CI / quality (pull_request) Successful in 2m9s
CI / push-validation (pull_request) Successful in 38s
CI / build (pull_request) Successful in 1m10s
CI / security (pull_request) Successful in 2m23s
CI / benchmark-regression (pull_request) Failing after 1m6s
CI / typecheck (pull_request) Successful in 2m34s
CI / unit_tests (pull_request) Failing after 4m16s
CI / coverage (pull_request) Has been skipped
CI / docker (pull_request) Has been skipped
CI / e2e_tests (pull_request) Successful in 4m11s
CI / integration_tests (pull_request) Successful in 5m26s
CI / status-check (pull_request) Failing after 8s
CI / benchmark-publish (pull_request) Has been skipped
CI / lint (pull_request) Failing after 1m51s
CI / helm (pull_request) Successful in 39s
CI / quality (pull_request) Successful in 2m9s
CI / push-validation (pull_request) Successful in 38s
CI / build (pull_request) Successful in 1m10s
CI / security (pull_request) Successful in 2m23s
CI / benchmark-regression (pull_request) Failing after 1m6s
CI / typecheck (pull_request) Successful in 2m34s
CI / unit_tests (pull_request) Failing after 4m16s
CI / coverage (pull_request) Has been skipped
CI / docker (pull_request) Has been skipped
CI / e2e_tests (pull_request) Successful in 4m11s
CI / integration_tests (pull_request) Successful in 5m26s
CI / status-check (pull_request) Failing after 8s
- Changed version comparison from exact equality (==) to >= using packaging.version for proper semantic version checking. - Removed all # type: ignore[no-any-return] comments which are prohibited per project policy. Replaced with clean _toml_to_python() helper that handles both tomllib and tomlkit parsing without type ignores. - Updated error messages to reflect >= semantics instead of == equality. ISSUES CLOSED: #9055
This commit is contained in:
@@ -8,6 +8,7 @@ from pathlib import Path
|
||||
from typing import Any
|
||||
|
||||
from behave import given, then, when
|
||||
from packaging.version import parse as parse_version
|
||||
from behave.runner import Context
|
||||
|
||||
|
||||
@@ -69,8 +70,8 @@ def step_read_pyyaml_dependency(context: Context) -> None:
|
||||
def step_pyyaml_minimum_version(context: Context, expected: str) -> None:
|
||||
"""Assert that the PyYAML minimum version is >= expected version."""
|
||||
min_version = context.pyyaml_min_version
|
||||
assert min_version == expected, (
|
||||
f"PyYAML minimum version {min_version} does not match expected {expected}. "
|
||||
assert parse_version(min_version) >= parse_version(expected), (
|
||||
f"PyYAML minimum version {min_version} is less than required {expected}. "
|
||||
f"Dependency spec: {context.pyyaml_version_spec}"
|
||||
)
|
||||
|
||||
@@ -125,8 +126,25 @@ def _load_toml(content: bytes) -> dict[str, Any]:
|
||||
import tomllib
|
||||
|
||||
return tomllib.loads(content.decode("utf-8"))
|
||||
except ImportError:
|
||||
except ImportError: # pragma: no cover — Python <3.11
|
||||
# Fallback for older Python versions without tomllib
|
||||
import tomlkit
|
||||
|
||||
return tomlkit.parse(content.decode("utf-8")).unwrap() # type: ignore[no-any-return]
|
||||
parsed_doc = tomlkit.parse(content.decode("utf-8"))
|
||||
return _toml_to_python(parsed_doc)
|
||||
|
||||
|
||||
def _toml_to_python(data: object) -> dict[str, Any]:
|
||||
"""Convert a TOML document from tomlkit (or tomllib) to plain Python dicts."""
|
||||
if isinstance(data, dict):
|
||||
def _flatten(d: dict[Any, Any]) -> dict[str, Any]:
|
||||
result: dict[str, Any] = {}
|
||||
for key, value in d.items():
|
||||
if isinstance(value, dict):
|
||||
result[key] = _flatten(value)
|
||||
else:
|
||||
result[key] = value
|
||||
return result
|
||||
return _flatten(data)
|
||||
raise TypeError(f"Expected dict-like TOML table, got {type(data).__name__}")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user