Skip to content

Commit d9b1a9f

Browse files
committed
sys.version_info is only a "named tuple"-like obj from 2.7
This also adds the mock package as a dependency for the testsuite, as we need it to test our test code.
1 parent 92c2e32 commit d9b1a9f

File tree

7 files changed

+53
-5
lines changed

7 files changed

+53
-5
lines changed

CHANGES.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,12 @@ Change Log
77
Released on XXX
88

99
* Added ordereddict as a mandatory dependency on Python 2.6.
10+
1011
* Added ``lxml``, ``genshi``, ``datrie``, ``charade``, and ``all`` extras that
1112
will do the right thing based on the specific interpreter implementation.
1213

14+
* Now requires the ``mock`` package for the testsuite.
15+
1316

1417
0.9999999/1.0b8
1518
~~~~~~~~~~~~~~~

README.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,9 @@ Please report any bugs on the `issue tracker
132132
Tests
133133
-----
134134

135-
Unit tests require the ``nose`` library and can be run using the
136-
``nosetests`` command in the root directory; ``ordereddict`` is
137-
required under Python 2.6. All should pass.
135+
Unit tests require the ``nose`` and ``mock`` libraries and can be run
136+
using the ``nosetests`` command in the root directory; ``ordereddict``
137+
is required under Python 2.6. All should pass.
138138

139139
Test data are contained in a separate `html5lib-tests
140140
<https://github.com/html5lib/html5lib-tests>`_ repository and included

html5lib/tests/support.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ def convertData(data):
128128
def errorMessage(input, expected, actual):
129129
msg = ("Input:\n%s\nExpected:\n%s\nRecieved\n%s\n" %
130130
(repr(input), repr(expected), repr(actual)))
131-
if sys.version_info.major == 2:
131+
if sys.version_info[0] == 2:
132132
msg = msg.encode("ascii", "backslashreplace")
133133
return msg
134134

html5lib/tests/test_meta.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
from __future__ import absolute_import, division, unicode_literals
2+
3+
import six
4+
from mock import Mock
5+
6+
from . import support
7+
8+
9+
def _createReprMock(r):
10+
"""Creates a mock with a __repr__ returning r
11+
12+
Also provides __str__ mock with default mock behaviour"""
13+
mock = Mock()
14+
mock.__repr__ = Mock()
15+
mock.__repr__.return_value = r
16+
mock.__str__ = Mock(wraps=mock.__str__)
17+
return mock
18+
19+
20+
def test_errorMessage():
21+
# Create mock objects to take repr of
22+
input = _createReprMock("1")
23+
expected = _createReprMock("2")
24+
actual = _createReprMock("3")
25+
26+
# Run the actual test
27+
r = support.errorMessage(input, expected, actual)
28+
29+
# Assertions!
30+
if six.PY2:
31+
assert b"Input:\n1\nExpected:\n2\nRecieved\n3\n" == r
32+
else:
33+
assert six.PY3
34+
assert "Input:\n1\nExpected:\n2\nRecieved\n3\n" == r
35+
36+
assert input.__repr__.call_count == 1
37+
assert expected.__repr__.call_count == 1
38+
assert actual.__repr__.call_count == 1
39+
assert not input.__str__.called
40+
assert not expected.__str__.called
41+
assert not actual.__str__.called

html5lib/treebuilders/etree_lxml.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def serializeElement(element, indent=0):
7979
next_element = next_element.getnext()
8080
elif isinstance(element, str) or isinstance(element, bytes):
8181
# Text in a fragment
82-
assert isinstance(element, str) or sys.version_info.major == 2
82+
assert isinstance(element, str) or sys.version_info[0] == 2
8383
rv.append("|%s\"%s\"" % (' ' * indent, element))
8484
else:
8585
# Fragment case

requirements-test.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
flake8
44
nose
55
ordereddict # Python 2.6
6+
mock

tox.ini

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ deps =
66
-r{toxinidir}/requirements-optional-cpython.txt
77
flake8
88
nose
9+
mock
910
commands =
1011
{envbindir}/nosetests -q
1112
{toxinidir}/flake8-run.sh
@@ -21,10 +22,12 @@ deps =
2122
Genshi
2223
nose
2324
six
25+
mock
2426

2527
[testenv:py26]
2628
basepython = python2.6
2729
deps =
2830
-r{toxinidir}/requirements-optional-2.6.txt
2931
flake8
3032
nose
33+
mock

0 commit comments

Comments
 (0)