Commit 4b339115 authored by Denis Laxalde's avatar Denis Laxalde
Browse files

[py3] Manipulate unicode strings in _test_profile()

This is to fix SEDA exports tests on python3.

We first dump XML documents as unicode using the _encoding argument
introduced in previous changeset. Accordingly, expected files are
changed to remove the XML declaration because dumped values will not
contain them.

Then we open files in text mode (using io.open() for consistency between
python2 and python3) and do string formatting using unicode values.
(Especially, six.binary_type(<some integer>) produces different values
in python2 and python3, and we actually want to stringify the integer --
the eid value.)
parent 63e2c0ef1a8e
<?xml version='1.0' encoding='utf-8' standalone='no'?>
<rng:grammar
xmlns:a="http://relaxng.org/ns/compatibility/annotations/1.0"
xmlns:clmDAFFileTypeCode="urn:un:unece:uncefact:codelist:draft:DAF:fileTypeCode:2009-08-18"
......
<?xml version='1.0' encoding='utf-8' standalone='no'?>
<xsd:schema
xmlns:clm60133="urn:un:unece:uncefact:codelist:standard:6:0133:40106"
xmlns:clmDAFFileTypeCode="urn:un:unece:uncefact:codelist:draft:DAF:fileTypeCode:2009-08-18"
......
<?xml version='1.0' encoding='utf-8' standalone='no'?>
<rng:grammar
xmlns:a="http://relaxng.org/ns/compatibility/annotations/1.0"
xmlns:clm60133="urn:un:unece:uncefact:codelist:standard:6:0133:40106"
......
<?xml version='1.0' encoding='utf-8' standalone='no'?>
<xsd:schema
xmlns:clm60133="urn:un:unece:uncefact:codelist:standard:6:0133:40106"
xmlns:clmDAFFileTypeCode="urn:un:unece:uncefact:codelist:draft:DAF:fileTypeCode:2009-08-18"
......
......@@ -26,7 +26,7 @@ import os
from os.path import basename, join
import unittest
from six import binary_type, text_type
from six import text_type
from six.moves import zip
from lxml import etree
......@@ -917,7 +917,7 @@ class OldSEDAExportMixin(object):
agent = cnx.entity_from_eid(self.agent_eid)
adapter = transfer.cw_adapt_to(adapter_id)
generated_xsd = adapter.dump()
generated_xsd = adapter.dump(_encoding=text_type)
if os.environ.get('TEST_WRITE_SEDA_FILES'):
orig_content = generated_xsd
......@@ -926,24 +926,24 @@ class OldSEDAExportMixin(object):
(text_type(agent.eid), 'agent-id'),
(agent.dc_title(), 'agent-name')]:
orig_content = orig_content.replace(value, '%({})s'.format(key))
with open(self.datapath(expected_file + '.new'), 'w') as stream:
with io.open(self.datapath(expected_file + '.new'), 'w') as stream:
stream.write(orig_content)
print('Regenerated expected file as {}.new'.format(expected_file))
root = etree.fromstring(generated_xsd)
root = etree.fromstring(generated_xsd.encode('utf-8'))
self.assertXmlValid(root)
with open(self.datapath(expected_file)) as f:
with io.open(self.datapath(expected_file), 'r') as f:
expected = f.read() % {
'unit-eid': binary_type(self.unit_eid),
'subunit1-eid': binary_type(self.subunit1_eid),
'subunit2-eid': binary_type(self.subunit2_eid),
'bdo-eid': binary_type(self.bdo_eid),
'kw-eid': binary_type(self.kw_eid),
'chi-eid': binary_type(self.chi_eid),
'concept-uri': binary_type(file_concept.cwuri),
'scheme-uri': binary_type(file_concept.scheme.cwuri),
'agent-id': binary_type(agent.eid),
'agent-name': binary_type(agent.dc_title()),
'unit-eid': text_type(self.unit_eid),
'subunit1-eid': text_type(self.subunit1_eid),
'subunit2-eid': text_type(self.subunit2_eid),
'bdo-eid': text_type(self.bdo_eid),
'kw-eid': text_type(self.kw_eid),
'chi-eid': text_type(self.chi_eid),
'concept-uri': file_concept.cwuri,
'scheme-uri': file_concept.scheme.cwuri,
'agent-id': text_type(agent.eid),
'agent-name': agent.dc_title(),
}
self.assertXmlEqual(expected, generated_xsd)
return adapter, root
......
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