Skip to content

Commit c99e58f

Browse files
committed
Housekeeping & version management
Thanks to an external contribution I update this project. Good! So now `xmlunittest` will be tested with `tox`, and still support Python 2.7 and 3.4. However, no support for older version of Python (no 2.6, no 3.3, etc.). Also, Python 2.7 works fine with lxml 2.3.x, but not Python 3.4. So, technically, it "works" with lxml 2.3.x, but to play safe, I prefer to say "only lxml 3.x and above". Ah, and thanks to @metamatik I now use the gender-neutral "their/them" in the documentation - I hope I didn't miss one! And version 0.3.1, too.
1 parent 7913c3e commit c99e58f

7 files changed

+71
-47
lines changed

README.rst

+1-11
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ Links
3535
How to
3636
======
3737

38-
- Extends xmlunittest.XmlTestCase
38+
- Extends ``xmlunittest.XmlTestCase``
3939
- Write your tests, using the function or method that generate XML document
4040
- Use xmlunittest.XmlTestCase‘s assertion methods to validate
4141
- Keep your test readable
@@ -66,13 +66,3 @@ Example:
6666
# Check
6767
self.assertXpathsUniqueValue(root, ('./leaf@id', ))
6868
self.assertXpathValues(root, './leaf@active', ('on', 'off'))
69-
70-
71-
Running the tests
72-
======
73-
74-
To run the unit tests for this package::
75-
76-
77-
pip install tox
78-
tox

doc/index.rst

+49-10
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,8 @@ Compatibility
4242

4343
Python ``xmlunittest`` has been tested with:
4444

45-
* ``lxml`` version 3.4.0
45+
* ``lxml`` version 3.0 and 3.4.
4646
* Python 2.7.6
47-
* Python 3.3.0
4847
* Python 3.4.0
4948

5049
Be aware: as a lot of string manipulation is involved, a lot of issues can
@@ -56,6 +55,27 @@ a Py2/Py3 compatible library.
5655
Python 2.7.6 support is maintained for now, but it will be eventually
5756
dropped. It's never too late to switch to Python 3!
5857

58+
LXML version 2.x or 3.x?
59+
------------------------
60+
61+
When dealing with version number, it appears that ``xmlunittest`` works with:
62+
63+
* Python 2.7 and lxml 2.3.5 and above.
64+
* Pytonn 3.4 and lmxl 3.0 and above.
65+
66+
.. warning::
67+
68+
No, ``xmlunittest`` **does not work** with Python 3 and an older version of
69+
lxml < 3.0. Also, note that this package is only tested with lxml >= 3.0.
70+
It works, but without warranty.
71+
72+
Why not Python 3.3?
73+
-------------------
74+
75+
This package works with Python 2.7, but it's only because we are lucky enough.
76+
This is a small project, and it does not aim to support more than one major
77+
version of python. The latest, the better!
78+
5979

6080
How to
6181
======
@@ -93,7 +113,7 @@ Example::
93113

94114

95115
Alternativly, one can use the :py:class:`XmlTestMixin` instead of the
96-
:py:class:`XmlTestCase`, as long as its own class also extends
116+
:py:class:`XmlTestCase`, as long as their own class also extends
97117
:py:class:`unittest.TestCase`.
98118

99119
This is convenient when there is already a subclass of
@@ -134,8 +154,8 @@ and again? If it is related only to XML tests, maybe you can share it?
134154

135155
First, you can fork the `project's github repository`__, then you will need
136156
some tools for development: all dependencies are available into the
137-
``requirements.txt`` file. You should also use a virtualenv (in fact two, one
138-
per python version).
157+
``requirements.txt`` file. You should also use a virtualenv (use two for each
158+
version, or use tox).
139159

140160
See an example of install (without virtualenv)::
141161

@@ -147,13 +167,32 @@ See an example of install (without virtualenv)::
147167

148168
.. __: https://github.com/Exirel/python-xmlunittest
149169

