Commit 677d664f authored by Denis Laxalde's avatar Denis Laxalde
Browse files

[py3] Adjust xsd2yams code and tests

* Use io.BytesIO instead of StringIO.StringIO.
* Explicitly encode strings before writing to stream.
* Decode results before string comparisons in tests.
parent 56b3e27c5127
...@@ -515,7 +515,7 @@ class CodeGenerator(object): ...@@ -515,7 +515,7 @@ class CodeGenerator(object):
"""Generator entry point: write generated code for :class:`XSYMapping` into the given stream """Generator entry point: write generated code for :class:`XSYMapping` into the given stream
""" """
if with_header: if with_header:
stream.write(_PY_HEADER) stream.write(_PY_HEADER.encode('utf-8'))
self._generate(mapping, stream) self._generate(mapping, stream)
def _generate(self, mapping, stream): def _generate(self, mapping, stream):
...@@ -538,7 +538,7 @@ class YamsSchemaGenerator(CodeGenerator): ...@@ -538,7 +538,7 @@ class YamsSchemaGenerator(CodeGenerator):
"""Yams schema generator""" """Yams schema generator"""
def _generate(self, mapping, stream): def _generate(self, mapping, stream):
stream.write('''from yams.buildobjs import EntityType, RelationDefinition stream.write(b'''from yams.buildobjs import EntityType, RelationDefinition
from yams.buildobjs import String, Boolean from yams.buildobjs import String, Boolean
from cubicweb.schema import RQLConstraint from cubicweb.schema import RQLConstraint
from cubicweb_seda.schema import seda_profile_element from cubicweb_seda.schema import seda_profile_element
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
# You should have received a copy of the GNU Lesser General Public License along # You should have received a copy of the GNU Lesser General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>. # with this program. If not, see <http://www.gnu.org/licenses/>.
from StringIO import StringIO from io import BytesIO
try: try:
import unittest2 as unittest import unittest2 as unittest
except ImportError: except ImportError:
...@@ -43,9 +43,9 @@ class CodeGenerationTC(unittest.TestCase): ...@@ -43,9 +43,9 @@ class CodeGenerationTC(unittest.TestCase):
def test_base(self): def test_base(self):
mapping = xsy_mapping('DataObjectPackage') mapping = xsy_mapping('DataObjectPackage')
stream = StringIO() stream = BytesIO()
YamsSchemaGenerator().generate(mapping, stream) YamsSchemaGenerator().generate(mapping, stream)
code = stream.getvalue() code = stream.getvalue().decode('utf-8')
# assert this is valid python # assert this is valid python
compile(code, '<generated schema>', mode='exec') compile(code, '<generated schema>', mode='exec')
# assert there is no duplicated classes # assert there is no duplicated classes
......
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