Skip to content

Conversation

@vinitkumar
Copy link
Owner

@vinitkumar vinitkumar commented Aug 12, 2025

Summary by Sourcery

Bump version to 5.2.1, update dependencies for Python 3.13, enhance get_unique_id to accept custom ID lists, streamline XML type logic, and expand test coverage for dicttoxml functionality

New Features:

  • Add comprehensive unit tests for CDATA handling, XML naming, list conversion, type detection, and ID attributes

Bug Fixes:

  • Ensure get_unique_id can accept an existing ID list to avoid collisions during ID generation

Enhancements:

  • Extend get_unique_id signature to accept an optional IDs list and simplify XML type detection by removing legacy type names

Build:

  • Bump project version to 5.2.1 and remove the deprecated ‘py’ dev dependency

Documentation:

  • Regenerate requirements files for Python 3.13 and update various dependency versions in docs and root requirements

Tests:

  • Revamp duplicate ID generation test using monkeypatch and Mock
  • Add new coverage tests in tests/test_additional_coverage.py for multiple dicttoxml behaviors

…me handling

Adds coverage for CDATA edge, numeric and namespaced keys, list header behavior,
@Flat handling, Decimal typing, cdata conversion, and id attributes when ids provided.
…get_unique_id API

- Accept optional ids list to avoid collisions deterministically in tests
- Replace legacy type name checks with direct 'str'/'int'
- Update tests to use monkeypatch for duplicate id simulation
@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Aug 12, 2025

Reviewer's Guide

This pull request bumps the project version and streamlines development dependencies, refactors the unique ID generator and XML type logic in json2xml, updates and unifies requirements across docs and root files, and simplifies existing tests while adding comprehensive coverage tests for the dicttoxml module.

File-Level Changes

Change Details Files
Version bump and dev dependency cleanup
  • Increment project version to 5.2.1
  • Remove 'py' package from dev dependencies
pyproject.toml
json2xml/__init__.py
Refactor get_unique_id signature and streamline XML type detection
  • Add optional 'ids' parameter to get_unique_id with conditional initialization
  • Remove legacy Python2 type checks ('unicode', 'long') in get_xml_type
json2xml/dicttoxml.py
Update and standardize project requirements
  • Bump pip-compile target to Python 3.13 and unify invocation
  • Update various package versions and switch references from docs/requirements.in to requirements.in
  • Add/remove dependencies to align with updated build and theme requirements
docs/requirements.txt
requirements.txt
Simplify get_unique_id test and add comprehensive dicttoxml coverage
  • Refactor test_get_unique_id_with_duplicates to use pytest monkeypatch and Mock
  • Add new TestAdditionalCoverage suite covering wrap_cdata, XML naming, list conversion, and type handling
tests/test_dict2xml.py
tests/test_additional_coverage.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@codecov
Copy link

codecov bot commented Aug 12, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.30%. Comparing base (43c4e18) to head (4e19a91).
⚠️ Report is 2 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #247   +/-   ##
=======================================
  Coverage   99.30%   99.30%           
=======================================
  Files           3        3           
  Lines         288      288           
=======================================
  Hits          286      286           
  Misses          2        2           
Flag Coverage Δ
unittests 99.30% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @vinitkumar - I've reviewed your changes - here's some feedback:

  • In get_xml_type, prefer using isinstance checks instead of comparing type(val).name strings for clarity and maintainability.
  • Since get_unique_id now accepts a caller-provided ids list, consider using a set for faster lookup or cloning the list at the start to avoid mutating the caller’s data unexpectedly.
  • The new test for get_unique_id references Mock but doesn’t import it; add the appropriate import (e.g., from unittest.mock import Mock) to prevent NameError.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In get_xml_type, prefer using isinstance checks instead of comparing type(val).__name__ strings for clarity and maintainability.
- Since get_unique_id now accepts a caller-provided ids list, consider using a set for faster lookup or cloning the list at the start to avoid mutating the caller’s data unexpectedly.
- The new test for get_unique_id references Mock but doesn’t import it; add the appropriate import (e.g., from unittest.mock import Mock) to prevent NameError.

## Individual Comments

### Comment 1
<location> `tests/test_dict2xml.py:784` </location>
<code_context>
-
-        module.make_id = mock_make_id
-        module.get_unique_id = patched_get_unique_id
+        unique_id = dicttoxml.get_unique_id("some_element", ids=ids)

-        try:
-            result = dicttoxml.get_unique_id("test")
-            assert result == "test_789012"
-            assert call_count == 2
-        finally:
-            module.make_id = original_make_id
-            module.get_unique_id = original_get_unique_id
+        assert unique_id == "new_id"
+        assert make_id_mock.call_count == 2

     def test_convert_with_bool_direct(self) -> None:
</code_context>

<issue_to_address>
Consider adding a test for get_unique_id when ids is None.

Adding a test for get_unique_id with ids=None will verify the function's default behavior and help prevent regressions.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment on lines 784 to 787
unique_id = dicttoxml.get_unique_id("some_element", ids=ids)

try:
result = dicttoxml.get_unique_id("test")
assert result == "test_789012"
assert call_count == 2
finally:
module.make_id = original_make_id
module.get_unique_id = original_get_unique_id
assert unique_id == "new_id"
assert make_id_mock.call_count == 2
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion (testing): Consider adding a test for get_unique_id when ids is None.

Adding a test for get_unique_id with ids=None will verify the function's default behavior and help prevent regressions.

@vinitkumar vinitkumar merged commit 3bf8ce9 into master Aug 12, 2025
31 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.

2 participants