def test_build_header(self):
        """
        I think this header is supposed to look like this:


        |1-1|1-2                    |
        |   |2-1        |2-2        |
        |   |3-1|3-2|3-3|3-4|3-5|3-6|

        """
        with XMLBuilder("BOXHD") as ctx:
            ctx.CHED("1-1", H=1)
            ctx.CHED("1-2", H=1)
            ctx.CHED("2-1", H=2)
            ctx.CHED("3-1", H=3)
            ctx.CHED("3-2", H=3)
            ctx.CHED("3-3", H=3)
            ctx.CHED("2-2", H=2)
            ctx.CHED("3-4", H=3)
            ctx.CHED("3-5", H=3)
            ctx.child_from_string(
                '<CHED H="3">3-6<LI>Other Content</LI></CHED>')
        root = formatting.build_header(ctx.xml.xpath('./CHED'))

        n11, n12 = root.children
        self.assertEqual('1-1', n11.text)
        self.assertEqual(1, n11.colspan)
        self.assertEqual(3, n11.rowspan)
        self.assertEqual([], n11.children)

        self.assertEqual('1-2', n12.text)
        self.assertEqual(6, n12.colspan)
        self.assertEqual(1, n12.rowspan)

        n21, n22 = n12.children
        self.assertEqual('2-1', n21.text)
        self.assertEqual(3, n21.colspan)
        self.assertEqual(1, n21.rowspan)

        n31, n32, n33 = n21.children
        self.assertEqual('3-1', n31.text)
        self.assertEqual('3-2', n32.text)
        self.assertEqual('3-3', n33.text)
        for n in n21.children:
            self.assertEqual(1, n.colspan)
            self.assertEqual(1, n.rowspan)

        self.assertEqual('2-2', n22.text)
        self.assertEqual(3, n22.colspan)
        self.assertEqual(1, n22.rowspan)

        n34, n35, n36 = n22.children
        self.assertEqual('3-4', n34.text)
        self.assertEqual('3-5', n35.text)
        self.assertEqual('3-6 Other Content', n36.text)
        for n in n22.children:
            self.assertEqual(1, n.colspan)
            self.assertEqual(1, n.rowspan)
    def test_build_header(self):
        """
        I think this header is supposed to look like this:


        |1-1|1-2                    |
        |   |2-1        |2-2        |
        |   |3-1|3-2|3-3|3-4|3-5|3-6|

        """
        with XMLBuilder("BOXHD") as ctx:
            ctx.CHED("1-1", H=1)
            ctx.CHED("1-2", H=1)
            ctx.CHED("2-1", H=2)
            ctx.CHED("3-1", H=3)
            ctx.CHED("3-2", H=3)
            ctx.CHED("3-3", H=3)
            ctx.CHED("2-2", H=2)
            ctx.CHED("3-4", H=3)
            ctx.CHED("3-5", H=3)
            ctx.child_from_string(
                '<CHED H="3">3-6<LI>Other Content</LI></CHED>')
        root = formatting.build_header(ctx.xml.xpath('./CHED'))

        n11, n12 = root.children
        self.assertEqual('1-1', n11.text)
        self.assertEqual(1, n11.colspan)
        self.assertEqual(3, n11.rowspan)
        self.assertEqual([], n11.children)

        self.assertEqual('1-2', n12.text)
        self.assertEqual(6, n12.colspan)
        self.assertEqual(1, n12.rowspan)

        n21, n22 = n12.children
        self.assertEqual('2-1', n21.text)
        self.assertEqual(3, n21.colspan)
        self.assertEqual(1, n21.rowspan)

        n31, n32, n33 = n21.children
        self.assertEqual('3-1', n31.text)
        self.assertEqual('3-2', n32.text)
        self.assertEqual('3-3', n33.text)
        for n in n21.children:
            self.assertEqual(1, n.colspan)
            self.assertEqual(1, n.rowspan)

        self.assertEqual('2-2', n22.text)
        self.assertEqual(3, n22.colspan)
        self.assertEqual(1, n22.rowspan)

        n34, n35, n36 = n22.children
        self.assertEqual('3-4', n34.text)
        self.assertEqual('3-5', n35.text)
        self.assertEqual('3-6 Other Content', n36.text)
        for n in n22.children:
            self.assertEqual(1, n.colspan)
            self.assertEqual(1, n.rowspan)
    def test_build_header(self):
        """
        I think this header is supposed to look like this:


        |1-1|1-2                    |
        |   |2-1        |2-2        |
        |   |3-1|3-2|3-3|3-4|3-5|3-6|

        """
        with self.tree.builder("BOXHD") as root:
            root.CHED("1-1", H=1)
            root.CHED("1-2", H=1)
            root.CHED("2-1", H=2)
            root.CHED("3-1", H=3)
            root.CHED("3-2", H=3)
            root.CHED("3-3", H=3)
            root.CHED("2-2", H=2)
            root.CHED("3-4", H=3)
            root.CHED("3-5", H=3)
            root.CHED(_xml="3-6<LI>Other Content</LI>", H=3)
        root = formatting.build_header(self.tree.render_xml().xpath('./CHED'))

        n11, n12 = root.children
        self.assertEqual('1-1', n11.text)
        self.assertEqual(1, n11.colspan)
        self.assertEqual(3, n11.rowspan)
        self.assertEqual([], n11.children)

        self.assertEqual('1-2', n12.text)
        self.assertEqual(6, n12.colspan)
        self.assertEqual(1, n12.rowspan)

        n21, n22 = n12.children
        self.assertEqual('2-1', n21.text)
        self.assertEqual(3, n21.colspan)
        self.assertEqual(1, n21.rowspan)

        n31, n32, n33 = n21.children
        self.assertEqual('3-1', n31.text)
        self.assertEqual('3-2', n32.text)
        self.assertEqual('3-3', n33.text)
        for n in n21.children:
            self.assertEqual(1, n.colspan)
            self.assertEqual(1, n.rowspan)

        self.assertEqual('2-2', n22.text)
        self.assertEqual(3, n22.colspan)
        self.assertEqual(1, n22.rowspan)

        n34, n35, n36 = n22.children
        self.assertEqual('3-4', n34.text)
        self.assertEqual('3-5', n35.text)
        self.assertEqual('3-6 Other Content', n36.text)
        for n in n22.children:
            self.assertEqual(1, n.colspan)
            self.assertEqual(1, n.rowspan)
