-
Notifications
You must be signed in to change notification settings - Fork 58
LCORE-740: type hints for test_configuration.py #608
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
LCORE-740: type hints for test_configuration.py #608
Conversation
WalkthroughType annotations were added and function signatures in tests/unit/test_configuration.py were refined (return types and parameter types like Path and Generator). No logic or control-flow changes were introduced; updates are confined to tests. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
🧹 Nitpick comments (1)
tests/unit/test_configuration.py (1)
232-233: Consider documenting the fixture parameter in docstrings.Per the coding guidelines for Google Python docstring style, functions with parameters should include an Args section. While
tmpdir/tmp_pathis a standard pytest fixture, documenting it would improve consistency.Example:
def test_load_proper_configuration(tmp_path: Path) -> None: """Test loading proper configuration from YAML file. Args: tmp_path: Temporary directory fixture provided by pytest. """Also applies to: 264-265, 424-425, 468-469, 511-512, 550-551
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
tests/unit/test_configuration.py(9 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
**/*.py
📄 CodeRabbit inference engine (CLAUDE.md)
**/*.py: All modules start with descriptive module-level docstrings explaining purpose
Use logger = logging.getLogger(name) for module logging after import logging
Define type aliases at module level for clarity
All functions require docstrings with brief descriptions
Provide complete type annotations for all function parameters and return types
Use typing_extensions.Self in model validators where appropriate
Use modern union syntax (str | int) and Optional[T] or T | None consistently
Function names use snake_case with descriptive, action-oriented prefixes (get_, validate_, check_)
Avoid in-place parameter modification; return new data structures instead of mutating arguments
Use appropriate logging levels: debug, info, warning, error with clear messages
All classes require descriptive docstrings explaining purpose
Class names use PascalCase with conventional suffixes (Configuration, Error/Exception, Resolver, Interface)
Abstract base classes should use abc.ABC and @AbstractMethod for interfaces
Provide complete type annotations for all class attributes
Follow Google Python docstring style for modules, classes, and functions, including Args, Returns, Raises, Attributes sections as needed
Files:
tests/unit/test_configuration.py
tests/{unit,integration}/**/*.py
📄 CodeRabbit inference engine (CLAUDE.md)
tests/{unit,integration}/**/*.py: Use pytest for all unit and integration tests
Do not use unittest in tests; pytest is the standard
Files:
tests/unit/test_configuration.py
tests/**/*.py
📄 CodeRabbit inference engine (CLAUDE.md)
tests/**/*.py: Use pytest-mock to create AsyncMock objects for async interactions in tests
Use the shared auth mock constant: MOCK_AUTH = ("mock_user_id", "mock_username", False, "mock_token") in tests
Files:
tests/unit/test_configuration.py
🧬 Code graph analysis (1)
tests/unit/test_configuration.py (2)
src/configuration.py (9)
configuration(65-69)AppConfig(36-153)LogicError(32-33)service_configuration(72-76)llama_stack_configuration(79-83)user_data_collection_configuration(86-90)mcp_servers(93-97)authentication_configuration(100-105)customization(119-123)src/models/config.py (3)
config(138-144)CustomProfile(441-460)ModelContextProtocolServer(167-172)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: e2e_tests
🔇 Additional comments (3)
tests/unit/test_configuration.py (3)
89-89: LGTM!The type annotation uses modern dict syntax and is appropriately typed.
307-307: LGTM!The type annotation is consistent with modern Python typing standards.
375-375: LGTM!The
-> Nonereturn type annotations correctly complete the function signatures.Also applies to: 382-382, 389-389, 396-396, 403-403, 410-410, 417-417
| # pylint: disable=broad-exception-caught,protected-access | ||
| @pytest.fixture(autouse=True) | ||
| def _reset_app_config_between_tests(): | ||
| def _reset_app_config_between_tests() -> Generator: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion | 🟠 Major
Complete the Generator type annotation.
The fixture return type should fully specify the Generator type parameters. For a fixture that yields without a value, use Generator[None, None, None] from collections.abc or typing.
Apply this diff:
-def _reset_app_config_between_tests() -> Generator:
+def _reset_app_config_between_tests() -> Generator[None, None, None]:📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| def _reset_app_config_between_tests() -> Generator: | |
| def _reset_app_config_between_tests() -> Generator[None, None, None]: | |
| # (fixture body unchanged) |
🤖 Prompt for AI Agents
In tests/unit/test_configuration.py around line 13, the return type for the
fixture is too generic; change the annotation to a fully specified Generator
type for a yield-only fixture by using Generator[None, None, None] and ensure
you import Generator from typing or collections.abc at the top of the file;
update the function signature to use Generator[None, None, None] and add or
adjust the import accordingly.
|
|
||
|
|
||
| def test_load_proper_configuration(tmpdir) -> None: | ||
| def test_load_proper_configuration(tmpdir: Path) -> None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Incorrect type annotation for pytest fixture.
The tmpdir fixture provides py.path.local objects, not pathlib.Path. The type annotation creates a mismatch that will cause type checker failures.
Recommended solution: Use pytest's tmp_path fixture instead, which provides pathlib.Path objects:
-def test_load_proper_configuration(tmpdir: Path) -> None:
+def test_load_proper_configuration(tmp_path: Path) -> None:
"""Test loading proper configuration from YAML file."""
- cfg_filename = tmpdir / "config.yaml"
+ cfg_filename = tmp_path / "config.yaml"Apply the same change to all test functions using tmpdir: Path (lines 264, 424, 468, 511, 550).
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| def test_load_proper_configuration(tmpdir: Path) -> None: | |
| def test_load_proper_configuration(tmp_path: Path) -> None: | |
| """Test loading proper configuration from YAML file.""" | |
| cfg_filename = tmp_path / "config.yaml" | |
| # ...rest of the test... |
🤖 Prompt for AI Agents
In tests/unit/test_configuration.py around line 232, the test function is
annotated with tmpdir: Path but pytest's tmpdir fixture yields py.path.local,
causing a type mismatch; change the parameter to use pytest's tmp_path fixture
(tmp_path: Path) instead and update the function signature accordingly; apply
the same replacement for all other test functions that currently declare tmpdir:
Path at lines 264, 424, 468, 511, and 550 so each uses tmp_path: Path to match
pathlib.Path objects.
Description
LCORE-740: type hints for
test_configuration.pyType of change
Related Tickets & Documents
Summary by CodeRabbit