Skip to content

Commit

Permalink
sys.version_info is only a "named tuple"-like obj from 2.7
Browse files Browse the repository at this point in the history
This also adds the mock package as a dependency for the testsuite,
as we need it to test our test code.
  • Loading branch information
gsnedders committed Dec 3, 2015
1 parent 92c2e32 commit d9b1a9f
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 5 deletions.
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@ Change Log
Released on XXX

* Added ordereddict as a mandatory dependency on Python 2.6.

* Added ``lxml``, ``genshi``, ``datrie``, ``charade``, and ``all`` extras that
will do the right thing based on the specific interpreter implementation.

* Now requires the ``mock`` package for the testsuite.


0.9999999/1.0b8
~~~~~~~~~~~~~~~
Expand Down
6 changes: 3 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,9 @@ Please report any bugs on the `issue tracker
Tests
-----

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

Test data are contained in a separate `html5lib-tests
<https://github.com/html5lib/html5lib-tests>`_ repository and included
Expand Down
2 changes: 1 addition & 1 deletion html5lib/tests/support.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def convertData(data):
def errorMessage(input, expected, actual):
msg = ("Input:\n%s\nExpected:\n%s\nRecieved\n%s\n" %
(repr(input), repr(expected), repr(actual)))
if sys.version_info.major == 2:
if sys.version_info[0] == 2:
msg = msg.encode("ascii", "backslashreplace")
return msg

Expand Down
41 changes: 41 additions & 0 deletions html5lib/tests/test_meta.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
from __future__ import absolute_import, division, unicode_literals

import six
from mock import Mock

from . import support


def _createReprMock(r):
"""Creates a mock with a __repr__ returning r
Also provides __str__ mock with default mock behaviour"""
mock = Mock()
mock.__repr__ = Mock()
mock.__repr__.return_value = r
mock.__str__ = Mock(wraps=mock.__str__)
return mock


def test_errorMessage():
# Create mock objects to take repr of
input = _createReprMock("1")
expected = _createReprMock("2")
actual = _createReprMock("3")

# Run the actual test
r = support.errorMessage(input, expected, actual)

# Assertions!
if six.PY2:
assert b"Input:\n1\nExpected:\n2\nRecieved\n3\n" == r
else:
assert six.PY3
assert "Input:\n1\nExpected:\n2\nRecieved\n3\n" == r

assert input.__repr__.call_count == 1
assert expected.__repr__.call_count == 1
assert actual.__repr__.call_count == 1
assert not input.__str__.called
assert not expected.__str__.called
assert not actual.__str__.called
2 changes: 1 addition & 1 deletion html5lib/treebuilders/etree_lxml.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def serializeElement(element, indent=0):
next_element = next_element.getnext()
elif isinstance(element, str) or isinstance(element, bytes):
# Text in a fragment
assert isinstance(element, str) or sys.version_info.major == 2
assert isinstance(element, str) or sys.version_info[0] == 2
rv.append("|%s\"%s\"" % (' ' * indent, element))
else:
# Fragment case
Expand Down
1 change: 1 addition & 0 deletions requirements-test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
flake8
nose
ordereddict # Python 2.6
mock
3 changes: 3 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ deps =
-r{toxinidir}/requirements-optional-cpython.txt
flake8
nose
mock
commands =
{envbindir}/nosetests -q
{toxinidir}/flake8-run.sh
Expand All @@ -21,10 +22,12 @@ deps =
Genshi
nose
six
mock

[testenv:py26]
basepython = python2.6
deps =
-r{toxinidir}/requirements-optional-2.6.txt
flake8
nose
mock

0 comments on commit d9b1a9f

Please sign in to comment.