Ensure iteration on XSMapping yield elements according to order in the XSD
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Thu, 13 Oct 2016 12:49:48 +0200
changeset 1784 a77fc051bb8a
parent 1783 c29eea525d9e
child 1833 8112742e0b48
Ensure iteration on XSMapping yield elements according to order in the XSD elements should be treaten FIFO.
test/test_xsd2yams.py
xsd.py
--- a/test/test_xsd2yams.py	Thu Oct 13 12:46:57 2016 +0200
+++ b/test/test_xsd2yams.py	Thu Oct 13 12:49:48 2016 +0200
@@ -130,6 +130,48 @@
             ]))
         self.assertRaises(StopIteration, next, element_defs)
 
+    def test_rule(self):
+        element_defs = iter(XSDMMapping('AppraisalRule'))
+        edef = next(element_defs)
+        self.assertEqual(
+            readable_edef(edef),
+            ('AppraisalRule', 'SEDAAppraisalRule', [
+                ('Sequence',
+                 [('seda_seq_appraisal_rule_rule', 'subject', 'SEDASeqAppraisalRuleRule')]),
+                ('Alternative',
+                 [('seda_alt_appraisal_rule_prevent_inheritance',
+                   'subject',
+                   'SEDAAltAppraisalRulePreventInheritance')]),
+                ('FinalAction', [('seda_final_action', 'subject', 'Concept')]),
+            ]))
+        edef = next(element_defs)
+        self.assertEqual(
+            readable_edef(edef),
+            ('Sequence', 'SEDASeqAppraisalRuleRule', [
+                ('Rule', [('seda_rule', 'subject', 'Concept')]),
+                ('StartDate',
+                 [('seda_start_date', 'object', 'SEDAStartDate'),
+                  ('start_date', 'subject', 'Date')])]))
+        edef = next(element_defs)
+        self.assertEqual(
+            readable_edef(edef),
+            ('Alternative', 'SEDAAltAppraisalRulePreventInheritance', [
+                ('PreventInheritance',
+                 [('seda_prevent_inheritance', 'object', 'SEDAPreventInheritance'),
+                  ('prevent_inheritance', 'subject', 'Boolean')]),
+                ('RefNonRuleId',
+                 [('seda_ref_non_rule_id_from', 'object', 'SEDARefNonRuleId'),
+                  ('seda_ref_non_rule_id_to', 'subject', 'Concept')])]))
+        edef = next(element_defs)
+        self.assertEqual(
+            readable_edef(edef),
+            ('StartDate', 'SEDAStartDate', []))
+        edef = next(element_defs)
+        self.assertEqual(
+            readable_edef(edef),
+            ('PreventInheritance', 'SEDAPreventInheritance', []))
+        self.assertRaises(StopIteration, next, element_defs)
+
     def test_binarydataobject(self):
         element_defs = XSDMMapping('BinaryDataObject')
         edef = next(iter(element_defs))
--- a/xsd.py	Thu Oct 13 12:46:57 2016 +0200
+++ b/xsd.py	Thu Oct 13 12:49:48 2016 +0200
@@ -414,7 +414,7 @@
 
     _push(xselement, etype_name(xselement))
     while _stack:
-        parent, parent_etype, child_defs = _stack.pop()
+        parent, parent_etype, child_defs = _stack.pop(0)
         if child_defs is None:
             child_defs = []
             skip = False