170+
.. note::
171+
172+
Installing lxml is not easy if you are not prepared. You will need some
173+
extra source package on your favorite OS (in particular some XML libs and
174+
python sources).
175+
176+
177+
Testing with tox
178+
----------------
179+
180+
Now that ``xmlunittest`` uses `tox`__ to run the tests, it's even easier to
181+
perform tests on multiple version of python. Instead of using ``py.test`` do::
182+
183+
$ tox test
184+
185+
And that's all! **Remember: Python 2.7 and Python 3.4. Nothing more.**
186+
187+
.. __: https://tox.readthedocs.org/en/latest/
188+
150189
Tips
151190
----
152191

153192
**Do**:
154193

155-
* Always tests with both Python 2.7, Python 3.3 and Python 3.4.
156-
* Always tests with namespaces
194+
* Always test with both Python 2.7 and Python 3.4 - use Tox!
195+
* Always test with namespaces
157196
* Always provide unit-tests.
158197
* Always provide documentation.
159198
* It's better to respect PEP8.
@@ -162,7 +201,7 @@ Tips
162201

163202
* Never add any other library. ``xmlunittest`` uses ``lxml`` and that's enough!
164203
* If you have to add a ``data.encode(charset)`` into an assert method, it's
165-
probably not be a good idea.
204+
probably not a good idea.
166205
* XML documents can not be compared as simple strings. Don't compare them
167-
as simple string. Don't.
168-
* Don't write more than 80 characters per line. Please. Don't.
206+
as simple string. **Don't.**
207+
* Don't write more than 80 characters per line. Please. **Don't.**

doc/xmlunittest.rst

+7-7
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ Document assertions
6767

6868
:param string root_tag: Optional, root element's tag name
6969

70-
One can provide the root element's tag name to the method for his own
70+
One can provide the root element's tag name to the method for their own
7171
convenience.
7272

7373
.. rubric:: Example
@@ -494,20 +494,20 @@ your own schema objects in these various schema languages.
494494
XML documents comparison assertion
495495
==================================
496496

497-
Sometimes, one may want to check a global XML document, because he know exactly
498-
what is expected, and can rely on a kind of "string compare". Of course, XML
499-
is not a simple string, and requires more than just an
497+
Sometimes, one may want to check a global XML document, because they know
498+
exactly what is expected, and can rely on a kind of "string compare". Of
499+
course, XML is not a simple string, and requires more than just an
500500
``assert data == expected``, because order of elements can vary, order of
501-
attributes, etc.
501+
attributes too, namespaces can come into play, etc.
502502

503503
In these cases, one can use the powerful - also dangerous - feature of `LXML
504504
Output Checker`. See also the documentation of the module
505505
`doctestcompare <http://lxml.de/api/lxml.doctestcompare-module.html>`_ for
506506
more information on the underlying implementation.
507507

508508
And as always, remember that the whole purpose of this :py:mod:`xmlunittest`
509-
is to **not** compare XML formated string. But, whatever, this function could
510-
help. May be.
509+
is to **avoid** any comparison of XML formated strings. But, whatever, this
510+
function could help. Maybe.
511511

512512
.. py:method:: XmlTestMixin.assertXmlEquivalentOutputs(data, expected)
513513

requirements.txt

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
pytest>=2.0.3
22
pytest-cov>=1.8.1
33
lxml>=2.3,<3.4.0
4+
tox>=1.8.1
5+
sphinx>=1.2.3

setup.py

-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
- Source: https://github.com/Exirel/python-xmlunittest
99
1010
"""
11-
1211
import codecs
1312
import os
1413

@@ -25,7 +24,6 @@ def read(*parts):
2524
'Intended Audience :: Developers',
2625
'License :: OSI Approved :: MIT License',
2726
'Programming Language :: Python :: 2.7',
28-
'Programming Language :: Python :: 3.3',
2927
'Programming Language :: Python :: 3.4',
3028
'Topic :: Software Development :: Libraries :: Python Modules',
3129
'Topic :: Software Development :: Testing',

tox.ini

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
[tox]
2-
envlist = py27, py33, py34
2+
envlist = py27, py34
33

44
[testenv]
55

66
commands =
7-
py.test
7+
py.test test.py
88

99
deps =
10-
lxml==2.3
10+
lxml==3.0
1111
pytest==2.6.4

xmlunittest.py

+9-14
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,13 @@ class XmlTestMixin(object):
1717
1818
One may want to extends unittest.TestCase itself, and then uses this
1919
mixin class to add specific XML assertions.
20-
2120
"""
2221
default_partial_tag = 'partialTest'
2322

