Skip to content

test: cover init validation, util error paths and formatter fields - #138

Merged
cvas22 merged 1 commit into
masterfrom
test/137-core-validation-coverage
Oct 24, 2026
Merged

cvas22 merged 1 commit into
masterfrom
test/137-core-validation-coverage

Conversation

@cvas22

@cvas22 cvas22 commented Oct 24, 2026 •

Copy link
Copy Markdown
Collaborator

Part of #137 (items 3, 4 and 5; Sanic/Quart and Connexion/Flask are left for follow-up PRs).

Added

  • tests/test_init_validation.py: double framework init, bad custom_formatter, unknown framework, init_request_instrument before init / after non-web init / with a bad formatter or DTO class, get_request_logger before init, config_root_logger with no handlers.
  • tests/test_util_validation.py: update_formatter_for_loggers, validate_subclass, parse_int.
  • tests/test_formatters_fields.py: component fields, repr() fallback for non-serialisable extras, props merging.

Tested: Python 3.14.6 on Windows; pytest tests --ignore=tests/smoketests --ignore=tests/test_gunicorn_flask.py gives 117 passed (95 before). Smoke tests and the gunicorn test were not run.

Notes

  • init_non_web called twice does not raise (non-web init leaves _current_framework unset), so only framework init is tested for the double-init error.
  • BaseJSONFormatter.base_object_common is a class-level dict written to by every formatter instance, so component settings leak between formatters; the test fixture restores it. Not changed here.
  • get_request_logger() after init_flask() but before request instrumentation raises AttributeError instead of the intended RuntimeError; fixed separately.

Summary by CodeRabbit

  • Tests
    • Expanded automated coverage for log formatting, including component settings, fallback handling for unsupported values, and the treatment of different props values.
    • Added checks for initialization and request-logging error cases, root logger configuration, formatter selection, logger validation, and integer parsing fallbacks.

Add unit tests for the argument validation and error paths of the public
init API, the util helpers, and the optional component and props fields
of the JSON formatters.

Refs #137

Signed-off-by: Srinivas Chippagiri <cvas22@gmail.com>
@qodo-code-review

Copy link
Copy Markdown

ⓘ Qodo reviews are paused because the subscription is no longer active. Ask your workspace admin to reactivate the subscription to resume reviews. Manage billing

@coderabbitai

coderabbitai Bot commented Oct 24, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 61b59a6b-90a4-4206-844a-9f8970b2677f
Commits

Reviewing files that changed from the base of the PR and between c775fe3 and 6af1b10.

Files selected for processing: 3
  • tests/test_formatters_fields.py
  • tests/test_init_validation.py
  • tests/test_util_validation.py

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 1 remain after this review.

Walkthrough

The pull request adds tests for JSON formatter output, initialization and request-logging validation, and utility behavior. It also tests root logger configuration when JSON logging is enabled but no handlers exist.

Changes: Formatter and validation test coverage

Layer / File(s) Summary
Formatter output fields
tests/test_formatters_fields.py
Tests cover configured and default component fields, fallback serialization of non-serializable values, and merging dictionary-valued props into the output root.
Initialization and request-logging validation
tests/test_init_validation.py
Tests cover initialization errors, request instrumentation validation, request logger access before initialization, and root logger behavior when no handlers exist.
Utility behavior
tests/test_util_validation.py
Tests cover invalid logger input, formatter updates for handlers, subclass validation, and parse_int fallback behavior.

Priority: Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Other

Possibly related issues

  • bobbui/json-logging-python issue 137: The pull request adds framework-free formatter, validation, and utility tests, including initialization and logger error paths. Sanic, Quart, Connexion, and Flask coverage remains outside this pull request.
Merge Risk: Minimal · up to 6af1b

No actionable issue is established in these tests; the change is ready for normal merge checks.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 8.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 24 functions across 3 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title "test: cover init validation, util error paths and formatter fields" matches the main change. The PR adds tests in three files: tests/test_init_validation.py (initialization validation and e…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title "test: cover init validation, util error paths and formatter fields" matches the main change. The PR adds tests in three files: tests/test_init_validation.py (initialization validation and error paths), tests/test_util_validation.py (util error handling and parse_int fallback), and tests/test_formatters_fields.py (formatter component fields, non-serializable extras, and props merging). The title is specific and concise. It uses the conventional "test:" prefix and names each area. It stays under 70 characters.

Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@cvas22
cvas22 merged commit 7c58518 into master Oct 24, 2026
16 checks passed

@llamapreview llamapreview Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

LlamaPReview — Review stopped

This pull request was merged before the review finished, so LlamaPReview stopped the remaining model work. No code-review verdict was produced.

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