Ejemplo n.º 1
0
    def test_combine_xml(self):
        docs = [
            XMLFeatureInfoDoc("<root><a>foo</a></root>"),
            XMLFeatureInfoDoc("<root><b>bar</b></root>"),
        ]
        result, infotype = combine_docs(docs, None)

        assert b"""<root><a>foo</a><b>bar</b></root>""" == result
        assert infotype == "xml"
Ejemplo n.º 2
0
    def test_combine(self):
        docs = [
            XMLFeatureInfoDoc(b'<root><a>foo</a></root>'),
            XMLFeatureInfoDoc(b'<root><b>bar</b></root>'),
            XMLFeatureInfoDoc(b'<other_root><a>baz</a></other_root>'),
        ]
        result = XMLFeatureInfoDoc.combine(docs)

        eq_(b'<root><a>foo</a></root>\n<root><b>bar</b></root>\n<other_root><a>baz</a></other_root>',
            result.as_string())
        eq_(result.info_type, 'text')
Ejemplo n.º 3
0
    def test_combine(self):
        docs = [
            XMLFeatureInfoDoc("<root><a>foo</a></root>"),
            XMLFeatureInfoDoc("<root><b>bar</b></root>"),
            XMLFeatureInfoDoc("<other_root><a>baz</a></other_root>"),
        ]
        result = XMLFeatureInfoDoc.combine(docs)

        assert strip_whitespace(result.as_string()) == strip_whitespace(
            b"<root><a>foo</a><b>bar</b><a>baz</a></root>")
        assert result.info_type == "xml"
Ejemplo n.º 4
0
    def test_combine(self):
        docs = [
            XMLFeatureInfoDoc('<root><a>foo</a></root>'),
            XMLFeatureInfoDoc('<root><b>bar</b></root>'),
            XMLFeatureInfoDoc('<other_root><a>baz</a></other_root>'),
        ]
        result = XMLFeatureInfoDoc.combine(docs)

        eq_(strip_whitespace(result.as_string()),
            strip_whitespace(b'<root><a>foo</a><b>bar</b><a>baz</a></root>'))
        eq_(result.info_type, 'xml')
Ejemplo n.º 5
0
    def test_combine(self):
        docs = [
            XMLFeatureInfoDoc(b"<root><a>foo</a></root>"),
            XMLFeatureInfoDoc(b"<root><b>bar</b></root>"),
            XMLFeatureInfoDoc(b"<other_root><a>baz</a></other_root>"),
        ]
        result = XMLFeatureInfoDoc.combine(docs)

        assert (
            b"<root><a>foo</a></root>\n<root><b>bar</b></root>\n<other_root><a>baz</a></other_root>"
            == result.as_string())
        assert result.info_type == "text"
Ejemplo n.º 6
0
 def test_multiple(self):
     t = XSLTransformer(self.xsl_script)
     doc = t.transform(XMLFeatureInfoDoc.combine([
         XMLFeatureInfoDoc(x) for x in
             [b'<a><b>ab</b></a>',
              b'<a><b>ab1</b><b>ab2</b><b>ab3</b></a>',
              b'<a><b>ab1</b><c>ac</c><b>ab2</b></a>',
         ]]))
     eq_(strip_whitespace(doc.as_string()),
         strip_whitespace(b'''
         <root>
           <foo>ab</foo>
           <foo>ab1</foo><foo>ab2</foo><foo>ab3</foo>
           <foo>ab1</foo><foo>ab2</foo>
         </root>'''))
     eq_(doc.info_type, 'xml')
Ejemplo n.º 7
0
 def test_multiple(self):
     t = XSLTransformer(self.xsl_script)
     doc = t.transform(
         XMLFeatureInfoDoc.combine([
             XMLFeatureInfoDoc(x) for x in [
                 b"<a><b>ab</b></a>",
                 b"<a><b>ab1</b><b>ab2</b><b>ab3</b></a>",
                 b"<a><b>ab1</b><c>ac</c><b>ab2</b></a>",
             ]
         ]))
     assert strip_whitespace(doc.as_string()) == strip_whitespace(b"""
         <root>
           <foo>ab</foo>
           <foo>ab1</foo><foo>ab2</foo><foo>ab3</foo>
           <foo>ab1</foo><foo>ab2</foo>
         </root>""")
     assert doc.info_type == "xml"