2423
def assertXmlDocument(self, data):
2524
"""Asserts `data` is an XML document and returns it.
2625
2726
Assertion and XML parsing using lxml.
28-
2927
"""
3028
# no assertion yet
3129
try:
@@ -57,7 +55,6 @@ def assertXmlNamespace(self, node, prefix, uri):
5755
"""Asserts `node` declares namespace `uri` using `prefix`.
5856
5957
One can use this method on element node.
60-
6158
"""
6259
self.assertIn(prefix, node.nsmap)
6360
self.assertEqual(node.nsmap.get(prefix), uri)
@@ -67,7 +64,6 @@ def assertXmlHasAttribute(self, node, attribute, **kwargs):
6764
6865
Argument `attribute` must be the attribute's name, with
6966
namespace's prefix (notation 'ns:att' and not '{uri}att').
70-
7167
"""
7268
assert attribute in node.attrib
7369

@@ -79,9 +75,7 @@ def assertXmlHasAttribute(self, node, attribute, **kwargs):
7975
kwargs.get('expected_values'))
8076

8177
def assertXmlNode(self, node, **kwargs):
82-
"""Asserts `node` is an element node with expected tag and value.
83-
84-
"""
78+
"""Asserts `node` is an element node with expected tag and value."""
8579
# Assert `node` is an element node and not None or a string or
8680
# anything like this
8781
self.assertIsInstance(node, etree._Element)
@@ -189,15 +183,17 @@ def assertXmlValidXSchema(self, node, xschema=None, filename=None,
189183

190184
if xschema is None and filename is not None:
191185
with open(filename, 'r') as xschema_file:
192-
schema = etree.XMLSchema(etree.XML(xschema_file.read().encode(encoding)))
186+
schema = etree.XMLSchema(
187+
etree.XML(xschema_file.read().encode(encoding)))
193188

194189
if schema is None:
195190
raise ValueError('No valid XMLSchema given.')
196191

197192
if not schema.validate(node):
198193
self.fail(schema.error_log.last_error)
199194

200-
def assertXmlValidRelaxNG(self, node, relaxng=None, filename=None, encoding='utf-8'):
195+
def assertXmlValidRelaxNG(self, node, relaxng=None, filename=None,
196+
encoding='utf-8'):
201197
"""Asserts XML node is valid according to the given RelaxNG."""
202198
schema = None
203199

@@ -208,7 +204,8 @@ def assertXmlValidRelaxNG(self, node, relaxng=None, filename=None, encoding='utf
208204

209205
if relaxng is None and filename is not None:
210206
with open(filename, 'r') as relaxng_file:
211-
schema = etree.RelaxNG(etree.XML(relaxng_file.read().encode(encoding)))
207+
schema = etree.RelaxNG(
208+
etree.XML(relaxng_file.read().encode(encoding)))
212209

213210
if schema is None:
214211
raise ValueError('No valid RelaxNG given.')
@@ -225,7 +222,6 @@ def assertXmlEquivalentOutputs(self, data, expected):
225222
check than just a kind of output.
226223
227224
See LXMLOutputChecker documentation for more information.
228-
229225
"""
230226
checker = LXMLOutputChecker()
231227

@@ -239,10 +235,9 @@ def assertXmlEquivalentOutputs(self, data, expected):
239235
class XmlTestCase(unittest.TestCase, XmlTestMixin):
240236
"""XML test case for unit test using python unittest built-in package.
241237
242-
One can extends this class for his test case and use helpful assertion
243-
method.
238+
One can extends this class for their test cases and use helpful assertion
239+
methods.
244240
245241
XML parsing uses python lxml.etree.
246-
247242
"""
248243
pass

0 commit comments

Comments
 (0)