Name | xmlassert JSON |
Version |
0.1.0
JSON |
| download |
home_page | None |
Summary | Human-readable XML comparison for testing with clean diff output |
upload_time | 2025-08-26 04:10:59 |
maintainer | None |
docs_url | None |
author | None |
requires_python | >=3.8 |
license | MIT |
keywords |
xml
testing
assert
diff
comparison
|
VCS |
 |
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# xmlassert
**xmlassert** is a Python library designed for comparing XML documents in tests,
providing clean,
human-readable diffs when assertions fail.
Unlike raw XML comparison tools,
it ignores formatting differences and focuses on semantic equivalence.
## Features
- **Human-readable diffs**: Get clean, formatted diff output instead of cryptic XML comparisons
- **Formatting-agnostic**: Ignores whitespace, indentation, and formatting variations
- **Secure parsing**: Uses secure XML parsing practices by default
- **Test-friendly**: Perfect for `pytest`, `unittest`, and other testing frameworks
## Installation
```bash
pip install xmlassert
```
## Quick Start
``` python
from xmlassert import assert_xml_equal
# These will pass (formatting differences are ignored)
assert_xml_equal("<root><a>text</a></root>", "<root>\n <a>text</a>\n</root>")
# This will fail with a clean diff
try:
assert_xml_equal(
"<root><a>expected</a></root>",
"<root><a>actual</a></root>"
)
except AssertionError as e:
print(e) # Shows beautiful diff output
```
## Usage Examples
### Basic XML Comparison
``` python
from xmlassert import assert_xml_equal
# Passes - formatting differences are ignored
xml1 = "<root><element>value</element></root>"
xml2 = """
<root>
<element>value</element>
</root>
"""
assert_xml_equal(xml1, xml2)
```
### Pytest Example
``` python
import pytest
from xmlassert import assert_xml_equal
def test_xml_generation():
generated_xml = generate_xml() # Your function
expected_xml = """
<config>
<setting enabled="true">value</setting>
</config>
"""
assert_xml_equal(generated_xml, expected_xml)
```
### Handling XML with Comments
``` python
from xmlassert import assert_xml_equal
# Comments are ignored by default in comparison
xml_with_comments = """
<root>
<!-- This comment is ignored -->
<element>value</element>
</root>
"""
xml_without_comments = "<root><element>value</element></root>"
assert_xml_equal(xml_with_comments, xml_without_comments) # Passes
```
### Sample Output
When comparison fails, you get clean, readable diffs:
``` diff
AssertionError: XML documents differ:
--- expected
+++ actual
@@ -1,3 +1,3 @@
<root>
- <element>expected value</element>
+ <element>actual value</element>
</root>
```
Instead of the unreadable:
```
AssertionError: XML mismatch: <root><element>expected value</element></root> != <root><element>actual value</element></root>
```
## Troubleshooting
### Namespace Handling
XML namespaces are compared strictly.
Ensure your XML uses consistent namespace declarations.
### Large XML Documents
For very large documents, consider using dedicated XML diff tools.
`xmlassert` is optimized for test-sized XML snippets.
### Encoding Issues
Ensure both XML strings use the same encoding (UTF-8 recommended).
## Why xmlassert?
Compared to other XML testing approaches:
| Feature | `xmlassert` | `xml.etree` | `xmlunit` | string compare |
|---------|-----------|-------------|-----------|----------------|
| Human-readable diffs | Yes | No | Partial | No |
| Formatting-agnostic | Yes | No | Yes | No |
| Easy to use | Yes | Partial | Partial | Yes |
| Secure parsing | Yes | Partial | Yes | No |
## Links
- [PyPI Package](https://pypi.org/project/xmlassert/)
- [Source Code](https://github.com/ivanovmg/xmlassert)
- [Issue Tracker](https://github.com/ivanovmg/xmlassert/issues)
- [Changelog](CHANGELOG.md)
Raw data
{
"_id": null,
"home_page": null,
"name": "xmlassert",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": null,
"keywords": "xml, testing, assert, diff, comparison",
"author": null,
"author_email": "Maxim Ivanov <ivanovmg@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/25/11/de9c2648ecca41a78f08e3f4ce688d213790a8e003b07499015f522176c4/xmlassert-0.1.0.tar.gz",
"platform": null,
"description": "# xmlassert\n\n**xmlassert** is a Python library designed for comparing XML documents in tests,\nproviding clean,\nhuman-readable diffs when assertions fail.\nUnlike raw XML comparison tools,\nit ignores formatting differences and focuses on semantic equivalence.\n\n## Features\n\n- **Human-readable diffs**: Get clean, formatted diff output instead of cryptic XML comparisons\n- **Formatting-agnostic**: Ignores whitespace, indentation, and formatting variations\n- **Secure parsing**: Uses secure XML parsing practices by default\n- **Test-friendly**: Perfect for `pytest`, `unittest`, and other testing frameworks\n\n## Installation\n\n```bash\npip install xmlassert\n```\n\n## Quick Start\n\n``` python\nfrom xmlassert import assert_xml_equal\n\n# These will pass (formatting differences are ignored)\nassert_xml_equal(\"<root><a>text</a></root>\", \"<root>\\n <a>text</a>\\n</root>\")\n\n# This will fail with a clean diff\ntry:\n assert_xml_equal(\n \"<root><a>expected</a></root>\",\n \"<root><a>actual</a></root>\"\n )\nexcept AssertionError as e:\n print(e) # Shows beautiful diff output\n```\n\n\n## Usage Examples\n\n### Basic XML Comparison\n\n``` python\nfrom xmlassert import assert_xml_equal\n\n# Passes - formatting differences are ignored\nxml1 = \"<root><element>value</element></root>\"\nxml2 = \"\"\"\n<root>\n <element>value</element>\n</root>\n\"\"\"\nassert_xml_equal(xml1, xml2)\n```\n\n\n### Pytest Example\n\n``` python\nimport pytest\nfrom xmlassert import assert_xml_equal\n\ndef test_xml_generation():\n generated_xml = generate_xml() # Your function\n expected_xml = \"\"\"\n <config>\n <setting enabled=\"true\">value</setting>\n </config>\n \"\"\"\n assert_xml_equal(generated_xml, expected_xml)\n```\n\n\n### Handling XML with Comments\n\n``` python\nfrom xmlassert import assert_xml_equal\n\n# Comments are ignored by default in comparison\nxml_with_comments = \"\"\"\n<root>\n <!-- This comment is ignored -->\n <element>value</element>\n</root>\n\"\"\"\nxml_without_comments = \"<root><element>value</element></root>\"\nassert_xml_equal(xml_with_comments, xml_without_comments) # Passes\n```\n\n### Sample Output\n\nWhen comparison fails, you get clean, readable diffs:\n\n``` diff\nAssertionError: XML documents differ:\n--- expected\n+++ actual\n@@ -1,3 +1,3 @@\n <root>\n- <element>expected value</element>\n+ <element>actual value</element>\n </root>\n```\n\nInstead of the unreadable:\n```\nAssertionError: XML mismatch: <root><element>expected value</element></root> != <root><element>actual value</element></root>\n```\n\n## Troubleshooting\n\n### Namespace Handling\nXML namespaces are compared strictly.\nEnsure your XML uses consistent namespace declarations.\n\n### Large XML Documents\nFor very large documents, consider using dedicated XML diff tools.\n`xmlassert` is optimized for test-sized XML snippets.\n\n### Encoding Issues\nEnsure both XML strings use the same encoding (UTF-8 recommended).\n\n\n## Why xmlassert?\n\nCompared to other XML testing approaches:\n\n| Feature | `xmlassert` | `xml.etree` | `xmlunit` | string compare |\n|---------|-----------|-------------|-----------|----------------|\n| Human-readable diffs | Yes | No | Partial | No |\n| Formatting-agnostic | Yes | No | Yes | No |\n| Easy to use | Yes | Partial | Partial | Yes |\n| Secure parsing | Yes | Partial | Yes | No |\n\n\n## Links\n\n- [PyPI Package](https://pypi.org/project/xmlassert/)\n- [Source Code](https://github.com/ivanovmg/xmlassert)\n- [Issue Tracker](https://github.com/ivanovmg/xmlassert/issues)\n- [Changelog](CHANGELOG.md)\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Human-readable XML comparison for testing with clean diff output",
"version": "0.1.0",
"project_urls": {
"Changelog": "https://github.com/ivanovmg/xmlassert/blob/main/CHANGELOG.md",
"Homepage": "https://github.com/ivanovmg/xmlassert",
"Issues": "https://github.com/ivanovmg/xmlassert/issues"
},
"split_keywords": [
"xml",
" testing",
" assert",
" diff",
" comparison"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "65703a9704b353404dfc0c22030e1ea49de4823122a7f6f4e4e945e9baaf9e70",
"md5": "9a183e1cfa47a0a14053a49a3971739f",
"sha256": "3f645a675a7b2093afaf50bee1e313352466b4c992d3e3a6464d8bede777f7d7"
},
"downloads": -1,
"filename": "xmlassert-0.1.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "9a183e1cfa47a0a14053a49a3971739f",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 6132,
"upload_time": "2025-08-26T04:10:58",
"upload_time_iso_8601": "2025-08-26T04:10:58.479910Z",
"url": "https://files.pythonhosted.org/packages/65/70/3a9704b353404dfc0c22030e1ea49de4823122a7f6f4e4e945e9baaf9e70/xmlassert-0.1.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "2511de9c2648ecca41a78f08e3f4ce688d213790a8e003b07499015f522176c4",
"md5": "4c0c26848d92578772df7be06f8d8097",
"sha256": "8bdbf2a566847d409b2e987bf08d076b92edc1a2e843a255fa1f79eba7bad699"
},
"downloads": -1,
"filename": "xmlassert-0.1.0.tar.gz",
"has_sig": false,
"md5_digest": "4c0c26848d92578772df7be06f8d8097",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 8619,
"upload_time": "2025-08-26T04:10:59",
"upload_time_iso_8601": "2025-08-26T04:10:59.434671Z",
"url": "https://files.pythonhosted.org/packages/25/11/de9c2648ecca41a78f08e3f4ce688d213790a8e003b07499015f522176c4/xmlassert-0.1.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-08-26 04:10:59",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "ivanovmg",
"github_project": "xmlassert",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "xmlassert"
}