def test_with_ns(self): body = self._get_ns_body() real = xml_to_string(body) expected = u''' до текст <tag1 {s.ns_attrib}>content</tag1> между текст <tag2 {s.ns_attrib}>содержание</tag2> <tag3 {s.ns_attrib}> <subtag>a</subtag> <subtag>b</subtag> <!-- comment --> <script type="text/javascript"> var f = (function(a) {{ return function(b) {{ alert(a + b); }}; }})(5); f(10); var str = '<div>' + '10' + 55 + '<div><h1>Hello</h1></div>' + '</div>'; f(str); </script> <div class="foo"> <a href="http://ru.ru" data-qa="test">Click me!</a> </div> </tag3> <tag4 {s.ns_attrib}/> после текст <{s.ns_id}:tagWithNs {s.ns_attrib}>abc</{s.ns_id}:tagWithNs>'''.format(s=self) self._assert_strings(real, expected)
def test_without_ns(self): body = etree.fromstring(self.sample_xml).find('body'.format(s=self)) self.assertEqual(body.tag, 'body') real = xml_to_string(body) self._assert_strings(real, self.content) self.assertEqual(xml_to_string(body, clean_xmlns=True), real)
def test_html(self): body = etree.fromstring(self.sample_html_as_xml).find('body'.format(s=self)) real = xml_to_string(body, clean_xmlns=True, method="html") self._assert_strings(real, self.result_html)
def test_clean_ns(self): body = self._get_ns_body() real = xml_to_string(body, clean_xmlns=True) self._assert_strings(real, self.content + u'\n<tagWithNs>abc</tagWithNs>')