===================
Python XML-Unittest
===================
Anyone uses XML, for RSS, for configuration files, for... well, we all use XML
for our own reasons (folk says one can not simply uses XML, but still...).
So, your code generates XML, and everything is fine. As you follow best
practices (if you don’t, I think you should), you have written some good
unit-tests, where you compare code’s result with an expected result. I mean you
compare string with string. One day, something bad might happen.
XML is not a simple string, it is a structured document. One can not simply
compare two XML string and expect everything to be fine: attributes’s order can
change unexpectedly, elements can be optional, and no one can explain simply
how spaces and tabs works in XML formatting.
Here comes XML unittest TestCase: if you want to use the built-in unittest
package (or if it is a requirement), and you are not afraid of using xpath
expression with ``lxml``, this library is made for you.
You will be able to test your XML document, and use the power of xpath and
various schema languages to write tests that matter.
Links
=====
- Distribution: https://pypi.python.org/pypi/xmlunittest
- Documentation: http://python-xmlunittest.readthedocs.org/en/latest/
- Source: https://github.com/Exirel/python-xmlunittest
How to
======
- Extends ``xmlunittest.XmlTestCase``
- Write your tests, using the function or method that generate XML document
- Use ``xmlunittest.XmlTestCase``‘s assertion methods to validate
- Keep your tests readable
Example:
.. code-block:: python
from xmlunittest import XmlTestCase
class CustomTestCase(XmlTestCase):
def test_my_custom_test(self):
# In a real case, data come from a call to your function/method.
data = """<?xml version="1.0" encoding="UTF-8" ?>
<root xmlns:ns="uri">
<leaf id="1" active="on" />
<leaf id="2" active="on" />
<leaf id="3" active="off" />
</root>"""
# Everything starts with `assertXmlDocument`
root = self.assertXmlDocument(data.encode())
# Check namespace
self.assertXmlNamespace(root, 'ns', 'uri')
# Check
self.assertXpathsUniqueValue(root, ('./leaf/@id', ))
self.assertXpathValues(root, './leaf/@active', ('on', 'off'))
Raw data
{
"_id": null,
"home_page": null,
"name": "xmlunittest",
"maintainer": "Florian Strzelecki",
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": null,
"keywords": null,
"author": "Florian Strzelecki",
"author_email": null,
"download_url": "https://files.pythonhosted.org/packages/8f/5b/bf612e3cc56bdd2fd3120e45ced6f318b4019bfec174bce3cc4d3b41bd5b/xmlunittest-1.0.1.tar.gz",
"platform": null,
"description": "===================\nPython XML-Unittest\n===================\n\nAnyone uses XML, for RSS, for configuration files, for... well, we all use XML\nfor our own reasons (folk says one can not simply uses XML, but still...).\n\nSo, your code generates XML, and everything is fine. As you follow best\npractices (if you don\u2019t, I think you should), you have written some good\nunit-tests, where you compare code\u2019s result with an expected result. I mean you\ncompare string with string. One day, something bad might happen.\n\nXML is not a simple string, it is a structured document. One can not simply\ncompare two XML string and expect everything to be fine: attributes\u2019s order can\nchange unexpectedly, elements can be optional, and no one can explain simply\nhow spaces and tabs works in XML formatting.\n\nHere comes XML unittest TestCase: if you want to use the built-in unittest\npackage (or if it is a requirement), and you are not afraid of using xpath\nexpression with ``lxml``, this library is made for you.\n\nYou will be able to test your XML document, and use the power of xpath and\nvarious schema languages to write tests that matter.\n\n\nLinks\n=====\n\n- Distribution: https://pypi.python.org/pypi/xmlunittest\n- Documentation: http://python-xmlunittest.readthedocs.org/en/latest/\n- Source: https://github.com/Exirel/python-xmlunittest\n\n\nHow to\n======\n\n- Extends ``xmlunittest.XmlTestCase``\n- Write your tests, using the function or method that generate XML document\n- Use ``xmlunittest.XmlTestCase``\u2018s assertion methods to validate\n- Keep your tests readable\n\nExample:\n\n.. code-block:: python\n\n from xmlunittest import XmlTestCase\n\n\n class CustomTestCase(XmlTestCase):\n\n def test_my_custom_test(self):\n # In a real case, data come from a call to your function/method.\n data = \"\"\"<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n <root xmlns:ns=\"uri\">\n <leaf id=\"1\" active=\"on\" />\n <leaf id=\"2\" active=\"on\" />\n <leaf id=\"3\" active=\"off\" />\n </root>\"\"\"\n\n # Everything starts with `assertXmlDocument`\n root = self.assertXmlDocument(data.encode())\n\n # Check namespace\n self.assertXmlNamespace(root, 'ns', 'uri')\n # Check\n self.assertXpathsUniqueValue(root, ('./leaf/@id', ))\n self.assertXpathValues(root, './leaf/@active', ('on', 'off'))\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Library using lxml and unittest for unit testing XML.",
"version": "1.0.1",
"project_urls": {
"Bug Tracker": "https://github.com/Exirel/python-xmlunittest/issues",
"Source": "https://github.com/Exirel/python-xmlunittest"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "860ed134d4e05138ed98ddbf427d1fc5a54d8ff25fd5418a1bf27af8df24d460",
"md5": "447b0374baa9bf03631ed1c76a9f3e0a",
"sha256": "48d76246f3dbfd0b644d9844394e165b8f482b33996bbebe324586fe9f9cfa7a"
},
"downloads": -1,
"filename": "xmlunittest-1.0.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "447b0374baa9bf03631ed1c76a9f3e0a",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 5922,
"upload_time": "2024-07-13T08:01:59",
"upload_time_iso_8601": "2024-07-13T08:01:59.755952Z",
"url": "https://files.pythonhosted.org/packages/86/0e/d134d4e05138ed98ddbf427d1fc5a54d8ff25fd5418a1bf27af8df24d460/xmlunittest-1.0.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "8f5bbf612e3cc56bdd2fd3120e45ced6f318b4019bfec174bce3cc4d3b41bd5b",
"md5": "7e9208be4a8d3bda7d704921e59f58d8",
"sha256": "1db262eac652d21a4af4548e8fb761f516918b980d9c1ba2828e4c7ff615e19f"
},
"downloads": -1,
"filename": "xmlunittest-1.0.1.tar.gz",
"has_sig": false,
"md5_digest": "7e9208be4a8d3bda7d704921e59f58d8",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 5863,
"upload_time": "2024-07-13T08:02:02",
"upload_time_iso_8601": "2024-07-13T08:02:02.201638Z",
"url": "https://files.pythonhosted.org/packages/8f/5b/bf612e3cc56bdd2fd3120e45ced6f318b4019bfec174bce3cc4d3b41bd5b/xmlunittest-1.0.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-07-13 08:02:02",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "Exirel",
"github_project": "python-xmlunittest",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [
{
"name": "pytest",
"specs": []
},
{
"name": "pytest-cov",
"specs": []
},
{
"name": "isort",
"specs": []
},
{
"name": "flake8",
"specs": []
},
{
"name": "sphinx",
"specs": []
},
{
"name": "sphinx-rtd-theme",
"specs": []
}
],
"lcname": "xmlunittest"
}