feat: Increase test coverage and strengthen dicttoxml typing
Summary
- Add targeted tests for edge branches in
dicttoxml(CDATA end sequence, namespaced/numeric keys, list header and @flat handling, Decimal typing, ids attribute behavior) - Refactor
get_unique_idto accept an optionalidsparameter for controllable uniqueness and simplify type checks inget_xml_type
Test plan
- Run:
python -m pip install -r requirements-dev.txt - Run:
pytest -q --cov=json2xml --cov-report=term-missing - Verify no regressions and improved coverage, especially around
dict2xml_str,list2xml_str, and CDATA handling
Summary by Sourcery
Allow external ID tracking in get_unique_id, refine XML type detection, and add targeted tests to cover CDATA handling, XML naming, list flattening, Decimal typing, and auto-generated IDs.
Enhancements:
- Extend get_unique_id to accept an optional list of existing IDs for duplicate prevention
- Simplify get_xml_type to only distinguish Python str, int, float, and number types
Tests:
- Add tests for CDATA end-sequence splitting and wrapping
- Add tests for valid XML name conversion of numeric and namespaced keys with @flat handling
- Add tests for dict2xml_str and list2xml_str behaviors including list headers and item_flat
- Add tests for Decimal values to be treated as numbers and proper type attributes
- Add tests for automatic id attribute assignment in convert_dict
- Update test for get_unique_id to verify duplicate resolution with a provided ids list
Reviewer's Guide
This PR refactors the unique ID generation and XML type detection in dicttoxml for stronger typing and controlled uniqueness, and adds a suite of targeted tests to cover edge cases like CDATA splitting, namespaced/numeric keys, list wrapping behavior, Decimal handling, and ID attribute injection.
Class diagram for test coverage improvements in test_additional_coverage.py
classDiagram
class test_additional_coverage
test_additional_coverage : +test_cdata_end_sequence()
test_additional_coverage : +test_namespaced_numeric_keys()
test_additional_coverage : +test_list_header_flat_handling()
test_additional_coverage : +test_decimal_typing()
test_additional_coverage : +test_ids_attribute_behavior()
test_additional_coverage --> dicttoxml : tests
File-Level Changes
| Change | Details | Files |
|---|---|---|
| Refactor get_unique_id to accept optional ids list and improve uniqueness logic |
|
json2xml/dicttoxml.py |
| Simplify get_xml_type by removing legacy type-name checks |
|
json2xml/dicttoxml.py |
| Update duplicate-ID test to leverage new ids parameter and monkeypatching |
|
tests/test_dict2xml.py |
| Add targeted edge-case tests to increase coverage |
|
tests/test_additional_coverage.py |
Tips and commands
Interacting with Sourcery
-
Trigger a new review: Comment
@sourcery-ai reviewon 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 issueto create an issue from it. -
Generate a pull request title: Write
@sourcery-aianywhere in the pull request title to generate a title at any time. You can also comment@sourcery-ai titleon the pull request to (re-)generate the title at any time. -
Generate a pull request summary: Write
@sourcery-ai summaryanywhere in the pull request body to generate a PR summary at any time exactly where you want it. You can also comment@sourcery-ai summaryon the pull request to (re-)generate the summary at any time. -
Generate reviewer's guide: Comment
@sourcery-ai guideon the pull request to (re-)generate the reviewer's guide at any time. -
Resolve all Sourcery comments: Comment
@sourcery-ai resolveon 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 dismisson 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 reviewto 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
- Contact our support team for questions or feedback.
- Visit our documentation for detailed guides and information.
- Keep in touch with the Sourcery team by following us on X/Twitter, LinkedIn or GitHub.
Codecov Report
:white_check_mark: All modified and coverable lines are covered by tests.
:white_check_mark: Project coverage is 100.00%. Comparing base (43c4e18) to head (8f19e8a).
:warning: Report is 1 commits behind head on master.
Additional details and impacted files
@@ Coverage Diff @@
## master #246 +/- ##
===========================================
+ Coverage 99.30% 100.00% +0.69%
===========================================
Files 3 3
Lines 288 289 +1
===========================================
+ Hits 286 289 +3
+ Misses 2 0 -2
| Flag | Coverage Δ | |
|---|---|---|
| unittests | 100.00% <100.00%> (+0.69%) |
:arrow_up: |
Flags with carried forward coverage won't be shown. Click here to find out more.
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.