Skip to content

Conversation

@tisnik
Copy link
Contributor

@tisnik tisnik commented Jul 15, 2025

Description

LCORE-303: fixed pylint issues

Type of change

  • Refactor
  • New feature
  • Bug fix
  • CVE fix
  • Optimization
  • Documentation Update
  • Configuration Update
  • Bump-up service version
  • Bump-up dependent library
  • Bump-up library or tool used for development (does not change the final image)
  • CI configuration change
  • Konflux configuration change
  • Unit tests improvement
  • Integration tests improvement
  • End to end tests improvement

Related Tickets & Documents

  • Related Issue #LCORE-303

Summary by CodeRabbit

  • Tests
    • Added and updated module-level docstrings for improved clarity in multiple test files.
    • Renamed pytest fixtures with explicit naming for consistency and readability.
    • Removed unused parameters from test functions to simplify signatures.
    • Improved import organization and code formatting across test modules.
    • Enhanced test coverage for response models and attachment handling.
    • Added docstrings to test helper methods and classes for better documentation.
    • Improved mock object representations and added pylint directives for cleaner test output.
    • Minor assertion style and comment formatting improvements.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 15, 2025

Walkthrough

The changes primarily enhance test code clarity and maintainability across several unit test modules. Updates include adding module-level docstrings, improving import organization, renaming fixtures and parameters for clarity, refining assertion styles, and adding string representations to mock classes. Several new test cases were introduced to increase coverage of model validation. No production code or test logic was altered.

Changes

File(s) Change Summary
tests/unit/app/endpoints/test_authorized.py
tests/unit/app/endpoints/test_config.py
tests/unit/app/endpoints/test_feedback.py
tests/unit/app/endpoints/test_health.py
tests/unit/app/endpoints/test_info.py
tests/unit/app/endpoints/test_models.py
tests/unit/app/endpoints/test_query.py
tests/unit/app/endpoints/test_root.py
tests/unit/app/endpoints/test_streaming_query.py
Added module-level docstrings describing the purpose of each test file.
tests/unit/app/endpoints/test_config.py
tests/unit/app/endpoints/test_feedback.py
tests/unit/app/endpoints/test_info.py
tests/unit/app/endpoints/test_models.py
tests/unit/app/endpoints/test_query.py
tests/unit/app/endpoints/test_root.py
Removed unused mocker parameters from test function signatures.
tests/unit/app/endpoints/test_models.py
tests/unit/app/endpoints/test_health.py
Improved import order for clarity and organization.
tests/unit/app/endpoints/test_query.py
tests/unit/app/endpoints/test_streaming_query.py
Renamed fixtures and parameters for clarity; improved mock class representations with __str__ and __repr__; reordered and grouped imports; added pylint disables; added docstrings to fixtures.
tests/unit/app/test_routers.py Added docstrings to MockFastAPI class methods.
tests/unit/models/test_config.py Improved import organization and assertion style consistency.
tests/unit/models/test_requests.py Added test for unknown attachment content types; added pylint directive to suppress false positive warning.
tests/unit/models/test_responses.py Added module docstring, new imports, and additional test cases for required field validation and status response variations.
tests/unit/runners/test_data_collector_runner.py Added pylint directive to suppress "broad-exception-caught" warning.
tests/unit/utils/test_endpoints.py Renamed fixtures with _fixture suffix, set explicit names, added docstrings, and specified UTF-8 encoding for file opening.

Poem

🐇
In the meadow of tests, we pruned and we grew,
Docstrings now blossom, and fixtures feel new.
Imports are tidy, assertions aligned,
New tests for models—no bug left behind!
With clarity hopping, our code's in full view—
A rabbit’s delight in the work we pursue!


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2d8c98b and d368e88.