Ejemplo n.º 8
0
    def test_combine(self):
        docs = [
            XMLFeatureInfoDoc('<root><a>foo</a></root>'),
            XMLFeatureInfoDoc('<root><b>bar</b></root>'),
            XMLFeatureInfoDoc('<other_root><a>baz</a></other_root>'),
        ]
        result = XMLFeatureInfoDoc.combine(docs)

        eq_(strip_whitespace(result.as_string()),
            strip_whitespace(b'<root><a>foo</a><b>bar</b><a>baz</a></root>'))
        eq_(result.info_type, 'xml')
Ejemplo n.º 9
0
    def test_combine(self):
        docs = [
            XMLFeatureInfoDoc(b'<root><a>foo</a></root>'),
            XMLFeatureInfoDoc(b'<root><b>bar</b></root>'),
            XMLFeatureInfoDoc(b'<other_root><a>baz</a></other_root>'),
        ]
        result = XMLFeatureInfoDoc.combine(docs)

        eq_(b'<root><a>foo</a></root>\n<root><b>bar</b></root>\n<other_root><a>baz</a></other_root>',
            result.as_string())
        eq_(result.info_type, 'text')
Ejemplo n.º 10
0
    def test_combine_transform_xml(self, tmpdir):
        xsl = tmpdir.join("transform.xsl")
        xsl.write("""<xsl:stylesheet version="1.0"
         xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
         <xsl:template match="/">
            <root>
                <xsl:apply-templates select='/a/b'/>
            </root>
         </xsl:template>
         <xsl:template match="/a/b">
             <foo><xsl:value-of select="text()" /></foo>
         </xsl:template>
        </xsl:stylesheet>
        """)
        transf = XSLTransformer(xsl.strpath)
        docs = [
            XMLFeatureInfoDoc("<a><b>foo1</b></a>"),
            XMLFeatureInfoDoc("<a><b>foo2</b></a>"),
        ]
        result, infotype = combine_docs(docs, transf)

        assert b"""<root><foo>foo1</foo><foo>foo2</foo></root>""" == result
        assert infotype is None
Ejemplo n.º 11
0
 def test_multiple(self):
     t = XSLTransformer(self.xsl_script)
     doc = t.transform(XMLFeatureInfoDoc.combine([
         XMLFeatureInfoDoc(x) for x in
             [b'<a><b>ab</b></a>',
              b'<a><b>ab1</b><b>ab2</b><b>ab3</b></a>',
              b'<a><b>ab1</b><c>ac</c><b>ab2</b></a>',
         ]]))
     eq_(strip_whitespace(doc.as_string()),
         strip_whitespace(b'''
         <root>
           <foo>ab</foo>
           <foo>ab1</foo><foo>ab2</foo><foo>ab3</foo>
           <foo>ab1</foo><foo>ab2</foo>
         </root>'''))
     eq_(doc.info_type, 'xml')
Ejemplo n.º 12
0
 def test_as_etree(self):
     doc = XMLFeatureInfoDoc('<root>hello</root>')
     eq_(doc.as_etree().getroot().text, 'hello')
Ejemplo n.º 13
0
 def test_as_string(self):
     input_tree = etree.fromstring('<root></root>')
     doc = XMLFeatureInfoDoc(input_tree)
     eq_(strip_whitespace(doc.as_string()),
         b'<root/>')
Ejemplo n.º 14
0
 def test_as_etree(self):
     doc = XMLFeatureInfoDoc('<root>hello</root>')
     eq_(doc.as_etree().getroot().text, 'hello')
Ejemplo n.º 15
0
 def test_as_string(self):
     input_tree = etree.fromstring('<root></root>')
     doc = XMLFeatureInfoDoc(input_tree)
     eq_(strip_whitespace(doc.as_string()), b'<root/>')
Ejemplo n.º 16
0
 def test_transformer(self):
     t = XSLTransformer(self.xsl_script)
     doc = t.transform(XMLFeatureInfoDoc('<a><b>Text</b></a>'))
     eq_(strip_whitespace(doc.as_string()), b'<root><foo>Text</foo></root>')
Ejemplo n.º 17
0
 def test_transformer(self):
     t = XSLTransformer(self.xsl_script)
     doc = t.transform(XMLFeatureInfoDoc("<a><b>Text</b></a>"))
     assert strip_whitespace(
         doc.as_string()) == b"<root><foo>Text</foo></root>"
Ejemplo n.º 18
0
 def test_as_string(self):
     input_tree = etree.fromstring("<root></root>")
     doc = XMLFeatureInfoDoc(input_tree)
     assert strip_whitespace(doc.as_string()) == b"<root/>"
Ejemplo n.º 19
0
 def test_as_etree(self):
     doc = XMLFeatureInfoDoc("<root>hello</root>")
     assert doc.as_etree().getroot().text == "hello"