Пример #4
0
    def test_build_header(self):
        xml = etree.fromstring("""
            <BOXHD>
                <CHED H="1">1-1</CHED>
                <CHED H="1">1-2</CHED>
                <CHED H="2">2-1</CHED>
                <CHED H="3">3-1</CHED>
                <CHED H="3">3-2</CHED>
                <CHED H="3">3-3</CHED>
                <CHED H="2">2-2</CHED>
                <CHED H="3">3-4</CHED>
                <CHED H="3">3-5</CHED>
                <CHED H="3">3-6<LI>Other Content</LI></CHED>
            </BOXHD>""")
        root = formatting.build_header(xml.xpath('./CHED'))

        n11, n12 = root.children
        self.assertEqual('1-1', n11.text)
        self.assertEqual(1, n11.colspan)
        self.assertEqual(3, n11.rowspan)
        self.assertEqual([], n11.children)

        self.assertEqual('1-2', n12.text)
        self.assertEqual(6, n12.colspan)
        self.assertEqual(1, n12.rowspan)

        n21, n22 = n12.children
        self.assertEqual('2-1', n21.text)
        self.assertEqual(3, n21.colspan)
        self.assertEqual(1, n21.rowspan)

        n31, n32, n33 = n21.children
        self.assertEqual('3-1', n31.text)
        self.assertEqual('3-2', n32.text)
        self.assertEqual('3-3', n33.text)
        for n in n21.children:
            self.assertEqual(1, n.colspan)
            self.assertEqual(1, n.rowspan)

        self.assertEqual('2-2', n22.text)
        self.assertEqual(3, n22.colspan)
        self.assertEqual(1, n22.rowspan)

        n34, n35, n36 = n22.children
        self.assertEqual('3-4', n34.text)
        self.assertEqual('3-5', n35.text)
        self.assertEqual('3-6 Other Content', n36.text)
        for n in n22.children:
            self.assertEqual(1, n.colspan)
            self.assertEqual(1, n.rowspan)