Additional assertion methods for testing XML
Project description
This library is a set of helper methods for testing XML with Python’s unittest library
Sample usage
To use these additional assertions, simply mix the xmltest.XMLAssertions class into your test class:
import unittest from xmltest import XMLAssertions class MyTestCase(unittest.TestCase, XMLAssertions): pass
Now suppose you have the following XML string that you wish to examine:
response_xml = """<?xml version="1.0" encoding="UTF-8" ?> <Response> <CardTxn> <authcode>060642</authcode> <card_scheme>Switch</card_scheme> <issuer country="UK">HSBC</issuer> </CardTxn> <reference>3000000088888888</reference> <merchantreference>1000001</merchantreference> <mode>LIVE</mode> <reason>ACCEPTED</reason> <status>1</status> <time>1071567305</time> </Response>"""
Assert the value of a particular element:
self.assertXMLElementText(response_xml, 'ACCEPTED', 'Response.reason')
Assert the attribute values of an element:
self.assertXMLElementAttributes(xml, {'country': 'UK'}, 'Response.CardTxn.issuer'}
As you can see, the assertion methods use a simple dot-separated syntax for referencing XML elements - not very sophisticated but sufficient for many situations. Fancy XPath-driven assertions to come later.
Installation
From PyPi (coming soon):
pip install unittest-xml
Contributing
To run the tests, install nose and mock:
pip install nose mock
and use:
nosetests
to run the tests.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file unittest-xml-0.1.tar.gz
.
File metadata
- Download URL: unittest-xml-0.1.tar.gz
- Upload date:
- Size: 2.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9495108eb0adb26d6a3122d4f62042af595d432be88723bc6c97ec66739edac8 |
|
MD5 | 313f6f24a378b94903f3532b26402c3d |
|
BLAKE2b-256 | ed31b2a10cbc2eac84fdb716109d66119531f81cf0ad2ad000c663fc6bd73d12 |