Skip to content
Permalink
Browse files

fix: syntax error in generated code using enumerations.

Fixes #117.
  • Loading branch information...
pope1ni committed Aug 28, 2018
1 parent 0eed4dc commit 4a86c94394a3bb58c514073571c4f75d0a2e4b1b
Showing with 29 additions and 1 deletion.
  1. +1 −1 soapfish/templates/lib.jinja2
  2. +17 −0 tests/assets/generation/enumeration2.xsd
  3. +11 −0 tests/generation/code_test.py
@@ -146,7 +146,7 @@ class {{ class_name|capitalize }}(xsd.ComplexType):
{%- if element.simpleType %}
{{ element.name|fix_keyword }} = xsd.Element({{ element.simpleType.restriction|type(known_types) }}(
{%- if element.simpleType.restriction.enumerations -%}
enumeration=[{% for enum in element.simpleType.restriction.enumerations %}'{{ enum.value }}'{% if not loop.last %}, {% endif %}{% endfor %}]
enumeration=[{% for enum in element.simpleType.restriction.enumerations %}'{{ enum.value }}'{% if not loop.last %}, {% endif %}{% endfor %}],
{%- endif %}
{%- if element.name in keywords %}tagname='{{ element.name }}',{% endif %}
{%- if element.simpleType.restriction.minInclusive %}minInclusive={{ element.simpleType.restriction.minInclusive.value }},{% endif %}
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" targetNamespace="http://example.com">
<xsd:complexType name="ComplexType">
<xsd:sequence>
<xsd:element name="Grade">
<xsd:simpleType>
<xsd:restriction base="xsd:string">
<xsd:enumeration value="A"/>
<xsd:enumeration value="B"/>
<xsd:enumeration value="C"/>
<xsd:length value="1"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
@@ -89,6 +89,17 @@ def test_schema_xsd_include(self):
code = code.decode()
assert_contains('Schema1_Element', code)

def test_schema_xsd_enumeration(self):
xml = utils.open_document('tests/assets/generation/enumeration2.xsd')
code = xsd2py.generate_code_from_xsd(xml)
if six.PY3:
code = code.decode()
m = {}
try:
self._exec(code, m)
except SyntaxError as e:
self.fail('%s: %s' % (e.__class__.__name__, e))

def test_schema_xsd_restriction(self):
xml = utils.open_document('tests/assets/generation/restriction.xsd')
code = xsd2py.generate_code_from_xsd(xml)

0 comments on commit 4a86c94

Please sign in to comment.
You can’t perform that action at this time.