From 19dda6d891a96215aa21c09994526e9b7d61399d Mon Sep 17 00:00:00 2001 From: David Stanek Date: Thu, 26 Jun 2014 05:49:53 +0000 Subject: [PATCH] Fixes test_exceptions.py for Python3 - XML is parsed as bytes - The XML returned from to_string is decoded from a byte string to a text string for the comparison. - Exception.message no longer exists in Python 3 bp python3 Change-Id: I3305433e52c0def422d9f04a4d9f04c6f017d10e --- keystone/tests/matchers.py | 6 +++--- keystone/tests/test_exception.py | 8 ++++---- keystone/tests/test_matchers.py | 6 +++--- tox.ini | 1 + 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/keystone/tests/matchers.py b/keystone/tests/matchers.py index f904d339cb..1b928c0c9a 100644 --- a/keystone/tests/matchers.py +++ b/keystone/tests/matchers.py @@ -12,7 +12,7 @@ # License for the specific language governing permissions and limitations # under the License. -import six +import io from lxml import etree from testtools import matchers @@ -35,13 +35,13 @@ class XMLEquals(object): def canonical_xml(s): s = s.strip() - fp = six.StringIO() + fp = io.BytesIO() dom = etree.fromstring(s, parser) dom.getroottree().write_c14n(fp) s = fp.getvalue() dom = etree.fromstring(s, parser) - return etree.tostring(dom, pretty_print=True) + return etree.tostring(dom, pretty_print=True).decode('utf-8') expected = canonical_xml(self.expected) other = canonical_xml(other) diff --git a/keystone/tests/test_exception.py b/keystone/tests/test_exception.py index 3a64578da2..a7cb7c3e3b 100644 --- a/keystone/tests/test_exception.py +++ b/keystone/tests/test_exception.py @@ -89,15 +89,15 @@ class ExceptionTestCase(tests.TestCase): e = exception.ValidationError(attribute='xx', target='Long \xe2\x80\x93 Dash') - self.assertIn(u'\u2013', e.message) + self.assertIn(u'\u2013', six.text_type(e)) def test_invalid_unicode_string(self): # NOTE(jamielennox): This is a complete failure case so what is - # returned in the e.message is not that important so long as there is - # an error with a message + # returned in the exception message is not that important so long + # as there is an error with a message e = exception.ValidationError(attribute='xx', target='\xe7a va') - self.assertIn('%(attribute)', e.message) + self.assertIn('%(attribute)', six.text_type(e)) class UnexpectedExceptionTestCase(ExceptionTestCase): diff --git a/keystone/tests/test_matchers.py b/keystone/tests/test_matchers.py index 092fa83147..d4215f1cea 100644 --- a/keystone/tests/test_matchers.py +++ b/keystone/tests/test_matchers.py @@ -21,19 +21,19 @@ from keystone.tests import matchers class TestXMLEquals(tests.BaseTestCase, helpers.TestMatchersInterface): - matches_xml = """ + matches_xml = b""" """ - equivalent_xml = """ + equivalent_xml = b""" """ - mismatches_xml = """ + mismatches_xml = b""" diff --git a/tox.ini b/tox.ini index 7e314a252b..b0bffac9e1 100644 --- a/tox.ini +++ b/tox.ini @@ -27,6 +27,7 @@ commands = keystone/tests/test_driver_hints.py \ keystone/tests/test_hacking_checks.py \ keystone/tests/test_injection.py \ + keystone/tests/test_matchers.py \ keystone/tests/test_policy.py \ keystone/tests/test_s3_token_middleware.py \ keystone/tests/test_singular_plural.py \