def testContainerAssignment (self): i = xs.string(self.body, _element=anything) instance = container() instance.anything = i explicit_xml = instance.toxml("utf-8") instance.anything = xs.string(self.body) implicit_xml = instance.toxml("utf-8") self.assertEqual(explicit_xml, implicit_xml) instance.anything = xs.int(43) self.assertTrue(isinstance(instance.anything, xs.int)) int_xml = instance.toxml("utf-8") instance.anything = self.body self.assertTrue(isinstance(instance.anything, xs.anyType)) oc = instance.anything.orderedContent() self.assertEqual(1, len(oc)) self.assertTrue(isinstance(oc[0], pyxb.binding.basis.NonElementContent)) xmlt = six.u('<container><anything>something</anything></container>') xmld = xmlt.encode('utf-8') self.assertEqual(xmld, instance.toxml('utf-8', root_only=True)) instance.anything = 43 self.assertTrue(isinstance(instance.anything, xs.anyType)) oc = instance.anything.orderedContent() self.assertEqual(1, len(oc)) self.assertTrue(isinstance(oc[0], pyxb.binding.basis.NonElementContent)) xmlt = six.u('<container><anything>43</anything></container>') xmld = xmlt.encode('utf-8') self.assertEqual(xmld, instance.toxml('utf-8', root_only=True))
def testContainerAssignment(self): i = xs.string(self.body, _element=anything) instance = container() instance.anything = i explicit_xml = instance.toxml("utf-8") instance.anything = xs.string(self.body) implicit_xml = instance.toxml("utf-8") self.assertEqual(explicit_xml, implicit_xml) instance.anything = xs.int(43) self.assertTrue(isinstance(instance.anything, xs.int)) int_xml = instance.toxml("utf-8") instance.anything = self.body self.assertTrue(isinstance(instance.anything, xs.anyType)) oc = instance.anything.orderedContent() self.assertEqual(1, len(oc)) self.assertTrue(isinstance(oc[0], pyxb.binding.basis.NonElementContent)) xmlt = six.u('<container><anything>something</anything></container>') xmld = xmlt.encode('utf-8') self.assertEqual(xmld, instance.toxml('utf-8', root_only=True)) instance.anything = 43 self.assertTrue(isinstance(instance.anything, xs.anyType)) oc = instance.anything.orderedContent() self.assertEqual(1, len(oc)) self.assertTrue(isinstance(oc[0], pyxb.binding.basis.NonElementContent)) xmlt = six.u('<container><anything>43</anything></container>') xmld = xmlt.encode('utf-8') self.assertEqual(xmld, instance.toxml('utf-8', root_only=True))
def testSchemaSupport(self): instance = trac26.eTranslateCardMulti(trac26.eConcCardCymru('un'), trac26.eConcCardEnglish('one'), xs.int(1)) self.assertTrue(instance.validateBinding()) instance.eConcCardCymru.append('dau') instance.eConcCardEnglish.append('two') instance.cardinal.append(2) self.assertTrue(instance.validateBinding())
def testElement (self): i = union(4) self.assertTrue(i.validateBinding()) i = union('two') self.assertTrue(i.validateBinding()) i = xs.int(53.42) i = union(52.43) i = listUnion([1, 3, 'one', 'two', 2]) self.assertTrue(i.validateBinding())
def testSchemaSupport (self): instance = trac26.eTranslateCardMulti(trac26.eConcCardCymru('un'), trac26.eConcCardEnglish('one'), xs.int(1)) self.assertTrue(instance.validateBinding()) instance.eConcCardCymru.append('dau') instance.eConcCardEnglish.append('two') instance.cardinal.append(2) self.assertTrue(instance.validateBinding())
def testElement(self): i = union(4) self.assertTrue(i.validateBinding()) i = union('two') self.assertTrue(i.validateBinding()) i = xs.int(53.42) i = union(52.43) i = listUnion([1, 3, 'one', 'two', 2]) self.assertTrue(i.validateBinding())
def testSchemaSupport (self): instance = trac26.eTranslateCard(trac26.eConcCardCymru('un'), trac26.eConcCardEnglish('one'), xs.int(1)) self.assertTrue(instance.validateBinding()) instance = trac26.CreateFromDocument(self.Good_xmlt) self.assertEqual(self.Good_xmld, instance.toxml('utf-8', root_only=True)) instance = trac26.eTranslateCard(trac26.eConcCardCymru('un')) instance.cardinal = 1 instance.eConcCardEnglish = 'one' self.assertTrue(instance.validateBinding())
def testCtorMixed (self): instance = Mixed() self.assertRaises(pyxb.AttributeValidationError, instance.validateBinding) instance = Mixed(units='m') self.assertTrue(instance.validateBinding()) instance = Mixed(4, units='m') self.assertTrue(instance.validateBinding()) self.assertEqual(u'4', instance.orderedContent()[0].value) instance = Mixed(xs.int(4), units='m') self.assertTrue(instance.validateBinding()) self.assertEqual(u'4', instance.orderedContent()[0].value)
def testSchemaSupport(self): instance = trac26.eTranslateCard(trac26.eConcCardCymru('un'), trac26.eConcCardEnglish('one'), xs.int(1)) self.assertTrue(instance.validateBinding()) instance = trac26.CreateFromDocument(self.Good_xmlt) self.assertEqual(self.Good_xmld, instance.toxml('utf-8', root_only=True)) instance = trac26.eTranslateCard(trac26.eConcCardCymru('un')) instance.cardinal = 1 instance.eConcCardEnglish = 'one' self.assertTrue(instance.validateBinding())
def testContainerAssignment(self): i = xs.string(self.body, _element=anything) instance = container() instance.anything = i explicit_xml = instance.toxml("utf-8") instance.anything = xs.string(self.body) implicit_xml = instance.toxml("utf-8") self.assertEqual(explicit_xml, implicit_xml) instance.anything = xs.int(43) int_xml = instance.toxml("utf-8") instance.anything = self.body # You can do that, but you won't be able to convert it to xml self.assertRaises(AttributeError, instance.toxml) instance.anything = 43 self.assertRaises(AttributeError, instance.toxml)
def testContainerAssignment (self): i = xs.string(self.body, _element=anything) instance = container() instance.anything = i explicit_xml = instance.toxml("utf-8") instance.anything = xs.string(self.body) implicit_xml = instance.toxml("utf-8") self.assertEqual(explicit_xml, implicit_xml) instance.anything = xs.int(43) int_xml = instance.toxml("utf-8") instance.anything = self.body # You can do that, but you won't be able to convert it to xml self.assertRaises(AttributeError, instance.toxml) instance.anything = 43 self.assertRaises(AttributeError, instance.toxml)
def testException(self): instance = trac26.eTranslateCardMulti(trac26.eConcCardCymru('un'), trac26.eConcCardEnglish('one'), xs.int(1)) self.assertTrue(instance.validateBinding()) instance.cardinal.append(2) with self.assertRaises(pyxb.UnprocessedElementContentError) as cm: instance.validateBinding() e = cm.exception self.assertTrue(e.fac_configuration.isAccepting()) self.assertEqual(3, len(e.symbols)) self.assertEqual(1, len(e.symbol_set)) (ed, syms) = e.symbol_set.iteritems().next() self.assertEqual(1, len(syms)) self.assertEqual(instance.cardinal[1], syms[0]) self.assertEqual(e.details(), self.Bad_details)
def testException (self): instance = trac26.eTranslateCardMulti(trac26.eConcCardCymru('un'), trac26.eConcCardEnglish('one'), xs.int(1)) self.assertTrue(instance.validateBinding()) instance.cardinal.append(2) with self.assertRaises(pyxb.UnprocessedElementContentError) as cm: instance.validateBinding() e = cm.exception self.assertTrue(e.fac_configuration.isAccepting()) self.assertEqual(3, len(e.symbols)) self.assertEqual(1, len(e.symbol_set)) (ed, syms) = e.symbol_set.iteritems().next() self.assertEqual(1, len(syms)) self.assertEqual(instance.cardinal[1], syms[0]) self.assertEqual(e.details(), self.Bad_details)
def testMulti(self): instance = multi() self.assertRaises(pyxb.SimpleTypeValueError, SET_li, instance, 1) self.assertRaises(pyxb.SimpleTypeValueError, SET_li, instance, [1, 2, 3]) instance.li = [[1, 2, 3], [2, 3, 4]] self.assertEqual(2, len(instance.li)) self.assertTrue(instance.validateBinding()) self.assertEqual(1, len(instance.orderedContent())) instance = multi([1, 2, 3], [1, 2, 3]) # two li values self.assertEqual(2, len(instance.li)) self.assertTrue(instance.validateBinding()) self.assertEqual(2, len(instance.orderedContent())) # The individual lists here aren't recognized as li elements, so this becomes something unknown self.assertRaises(pyxb.MixedContentError, multi, [[1, 2, 3], [2, 3, 4]]) self.assertRaises(pyxb.SimpleTypeValueError, multi, li=[1, 2, 3]) instance = multi(li=[[1, 2, 3], [2, 3, 4]]) self.assertEqual(2, len(instance.li)) self.assertTrue(instance.validateBinding()) self.assertEqual(1, len(instance.orderedContent())) instance = multi(li=[]) instance.li.append(xs.int(1)) self.assertRaises(pyxb.SimpleTypeValueError, instance.validateBinding) instance = CreateFromDocument('<multi><li>1</li></multi>') self.assertEqual(1, len(instance.li)) self.assertTrue(instance.validateBinding()) self.assertEqual(1, len(instance.orderedContent())) instance.li = [] instance.li.append([1, 2, 3]) instance.li.append([2, 3, 4]) self.assertEqual(2, len(instance.li)) self.assertTrue(instance.validateBinding()) self.assertEqual(2, len(instance.orderedContent()))
def testMulti (self): instance = multi() self.assertRaises(pyxb.SimpleTypeValueError, SET_li, instance, 1) self.assertRaises(pyxb.SimpleTypeValueError, SET_li, instance, [1, 2, 3]) instance.li = [[1,2,3], [2,3,4]] self.assertEqual(2, len(instance.li)) self.assertTrue(instance.validateBinding()) self.assertEqual(1, len(instance.orderedContent())) instance = multi([1,2,3], [1,2,3]) # two li values self.assertEqual(2, len(instance.li)) self.assertTrue(instance.validateBinding()) self.assertEqual(2, len(instance.orderedContent())) # The individual lists here aren't recognized as li elements, so this becomes something unknown self.assertRaises(pyxb.MixedContentError, multi, [[1,2,3], [2,3,4]]) self.assertRaises(pyxb.SimpleTypeValueError, multi, li=[1,2,3]) instance = multi(li=[[1,2,3],[2,3,4]]) self.assertEqual(2, len(instance.li)) self.assertTrue(instance.validateBinding()) self.assertEqual(1, len(instance.orderedContent())) instance = multi(li=[]) instance.li.append(xs.int(1)) self.assertRaises(pyxb.SimpleTypeValueError, instance.validateBinding) instance = CreateFromDocument('<multi><li>1</li></multi>') self.assertEqual(1, len(instance.li)) self.assertTrue(instance.validateBinding()) self.assertEqual(1, len(instance.orderedContent())) instance.li = [] instance.li.append([1,2,3]) instance.li.append([2,3,4]) self.assertEqual(2, len(instance.li)) self.assertTrue(instance.validateBinding()) self.assertEqual(2, len(instance.orderedContent()))
def testMulti (self): instance = multi() self.assertRaises(pyxb.BadTypeValueError, SET_li, instance, 1) self.assertRaises(pyxb.BadTypeValueError, SET_li, instance, [1, 2, 3]) instance.li = [[1,2,3], [2,3,4]] self.assertEqual(2, len(instance.li)) self.assertTrue(instance.validateBinding()) self.assertEqual(1, len(instance.content())) instance = multi([1,2,3], [1,2,3]) # two li values self.assertEqual(2, len(instance.li)) self.assertTrue(instance.validateBinding()) self.assertEqual(2, len(instance.content())) self.assertRaises(pyxb.UnrecognizedContentError, multi, [[1,2,3], [2,3,4]]) self.assertRaises(pyxb.BadTypeValueError, multi, li=[1,2,3]) instance = multi(li=[[1,2,3],[2,3,4]]) self.assertEqual(2, len(instance.li)) self.assertTrue(instance.validateBinding()) self.assertEqual(1, len(instance.content())) instance = multi(li=[]) instance.li.append(xs.int(1)) self.assertRaises(pyxb.BindingValidationError, instance.validateBinding) instance = CreateFromDocument('<multi><li>1</li></multi>') self.assertEqual(1, len(instance.li)) self.assertTrue(instance.validateBinding()) self.assertEqual(1, len(instance.content())) instance.li = [] instance.li.append([1,2,3]) instance.li.append([2,3,4]) self.assertEqual(2, len(instance.li)) self.assertTrue(instance.validateBinding()) self.assertEqual(2, len(instance.content()))
def testInt (self): self.assertEqual(0, xs.int()); self.assertEqual(0, CreateFromDocument(six.u('<int>0</int>'))); self.assertRaises(SimpleTypeValueError, CreateFromDocument, six.u('<int/>'));
def testInt(self): self.assertEqual(0, xs.int()) self.assertEqual(0, CreateFromDocument(six.u('<int>0</int>'))) self.assertRaises(SimpleTypeValueError, CreateFromDocument, six.u('<int/>'))