Skip to content

Conversation

@vinitkumar
Copy link
Owner

@vinitkumar vinitkumar commented Feb 21, 2025

Summary by Sourcery

Added tests to increase code coverage for edge cases and error handling in the dicttoxml module, including tests for unsupported data types, invalid XML characters in keys, lists containing None values, and custom IDs.

Tests:

  • Added tests to increase code coverage for edge cases and error handling in the dicttoxml module.
  • Added tests for handling unsupported data types, invalid XML characters in keys, and lists containing None values.
  • Added tests for generating custom IDs.

@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Feb 21, 2025

Reviewer's Guide by Sourcery

This pull request adds several new test cases to tests/test_dict2xml.py to increase code coverage and improve the robustness of the dicttoxml library. The new tests cover edge cases such as handling unsupported data types, invalid XML characters in keys, None values in lists, and custom IDs.

No diagrams generated as the changes look simple and do not need a visual representation.

File-Level Changes

Change Details Files
Added tests to cover previously uncovered lines in dicttoxml.py, focusing on edge cases and error handling.
  • Added a test case for get_xml_type when an unsupported type is passed.
  • Added a test case for make_valid_xml_name to handle invalid XML characters in keys.
  • Added a test case for dict2xml_str to raise a TypeError when an invalid type is encountered.
  • Added a test case for convert_dict to raise a TypeError when an invalid type is encountered.
  • Added a test case for convert_list to raise a TypeError when an invalid type is encountered.
  • Added a test case for convert_list to handle None values.
  • Added a test case for convert_list to handle custom IDs.
tests/test_dict2xml.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!
  • Generate a plan of action for an issue: Comment @sourcery-ai plan on
    an issue to generate a plan of action for it.

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 Feb 21, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.22%. Comparing base (045cf0b) to head (6d16860).
Report is 6 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #230      +/-   ##
==========================================
+ Coverage   95.71%   97.22%   +1.51%     
==========================================
  Files           6        6              
  Lines         676      720      +44     
==========================================
+ Hits          647      700      +53     
+ Misses         29       20       -9     
Flag Coverage Δ
unittests 97.22% <100.00%> (+1.51%) ⬆️

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:

Overall Comments:

  • These tests are good, but could be improved by using pytest.mark.parametrize to avoid repetition.
Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟡 Testing: 1 issue found
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

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.

class CustomClass:
pass

items = [CustomClass()]
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 testing convert_list with a mix of valid and invalid types

Currently, test_convert_list_invalid_type checks the behavior when all items in the list are of an invalid type. It would be valuable to add a test case where the list contains a mix of valid (e.g., str, int, dict) and invalid types to ensure the function handles such scenarios gracefully and doesn't fail entirely.

Suggested implementation:

    def test_convert_list_mixed_types(self):
        """Test convert_list with a mix of valid and invalid types."""
        class CustomClass:
            pass

        items = ["valid string", 100, {"a": "b"}, CustomClass()]
        with pytest.raises(TypeError, match="Unsupported data type:"):
            dicttoxml.convert_list(
                items=items,
                ids=None,
                parent="root",
                attr_type=False,
                item_func=lambda x: "item",
                cdata=False,
                item_wrap=False
            )

    def test_convert_list_with_none(self):
        ...

Place the new test function in an appropriate location within the file to ensure consistency with the test suite structure.

@vinitkumar vinitkumar merged commit b704fba into master Feb 21, 2025
162 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