Permalink
Browse files

Merge branch 'release-1.8' into mainline

Include fixes from #52
  • Loading branch information...
2 parents 6d8389a + c3bb826 commit d64f09f94c54ba1e7d529b07675af8c7c7747a13 @offbyone offbyone committed Apr 10, 2015
View
@@ -1,2 +1,2 @@
[pytest]
-addopts = --cov hamcrest --cov-report term-missing
+addopts = --cov hamcrest --cov-report term-missing --no-cov-on-fail
@@ -25,7 +25,7 @@ def append_description_of(self, value):
value.describe_to(self)
elif six.PY3 and isinstance(value, six.text_type):
self.append(repr(value))
- elif isinstance(value, six.binary_type):
+ elif six.PY2 and isinstance(value, six.binary_type):
self.append_string_in_python_syntax(value)
elif isinstance(value, six.text_type):
self.append_string_in_python_syntax(value)
@@ -1,4 +1,8 @@
from __future__ import absolute_import
+
+import codecs
+import six
+
from .base_description import BaseDescription
__author__ = "Jon Reid"
@@ -31,4 +35,4 @@ def __str__(self):
return self.out
def append(self, string):
- self.out += string
+ self.out += six.text_type(string)
@@ -0,0 +1,56 @@
+# coding: utf-8
+import six
+import pytest
+from mock import sentinel, patch
+
+from hamcrest.core.base_description import BaseDescription
+from hamcrest.core.selfdescribing import SelfDescribing
+
+__author__ = "Chris Rose"
+__copyright__ = "Copyright 2015 hamcrest.org"
+__license__ = "BSD, see License.txt"
+
+
+class Collector(BaseDescription):
+ def __init__(self):
+ self.appended = []
+
+ def append(self, obj):
+ self.appended.append(obj)
+
+class Described(SelfDescribing):
+ def describe_to(self, desc):
+ desc.append('described')
+
+
+@pytest.fixture
+def desc():
+ return Collector()
+
+def test_append_text_delegates(desc):
+ desc.append_text(sentinel.Text)
+ assert desc.appended == [sentinel.Text]
+
+
+@pytest.mark.parametrize('described, appended', (
+ (Described(), 'described'),
+ pytest.mark.skipif(six.PY3, reason="py2 only")((six.u('unicode-py2'), "'unicode-py2'")),
+ pytest.mark.skipif(six.PY3, reason="py2 only")((six.b('bytes-py2'), "'bytes-py2'")),
+ pytest.mark.skipif(six.PY2, reason="py3 only")((six.u('unicode-py3'), "'unicode-py3'")),
+ pytest.mark.skipif(six.PY2, reason="py3 only")((six.b('bytes-py3'), "<b'bytes-py3'>")),
+ (six.u("\U0001F4A9"), six.u("'{0}'").format(six.u("\U0001F4A9"))),
+))
+def test_append_description_types(desc, described, appended):
+ desc.append_description_of(described)
+ assert ''.join(desc.appended) == appended
+
+
+@pytest.mark.parametrize("char, rep", (
+ ("'", r"'"),
+ ("\n", r"\n"),
+ ("\r", r"\r"),
+ ("\t", r"\t"),
+))
+def test_string_in_python_syntax(desc, char, rep):
+ desc.append_string_in_python_syntax(char)
+ assert ''.join(desc.appended) == "'{0}'".format(rep)
@@ -7,6 +7,8 @@
from hamcrest_unit_test.matcher_test import MatcherTest
import unittest
+import pytest
+import six
__author__ = "Jon Reid"
__copyright__ = "Copyright 2011 hamcrest.org"
@@ -52,6 +54,20 @@ def testMismatchDescriptionShowsActualArgument(self):
def testDescribeMismatch(self):
self.assert_describe_mismatch("was 'bad'", equal_to('good'), 'bad')
+ def testEqualToWithEqualBytes(self):
+ self.assert_matches("equal for b", equal_to(six.b('a')), six.b('a'))
+
+ def testNotEqualToWithEqualBytes(self):
+ self.assert_does_not_match("equal for b", equal_to(six.b('a')), six.b('b'))
+
+ @pytest.mark.skipif(six.PY2, reason="Py3 formatting")
+ def testByteInequalityDescriptionPy3(self):
+ self.assert_mismatch_description("was <{0!r}>".format(six.b('b')), equal_to(six.b('a')), six.b('b'))
+
+ @pytest.mark.skipif(six.PY3, reason="Py2 formatting")
+ def testByteInequalityDescriptionPy2(self):
+ self.assert_mismatch_description("was {0!r}".format(six.b('b')), equal_to(six.b('a')), six.b('b'))
+
if __name__ == '__main__':
unittest.main()
@@ -3,6 +3,7 @@
from hamcrest.core.selfdescribing import SelfDescribing
import re
+import pytest
try:
import unittest2 as unittest
except ImportError:
@@ -51,5 +52,14 @@ def testDescribeUnicodeStringAsUnicode(self):
self.description.append_description_of(six.u('\u05d0'))
self.assertEqual(six.u("'\u05d0'"), str(self.description))
+
+# below is a set of things that should append without error to string
+# descriptions
+@pytest.mark.parametrize('valid_input', ('native', six.b('bytes'), six.u('unicode')))
+def test_description_append_valid_input(valid_input):
+ desc = StringDescription()
+ desc.append(valid_input)
+ str(desc)
+
if __name__ == "__main__":
unittest.main()
View
@@ -8,6 +8,7 @@ envlist = py26,py27,py32,py33,py34,pypy,docs-py3
commands = {envbindir}/py.test []
{envpython} tests/object_import.py
deps = pytest
+ mock
pytest-cov
[testenv:py26]

0 comments on commit d64f09f

Please sign in to comment.