-
Notifications
You must be signed in to change notification settings - Fork 55
LCORE-740: Type hints in conversation cache unit tests #734
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 in conversation cache unit tests #734
Conversation
WalkthroughAdded explicit type annotations and return types to cache-related unit tests and fixtures across multiple test modules; sqlite fixture now accepts a Changes
Sequence Diagram(s)(Skipped — changes are typing and signature-only; no control-flow modifications to visualize.) Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes
Possibly related PRs
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
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: 0
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (2)
tests/unit/cache/test_cache_factory.py (2)
54-60: Incorrect type annotation for tmpdir fixture.The
tmpdirfixture returnspy.path.local, notpathlib.Path. This creates a type mismatch.Apply this diff to use the correct pytest fixture that returns
pathlib.Path:-@pytest.fixture(name="sqlite_cache_config_fixture") -def sqlite_cache_config(tmpdir: Path) -> ConversationCacheConfiguration: +@pytest.fixture(name="sqlite_cache_config_fixture") +def sqlite_cache_config(tmp_path: Path) -> ConversationCacheConfiguration: """Fixture containing initialized instance of SQLite cache.""" - db_path = str(tmpdir / "test.sqlite") + db_path = str(tmp_path / "test.sqlite") return ConversationCacheConfiguration( type=CACHE_TYPE_SQLITE, sqlite=SQLiteDatabaseConfiguration(db_path=db_path) )
112-121: Incorrect type annotation for tmpdir parameter.Same issue as the fixture:
tmpdirreturnspy.path.local, notpathlib.Path.Apply this diff to use the correct pytest fixture:
-def test_conversation_cache_sqlite_improper_config(tmpdir: Path) -> None: +def test_conversation_cache_sqlite_improper_config(tmp_path: Path) -> None: """Check if memory cache configuration is checked in cache factory.""" - db_path = str(tmpdir / "test.sqlite") + db_path = str(tmp_path / "test.sqlite") cc = ConversationCacheConfiguration( type=CACHE_TYPE_SQLITE, sqlite=SQLiteDatabaseConfiguration(db_path=db_path) )
🧹 Nitpick comments (1)
tests/unit/cache/test_cache_factory.py (1)
71-73: Remove trailing comma after single parameter.While not incorrect, the trailing comma after a single parameter is unconventional and inconsistent with Python style conventions.
def test_conversation_cache_noop( - noop_cache_config_fixture: ConversationCacheConfiguration, + noop_cache_config_fixture: ConversationCacheConfiguration ) -> None:
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
tests/unit/cache/test_cache_factory.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/cache/test_cache_factory.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/cache/test_cache_factory.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/cache/test_cache_factory.py
🧠 Learnings (1)
📓 Common learnings
Learnt from: CR
PR: lightspeed-core/lightspeed-stack#0
File: CLAUDE.md:0-0
Timestamp: 2025-09-18T16:46:33.353Z
Learning: Applies to src/{models/**/*.py,configuration.py} : Use precise type hints in configuration (e.g., Optional[FilePath], PositiveInt, SecretStr)
Learnt from: CR
PR: lightspeed-core/lightspeed-stack#0
File: CLAUDE.md:0-0
Timestamp: 2025-09-18T16:46:33.353Z
Learning: Applies to **/*.py : Provide complete type annotations for all function parameters and return types
🧬 Code graph analysis (1)
tests/unit/cache/test_cache_factory.py (2)
src/models/config.py (2)
ConversationCacheConfiguration(514-552)InMemoryCacheConfig(81-84)src/cache/cache_factory.py (2)
CacheFactory(16-49)conversation_cache(20-49)
⏰ 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). (3)
- GitHub Check: build-pr
- GitHub Check: e2e_tests (azure)
- GitHub Check: e2e_tests (ci)
🔇 Additional comments (4)
tests/unit/cache/test_cache_factory.py (4)
3-3: Path import is unused after fixing tmpdir type annotation.The
Pathimport is added to support the type annotations on lines 55 and 112. However, thetmpdirfixture returnspy.path.local, notpathlib.Path. Consider using pytest'stmp_pathfixture instead, which returnspathlib.Pathand would make this import necessary.
124-126: Type annotations look good.The parameter and return type annotations are correctly applied. The
MockerFixturetype is properly used for the mocker parameter.
135-146: Return type annotation correctly applied.
149-155: Return type annotation correctly applied.
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: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
tests/unit/cache/test_noop_cache.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/cache/test_noop_cache.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/cache/test_noop_cache.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/cache/test_noop_cache.py
🧠 Learnings (1)
📓 Common learnings
Learnt from: CR
PR: lightspeed-core/lightspeed-stack#0
File: CLAUDE.md:0-0
Timestamp: 2025-09-18T16:46:33.353Z
Learning: Applies to src/{models/**/*.py,configuration.py} : Use precise type hints in configuration (e.g., Optional[FilePath], PositiveInt, SecretStr)
Learnt from: CR
PR: lightspeed-core/lightspeed-stack#0
File: CLAUDE.md:0-0
Timestamp: 2025-09-18T16:46:33.353Z
Learning: Applies to **/*.py : Provide complete type annotations for all function parameters and return types
🧬 Code graph analysis (1)
tests/unit/cache/test_noop_cache.py (1)
src/cache/noop_cache.py (1)
NoopCache(12-128)
⏰ 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). (3)
- GitHub Check: e2e_tests (ci)
- GitHub Check: e2e_tests (azure)
- GitHub Check: build-pr
🔇 Additional comments (2)
tests/unit/cache/test_noop_cache.py (2)
30-35: LGTM: Fixture type hint correctly added.The return type annotation
-> NoopCacheaccurately reflects the fixture's return value and aligns with the coding guidelines.
38-198: LGTM: Test function type hints correctly added.All test functions now have proper type annotations for parameters and return types, following the coding guidelines. The type hints accurately reflect the function signatures.
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: 0
🧹 Nitpick comments (1)
tests/unit/cache/test_postgres_cache.py (1)
48-48: Type hints correctly added to mock classes.The type annotations for both mock classes are appropriate. The
-> Nonereturn types correctly indicate that these methods either don't return a value or raise exceptions.For added precision, line 63's
cursor()method could use-> NoReturnsince it always raises an exception:+from typing import Any, NoReturn + class ConnectionMock: """Mock class for connection.""" def __init__(self) -> None: """Construct the connection mock class.""" - def cursor(self) -> None: + def cursor(self) -> NoReturn: """Getter for mock cursor.""" raise psycopg2.OperationalError("can not SELECT")However,
-> Noneis an acceptable convention for exception-raising methods.Also applies to: 51-51, 60-60, 63-63
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
tests/unit/cache/test_noop_cache.py(9 hunks)tests/unit/cache/test_postgres_cache.py(28 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- tests/unit/cache/test_noop_cache.py
🧰 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/cache/test_postgres_cache.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/cache/test_postgres_cache.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/cache/test_postgres_cache.py
🧠 Learnings (2)
📓 Common learnings
Learnt from: CR
PR: lightspeed-core/lightspeed-stack#0
File: CLAUDE.md:0-0
Timestamp: 2025-09-18T16:46:33.353Z
Learning: Applies to src/{models/**/*.py,configuration.py} : Use precise type hints in configuration (e.g., Optional[FilePath], PositiveInt, SecretStr)
Learnt from: CR
PR: lightspeed-core/lightspeed-stack#0
File: CLAUDE.md:0-0
Timestamp: 2025-09-18T16:46:33.353Z
Learning: Applies to **/*.py : Provide complete type annotations for all function parameters and return types
📚 Learning: 2025-09-18T16:46:33.353Z
Learnt from: CR
PR: lightspeed-core/lightspeed-stack#0
File: CLAUDE.md:0-0
Timestamp: 2025-09-18T16:46:33.353Z
Learning: Applies to src/{models/**/*.py,configuration.py} : Use precise type hints in configuration (e.g., Optional[FilePath], PositiveInt, SecretStr)
Applied to files:
tests/unit/cache/test_postgres_cache.py
🧬 Code graph analysis (1)
tests/unit/cache/test_postgres_cache.py (5)
src/models/config.py (2)
config(140-146)PostgreSQLDatabaseConfiguration(87-105)src/models/cache_entry.py (1)
CacheEntry(7-24)src/models/responses.py (2)
ConversationData(165-176)ReferencedDocument(179-191)src/cache/cache_error.py (1)
CacheError(4-5)src/cache/postgres_cache.py (1)
PostgresCache(17-419)
⏰ 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). (3)
- GitHub Check: e2e_tests (azure)
- GitHub Check: e2e_tests (ci)
- GitHub Check: build-pr
🔇 Additional comments (4)
tests/unit/cache/test_postgres_cache.py (4)
5-5: LGTM! Imports correctly updated for type hints.The addition of
Anyfrom typing is necessary for the type annotations added throughout the file, and the import reordering improves consistency.Also applies to: 16-17
68-75: Fixture type annotation is correct.The return type
PostgreSQLDatabaseConfigurationaccurately reflects what the fixture provides and follows the coding guidelines for complete type annotations. Based on learnings.
78-81: Excellent work adding comprehensive type annotations to all test functions.All test functions now have complete type hints for parameters and return types, following the coding guidelines perfectly. The consistent use of
MockerFixtureandPostgreSQLDatabaseConfigurationtypes improves code clarity and maintainability. As per coding guidelines.Also applies to: 92-95, 105-108, 124-127, 137-140, 152-155, 166-169, 178-181, 192-195, 206-209, 223-226, 245-248, 261-264, 274-277, 291-294, 308-311, 327-330, 344-347, 361-364, 376-379, 408-411, 432-435, 448-451
237-237: Type annotations complete for remaining test functions.The type hints are correctly applied, including the parameter-less test function on line 237 which appropriately has only a return type annotation.
Also applies to: 510-513
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: 0
🧹 Nitpick comments (1)
tests/unit/cache/test_sqlite_cache.py (1)
72-412: LGTM: Test functions properly annotated.All test functions now have correct
-> Nonereturn type annotations, aligning with the coding guidelines for complete type annotations.Consider migrating from the deprecated
tmpdirfixture totmp_pathfor better type consistency, astmp_pathreturnspathlib.Pathdirectly. This would align the runtime fixture type with the declaredPathannotation.Example migration for one test:
-def test_cache_initialization(tmpdir: Path) -> None: +def test_cache_initialization(tmp_path: Path) -> None: """Test the get operation when DB is not connected.""" - cache = create_cache(tmpdir) + cache = create_cache(tmp_path) assert cache is not None assert cache.connection is not None
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
tests/unit/cache/test_sqlite_cache.py(21 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/cache/test_sqlite_cache.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/cache/test_sqlite_cache.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/cache/test_sqlite_cache.py
🧠 Learnings (1)
📓 Common learnings
Learnt from: CR
PR: lightspeed-core/lightspeed-stack#0
File: CLAUDE.md:0-0
Timestamp: 2025-09-18T16:46:33.353Z
Learning: Applies to **/*.py : Provide complete type annotations for all function parameters and return types
Learnt from: CR
PR: lightspeed-core/lightspeed-stack#0
File: CLAUDE.md:0-0
Timestamp: 2025-09-18T16:46:33.353Z
Learning: Applies to src/{models/**/*.py,configuration.py} : Use precise type hints in configuration (e.g., Optional[FilePath], PositiveInt, SecretStr)
🧬 Code graph analysis (1)
tests/unit/cache/test_sqlite_cache.py (3)
src/cache/sqlite_cache.py (4)
SQLiteCache(19-414)connected(148-167)initialize_cache(169-187)insert_or_append(245-307)src/models/config.py (1)
SQLiteDatabaseConfiguration(75-78)src/utils/connection_decorator.py (1)
connection(6-22)
⏰ 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). (3)
- GitHub Check: e2e_tests (azure)
- GitHub Check: e2e_tests (ci)
- GitHub Check: build-pr
🔇 Additional comments (3)
tests/unit/cache/test_sqlite_cache.py (3)
5-5: LGTM: Appropriate import for mock typing.The
Anyimport is correctly used for mock class methods where strict typing is unnecessary.
42-62: LGTM: Mock classes properly typed.The type annotations for
CursorMockandConnectionMockare correct. UsingAnyfor the command parameter and cursor return type is appropriate for test mocks.
65-69: LGTM: Helper function correctly typed.The type annotations for
create_cacheare accurate, withPathparameter andSQLiteCachereturn type matching the implementation.
Description
LCORE-740: Type hints in conversation cache unit tests
Type of change
Related Tickets & Documents
Summary by CodeRabbit