📒 Files selected for processing (3)
  • tests/unit/app/endpoints/test_query.py (12 hunks)
  • tests/unit/models/test_requests.py (3 hunks)
  • tests/unit/models/test_responses.py (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • tests/unit/models/test_requests.py
  • tests/unit/models/test_responses.py
  • tests/unit/app/endpoints/test_query.py
⏰ 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: build-pr
✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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

🔭 Outside diff range comments (1)
tests/unit/app/endpoints/test_query.py (1)

108-161: Assertion hard-codes user_id_placeholder – likely to break

query_endpoint_handler passes the real user id extracted from auth, yet the assertion expects the constant "user_id_placeholder".
Unless the production code deliberately overwrites the user id, this test will fail when Black is fixed.

Proposed fix – relax the expectation:

-        mock_transcript.assert_called_once_with(
-            user_id="user_id_placeholder",
+        mock_transcript.assert_called_once_with(
+            user_id=mocker.ANY,

or, if the real id should be mock_user_id:

-            user_id="user_id_placeholder",
+            user_id="mock_user_id",

Verify the production implementation and adjust accordingly.

🧹 Nitpick comments (6)
tests/unit/models/test_requests.py (1)

22-33: Fix typo in method name.

The test logic is correct and provides good coverage for edge cases with unknown content types. However, there's a typo in the method name.

-    def test_constructor_unknown_attachmen_type(self) -> None:
+    def test_constructor_unknown_attachment_type(self) -> None:
tests/unit/models/test_responses.py (1)

60-67: Good addition of required field validation tests.

These tests enhance coverage by verifying that Pydantic models properly enforce required fields. Consider using more specific exception types like ValidationError instead of the generic Exception for better test precision.

-        with pytest.raises(Exception):
+        with pytest.raises(ValidationError):

Also applies to: 79-82

tests/unit/app/endpoints/test_query.py (4)

32-34: Redundant autouse=True + explicit fixture parameter

Because the fixture is autouse=True, every test already receives the initialized configuration; declaring it again as a parameter (e.g. def test_…(setup_configuration, …)) is optional.
Retaining both is safe but adds indirection; consider dropping either the autouse flag or the explicit parameter for brevity.


61-68: Same redundancy for the agent-mock fixture

The prepare_agent_mocks_fixture is also autouse + explicitly injected in some tests. Trim one usage style for consistency with the previous comment.


120-122: Inverted boolean is hard to read

transcripts_disabled = (not store_transcript_to_file) doubles the negation.
A clearer expression is:

-    mock_config.user_data_collection_configuration.transcripts_disabled = (
-        not store_transcript_to_file
-    )
+    mock_config.user_data_collection_configuration.transcripts_disabled = (
+        not store_transcript_to_file
+    )

Even better:

mock_config.user_data_collection_configuration.transcripts_disabled = \
    not store_transcript_to_file

Consider renaming the variable or using a positive flag to remove the not.


858-869: get_rag_toolgroups test only checks happy paths

Consider adding an assertion for the structure of the returned dict (e.g. presence of "args" and "vector_db_ids") and a test for invalid input (e.g. None).

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between cabe14e and c844125.

📒 Files selected for processing (15)
  • tests/unit/app/endpoints/test_authorized.py (1 hunks)
  • tests/unit/app/endpoints/test_config.py (2 hunks)
  • tests/unit/app/endpoints/test_feedback.py (2 hunks)
  • tests/unit/app/endpoints/test_health.py (1 hunks)
  • tests/unit/app/endpoints/test_info.py (1 hunks)
  • tests/unit/app/endpoints/test_models.py (2 hunks)
  • tests/unit/app/endpoints/test_query.py (12 hunks)
  • tests/unit/app/endpoints/test_root.py (1 hunks)
  • tests/unit/app/endpoints/test_streaming_query.py (8 hunks)
  • tests/unit/app/test_routers.py (1 hunks)
  • tests/unit/models/test_config.py (4 hunks)
  • tests/unit/models/test_requests.py (3 hunks)
  • tests/unit/models/test_responses.py (4 hunks)
  • tests/unit/runners/test_data_collector_runner.py (1 hunks)
  • tests/unit/utils/test_endpoints.py (4 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (7)
tests/unit/app/endpoints/test_info.py (2)
src/app/endpoints/info.py (1)
  • info_endpoint_handler (24-26)
src/configuration.py (2)
  • configuration (47-52)
  • AppConfig (20-100)
tests/unit/app/endpoints/test_root.py (1)
src/app/endpoints/root.py (1)
  • root_endpoint_handler (774-777)
tests/unit/models/test_requests.py (1)
src/models/requests.py (1)
  • Attachment (11-55)
tests/unit/models/test_config.py (2)
src/models/config.py (1)
  • AuthenticationConfiguration (134-151)
src/configuration.py (1)
  • mcp_servers (79-84)
tests/unit/models/test_responses.py (1)
src/models/responses.py (3)
  • StatusResponse (215-244)
  • AuthorizedResponse (247-268)
  • UnauthorizedResponse (271-285)
tests/unit/app/endpoints/test_streaming_query.py (1)
tests/unit/app/endpoints/test_query.py (2)
  • setup_configuration_fixture (33-58)
  • prepare_agent_mocks_fixture (62-68)
tests/unit/utils/test_endpoints.py (1)
src/models/requests.py (1)
  • QueryRequest (60-133)
🪛 GitHub Actions: Black
tests/unit/app/endpoints/test_query.py

[error] 1-1: Black formatting check failed. File would be reformatted. Run 'black --write' to fix code style issues.

⏰ 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: build-pr
🔇 Additional comments (34)
tests/unit/runners/test_data_collector_runner.py (1)

58-58: LGTM: Appropriate pylint suppression for test context.

The broad exception catching is intentional in this test to verify that the start_data_collector function properly raises and propagates exceptions. The targeted pylint disable comment is well-placed and aligns with the PR's objective of fixing pylint issues.

tests/unit/models/test_requests.py (2)

1-2: LGTM: Clear module-level documentation.

The module docstring clearly describes the purpose of the test file.


69-72: LGTM: Appropriate pylint suppression for false positive.

The pylint disable comment correctly addresses a false positive where pylint cannot infer that qr.attachments is a list when it's not None. The comment clearly explains it's a false positive.

tests/unit/utils/test_endpoints.py (5)

17-23: LGTM: Improved fixture naming and file handling.

The explicit fixture naming and UTF-8 encoding specification are good practices that improve code clarity and cross-platform compatibility.


26-37: LGTM: Consistent fixture naming pattern with improved documentation.

The explicit fixture naming and added docstring improve code clarity while maintaining the same functionality.


40-52: LGTM: Consistent fixture improvements.

The naming pattern and documentation are consistent with other fixtures in the file.


55-68: LGTM: Consistent pattern maintained.

The fixture naming and documentation follow the established pattern in this file.


71-80: LGTM: Final fixtures follow the same improved pattern.

All fixtures now use consistent naming conventions with explicit names and clear documentation.

tests/unit/app/endpoints/test_authorized.py (1)

1-2: LGTM: Clear module documentation.

The module docstring clearly describes the purpose of the test file, improving code documentation consistency across the test suite.

tests/unit/app/endpoints/test_health.py (2)

1-2: LGTM: Clear module documentation.

The module docstring clearly describes the purpose of the test file.


5-6: LGTM: Improved import organization.

Moving the HealthStatus import to a more logical position improves code organization and readability.

tests/unit/app/test_routers.py (1)

32-32: LGTM! Good documentation improvements.

The added docstrings enhance code clarity and address pylint requirements for method documentation. The descriptions accurately reflect the purpose of each method.

Also applies to: 36-36

tests/unit/app/endpoints/test_root.py (2)

1-1: Good addition of module-level docstring.

The docstring clearly describes the file's purpose and addresses pylint requirements for module documentation.


6-6: Correct removal of unused parameter.

Removing the unused mocker parameter eliminates pylint warnings and simplifies the function signature without affecting test functionality.

tests/unit/app/endpoints/test_info.py (2)

1-1: Good addition of module-level docstring.

The docstring clearly identifies the file's purpose and improves code documentation.


7-7: Appropriate removal of unused parameter.

The mocker parameter is not used in this test function, so removing it correctly addresses pylint warnings.

tests/unit/app/endpoints/test_feedback.py (2)

1-1: Good addition of module-level docstring.

The docstring provides clear identification of the file's purpose and improves documentation.


128-128: Correct removal of unused parameter.

The test_feedback_status function doesn't use any mocking functionality, so removing the unused mocker parameter appropriately addresses pylint warnings.

tests/unit/app/endpoints/test_config.py (2)

1-1: Good addition of module-level docstring.

The docstring clearly describes the file's purpose and enhances code documentation.


25-25: Appropriate cleanup of unused parameter.

The mocker parameter is not used in this test function, so removing it correctly addresses pylint warnings and simplifies the function signature.

tests/unit/app/endpoints/test_models.py (3)

1-1: Excellent addition of module-level docstring.

The docstring clearly describes the module's purpose and addresses pylint documentation requirements.


5-5: Good import organization improvement.

Adding the pytest import at the module level improves code organization and follows standard practices.


68-68: Correctly removed unused mocker parameter.

The test function doesn't use mocking, so removing the unused parameter addresses the pylint unused-argument warning appropriately.

tests/unit/models/test_config.py (3)

4-4: Excellent import organization improvements.

Moving Path, ValidationError, and AuthenticationConfiguration to the top-level imports eliminates redundant imports within functions and improves code organization.

Also applies to: 8-8, 18-18


99-100: Good refactoring of pytest.raises for readability.

Pre-assigning the match string to a variable improves readability and follows good practices for long error messages.


310-310: More pythonic assertion style.

Using assert not cfg.mcp_servers is more idiomatic than assert cfg.mcp_servers == [] for checking empty collections.

tests/unit/models/test_responses.py (2)

1-1: Great addition of comprehensive module-level docstring.

The docstring clearly describes all the response models being tested, addressing pylint documentation requirements effectively.


35-46: Excellent test splitting for better clarity.

Separating the constructor tests for enabled and disabled states improves test organization and makes test intentions clearer.

tests/unit/app/endpoints/test_streaming_query.py (5)

1-4: Excellent documentation and pylint configuration.

The module-level docstring clearly describes the test purpose, and the pylint disable comment appropriately handles the legitimate case of a comprehensive test file.


7-7: Good addition of missing imports.

Adding pytest, StreamingResponse, APIConnectionError, and UserMessage imports improves code organization and addresses import-related pylint issues.

Also applies to: 10-10, 12-13


57-58: Excellent fixture naming and documentation improvements.

Renaming fixtures with explicit names (setup_configuration_fixture, prepare_agent_mocks_fixture) and adding descriptive docstrings significantly improves test readability and maintainability.

Also applies to: 85-87


351-361: Great enhancement of mock objects with string representations.

Adding __str__ and __repr__ methods with docstrings to the MockShield classes improves debugging output and test clarity when these mocks are used in assertions or error messages.

Also applies to: 398-409


216-216: Good comment style consistency improvements.

Updating comment formatting and capitalization creates a more consistent and professional codebase.

Also applies to: 297-298, 334-335

tests/unit/app/endpoints/test_query.py (1)

377-388: 👍 Added __str__ / __repr__ for MockShield

The custom dunder methods improve debugging output and log clarity; nice touch.

Comment on lines +1 to +4
"""Unit tests for the /query REST API endpoint."""

# pylint: disable=too-many-lines

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Black formatter failing – run black before merging

GitHub Actions shows a Black failure. The whole module must be reformatted or the merge will be blocked.
Run:

black tests/unit/app/endpoints/test_query.py

and commit the result.

🧰 Tools
🪛 GitHub Actions: Black

[error] 1-1: Black formatting check failed. File would be reformatted. Run 'black --write' to fix code style issues.

🤖 Prompt for AI Agents
In tests/unit/app/endpoints/test_query.py at the beginning of the file, the code
is not formatted according to Black's style guidelines, causing GitHub Actions
to fail. Run the Black formatter on the entire file using the command `black
tests/unit/app/endpoints/test_query.py` and commit the reformatted file to fix
the issue.

@tisnik tisnik force-pushed the lcore-303-fixed-pylint-issues- branch from c844125 to 2d8c98b Compare July 15, 2025 06:10
@tisnik tisnik merged commit aa2454f into lightspeed-core:main Jul 15, 2025
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant