Commit a738d529 authored by Denis Laxalde's avatar Denis Laxalde
Browse files

[py3] Properly handle when comparing XML in check_xsd_profile test method

We use io.open() to consistently open files in text mode in both python2
and python3 (we use text mode because we need to .format() the read
string, which is only possible with text on python3). Accordingly, we
set encoding=text_type when dumping XML to string, in order to produce a
unicode string.
parent fe168e4a546b
......@@ -19,6 +19,7 @@ You may want to set the TEST_WRITE_SEDA_FILES environment variable to activate
writing of generated content back to the file-system.
"""
import io
from doctest import Example
from itertools import chain, repeat
import os
......@@ -106,13 +107,13 @@ class XmlTestMixin(object):
"""Check that the SEDA profile can be used to validate a sample XML document."""
if os.environ.get('TEST_WRITE_SEDA_FILES'):
fname = join('/tmp', basename(sample_file))
with open(fname, 'w') as stream:
stream.write(etree.tostring(root, pretty_print=True))
with io.open(fname, 'w') as stream:
stream.write(etree.tostring(root, encoding=text_type, pretty_print=True))
print('Generated profile saved to {}'.format(fname))
profile = self.schema_class(root)
with open(sample_file) as f:
with io.open(sample_file) as f:
sample_xml_string = f.read().format(**substitutions)
profile.assert_(etree.fromstring(sample_xml_string))
profile.assert_(etree.fromstring(sample_xml_string.encode('utf-8')))
class XMLSchemaTestMixin(XmlTestMixin):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment