chore: resolve linting errors in test modules

This commit is contained in:
Ahmed Allam
2025-12-03 23:33:38 +04:00
committed by Ahmed Allam
parent 65c3383ecc
commit 6c5c0b0d1c
3 changed files with 36 additions and 16 deletions

View File

@@ -129,9 +129,15 @@ module = [
"textual.*", "textual.*",
"pyte.*", "pyte.*",
"libtmux.*", "libtmux.*",
"pytest.*",
] ]
ignore_missing_imports = true ignore_missing_imports = true
# Relax strict rules for test files (pytest decorators are not fully typed)
[[tool.mypy.overrides]]
module = ["tests.*"]
disallow_untyped_decorators = false
# ============================================================================ # ============================================================================
# Ruff Configuration (Fast Python Linter & Formatter) # Ruff Configuration (Fast Python Linter & Formatter)
# ============================================================================ # ============================================================================

View File

@@ -1,10 +1,13 @@
"""Pytest configuration and shared fixtures for Strix tests.""" """Pytest configuration and shared fixtures for Strix tests."""
from collections.abc import Callable
from typing import Any
import pytest import pytest
@pytest.fixture @pytest.fixture
def sample_function_with_types(): def sample_function_with_types() -> Callable[..., None]:
"""Create a sample function with type annotations for testing argument conversion.""" """Create a sample function with type annotations for testing argument conversion."""
def func( def func(
@@ -12,8 +15,8 @@ def sample_function_with_types():
count: int, count: int,
enabled: bool, enabled: bool,
ratio: float, ratio: float,
items: list, items: list[Any],
config: dict, config: dict[str, Any],
optional: str | None = None, optional: str | None = None,
) -> None: ) -> None:
pass pass
@@ -22,10 +25,10 @@ def sample_function_with_types():
@pytest.fixture @pytest.fixture
def sample_function_no_annotations(): def sample_function_no_annotations() -> Callable[..., None]:
"""Create a sample function without type annotations.""" """Create a sample function without type annotations."""
def func(arg1, arg2, arg3): def func(arg1: Any, arg2: Any, arg3: Any) -> None:
pass pass
return func return func

View File

@@ -5,8 +5,7 @@ string arguments to their appropriate Python types based on function
type annotations. type annotations.
""" """
import json from collections.abc import Callable
from typing import Optional, Union
import pytest import pytest
@@ -177,17 +176,17 @@ class TestConvertStringToType:
def test_optional_type(self) -> None: def test_optional_type(self) -> None:
"""Test conversion with Optional type.""" """Test conversion with Optional type."""
result = convert_string_to_type("42", Optional[int]) result = convert_string_to_type("42", int | None)
assert result == 42 assert result == 42
def test_union_type(self) -> None: def test_union_type(self) -> None:
"""Test conversion with Union type.""" """Test conversion with Union type."""
result = convert_string_to_type("42", Union[int, str]) result = convert_string_to_type("42", int | str)
assert result == 42 assert result == 42
def test_union_type_with_none(self) -> None: def test_union_type_with_none(self) -> None:
"""Test conversion with Union including None.""" """Test conversion with Union including None."""
result = convert_string_to_type("hello", Union[str, None]) result = convert_string_to_type("hello", str | None)
assert result == "hello" assert result == "hello"
def test_modern_union_syntax(self) -> None: def test_modern_union_syntax(self) -> None:
@@ -199,7 +198,9 @@ class TestConvertStringToType:
class TestConvertArguments: class TestConvertArguments:
"""Tests for the convert_arguments function.""" """Tests for the convert_arguments function."""
def test_converts_typed_arguments(self, sample_function_with_types) -> None: def test_converts_typed_arguments(
self, sample_function_with_types: Callable[..., None]
) -> None:
"""Test that arguments are converted based on type annotations.""" """Test that arguments are converted based on type annotations."""
kwargs = { kwargs = {
"name": "test", "name": "test",
@@ -218,32 +219,42 @@ class TestConvertArguments:
assert result["items"] == [1, 2, 3] assert result["items"] == [1, 2, 3]
assert result["config"] == {"key": "value"} assert result["config"] == {"key": "value"}
def test_passes_through_none_values(self, sample_function_with_types) -> None: def test_passes_through_none_values(
self, sample_function_with_types: Callable[..., None]
) -> None:
"""Test that None values are passed through unchanged.""" """Test that None values are passed through unchanged."""
kwargs = {"name": "test", "count": None} kwargs = {"name": "test", "count": None}
result = convert_arguments(sample_function_with_types, kwargs) result = convert_arguments(sample_function_with_types, kwargs)
assert result["count"] is None assert result["count"] is None
def test_passes_through_non_string_values(self, sample_function_with_types) -> None: def test_passes_through_non_string_values(
self, sample_function_with_types: Callable[..., None]
) -> None:
"""Test that non-string values are passed through unchanged.""" """Test that non-string values are passed through unchanged."""
kwargs = {"name": "test", "count": 42} kwargs = {"name": "test", "count": 42}
result = convert_arguments(sample_function_with_types, kwargs) result = convert_arguments(sample_function_with_types, kwargs)
assert result["count"] == 42 assert result["count"] == 42
def test_unknown_parameter_passed_through(self, sample_function_with_types) -> None: def test_unknown_parameter_passed_through(
self, sample_function_with_types: Callable[..., None]
) -> None:
"""Test that parameters not in signature are passed through.""" """Test that parameters not in signature are passed through."""
kwargs = {"name": "test", "unknown_param": "value"} kwargs = {"name": "test", "unknown_param": "value"}
result = convert_arguments(sample_function_with_types, kwargs) result = convert_arguments(sample_function_with_types, kwargs)
assert result["unknown_param"] == "value" assert result["unknown_param"] == "value"
def test_function_without_annotations(self, sample_function_no_annotations) -> None: def test_function_without_annotations(
self, sample_function_no_annotations: Callable[..., None]
) -> None:
"""Test handling of functions without type annotations.""" """Test handling of functions without type annotations."""
kwargs = {"arg1": "value1", "arg2": "42"} kwargs = {"arg1": "value1", "arg2": "42"}
result = convert_arguments(sample_function_no_annotations, kwargs) result = convert_arguments(sample_function_no_annotations, kwargs)
assert result["arg1"] == "value1" assert result["arg1"] == "value1"
assert result["arg2"] == "42" assert result["arg2"] == "42"
def test_raises_error_on_conversion_failure(self, sample_function_with_types) -> None: def test_raises_error_on_conversion_failure(
self, sample_function_with_types: Callable[..., None]
) -> None:
"""Test that ArgumentConversionError is raised on conversion failure.""" """Test that ArgumentConversionError is raised on conversion failure."""
kwargs = {"count": "not_a_number"} kwargs = {"count": "not_a_number"}
with pytest.raises(ArgumentConversionError) as exc_info: with pytest.raises(ArgumentConversionError) as exc_info: