def test_load_after_parsestring(self): # lxml 2.2.7 (used internally by xmlmap) has a bug that causes # lxml.etree.parse() to fail after a call to # lxml.etree.fromstring(). this causes the second call below to fail # unless we work around that bug in xmlmap. xmlmap.parseString('<foo/>') # has global side effects in lxml xmlmap.loadSchema('http://www.w3.org/2001/xml.xsd') # fails
def setUp(self): # parseString wants a url. let's give it a proper one. url = '%s#%s.%s' % (__file__, self.__class__.__name__, 'FIXTURE_TEXT') self.fixture = xmlmap.parseString(self.FIXTURE_TEXT, url) self.obj = ListTestObject(self.fixture)
def testTextNode(self): # special case for text() class TextObject(xmlmap.XmlObject): text_node = xmlmap.StringField('text()') nested_text = xmlmap.StringField('nest[@type="feather"]/text()') missing_text = xmlmap.StringField('missing[@type="foo"]/text()') # parseString wants a url. let's give it a proper one. url = '%s#%s.%s' % (__file__, self.__class__.__name__, 'TEXT_XML_FIXTURES') xml = '''<text>some text<nest type='feather'>robin</nest></text>''' obj = TextObject(xmlmap.parseString(xml, url)) self.assertEqual('some text', obj.text_node) # set text node obj.text_node = 'la' self.assertEqual('la', obj.node.xpath('string(text())')) self.assertEqual('la', obj.text_node) # set to empty string obj.text_node = '' self.assertEqual('', obj.node.xpath('string(text())')) self.assertEqual('', obj.text_node) # set to value then set to None - text should be cleared out obj.text_node = 'la' obj.text_node = None self.assertEqual('', obj.node.xpath('string(text())')) self.assertEqual('', obj.text_node) self.assertEqual('robin', obj.nested_text) # create parent of a text node obj.missing_text = 'tra' self.assertEqual('tra', obj.node.xpath('string(missing/text())')) self.assertEqual('tra', obj.missing_text)