Library using lxml and unittest for unit testing XML.
Project description
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-hypernode.com/pypi/xmlunittest
Documentation: http://python-xmlunittest.readthedocs.org/en/latest/
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:
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'))
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file xmlunittest-1.0.1.tar.gz
.
File metadata
- Download URL: xmlunittest-1.0.1.tar.gz
- Upload date:
- Size: 5.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1db262eac652d21a4af4548e8fb761f516918b980d9c1ba2828e4c7ff615e19f |
|
MD5 | 7e9208be4a8d3bda7d704921e59f58d8 |
|
BLAKE2b-256 | 8f5bbf612e3cc56bdd2fd3120e45ced6f318b4019bfec174bce3cc4d3b41bd5b |
File details
Details for the file xmlunittest-1.0.1-py3-none-any.whl
.
File metadata
- Download URL: xmlunittest-1.0.1-py3-none-any.whl
- Upload date:
- Size: 5.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 48d76246f3dbfd0b644d9844394e165b8f482b33996bbebe324586fe9f9cfa7a |
|
MD5 | 447b0374baa9bf03631ed1c76a9f3e0a |
|
BLAKE2b-256 | 860ed134d4e05138ed98ddbf427d1fc5a54d8ff25fd5418a1bf27af8df24d460 |