コード例 #1
0
def test_split_comma_footnotes(original, expected):
    """The XML will sometimes merge multiple references to footnotes into a
    single tag. Verify that they get split"""
    with XMLBuilder("ROOT") as ctx:
        ctx.child_from_string("<P>{0}</P>".format(original))

    with XMLBuilder("ROOT") as ctx2:
        ctx2.child_from_string("<P>{0}</P>".format(expected))
    preprocessors.Footnotes().split_comma_footnotes(ctx.xml)
    assert ctx.xml_str == ctx2.xml_str
コード例 #2
0
    def test_table_with_caption_with_footnote_as_caption(self):
        """
        Caption[^1](No work of any kind shall be conducted)
         Caption[^1]
        |R1C1       |
        |R2C1 |R2C2 |

        This is testing the implementation of the TTITLE as a caption element.
        """
        with XMLBuilder("GPOTABLE", COLS=6) as ctx:
            ctx.child_from_string("<TTITLE>Caption<SU>1</SU></TTITLE>")
            with ctx.BOXHD():
                ctx.CHED(u"R1C1", H=1)
                ctx.CHED(u"R2C1", H=2)
                ctx.CHED(u"R2C2", H=2)
            ctx.child_from_string(
                "<TNOTE><SU>1</SU> No work of any kind shall be conducted"
                "</TNOTE>")

        preprocessor = preprocessors.Footnotes()
        preprocessor.transform(ctx.xml)
        markdown = formatting.table_xml_to_plaintext(ctx.xml)
        self.assertTrue("R1C1" in markdown)
        self.assertTrue("R2C2" in markdown)

        node = Node(markdown, source_xml=ctx.xml)
        result = formatting.Formatting(None).process(node)
        self.assertEqual(2, len(result))
        table, footnote = result

        self.assertEqual(markdown, table['text'])
        self.assertEqual([0], table['locations'])
        data = table['table_data']
        self.assertTrue("header" in data)

        # Verify header matches:
        def mkhd(t, c, r):
            return {'text': t, 'colspan': c, 'rowspan': r}

        self.assertEqual(
            [[mkhd("R1C1", 2, 1)], [mkhd("R2C1", 1, 1),
                                    mkhd("R2C2", 1, 1)]], data["header"])
        self.assertTrue("caption" in data)
        self.assertEqual("Caption[^1](No work of any kind shall be conducted)",
                         data["caption"])
        self.assertEqual(u'[^1](No work of any kind shall be conducted)',
                         footnote['text'])
        self.assertEqual(u'1', footnote['footnote_data']['ref'])
        self.assertEqual(u'No work of any kind shall be conducted',
                         footnote['footnote_data']['note'])
        self.assertEqual([0], footnote['locations'])
コード例 #3
0
def test_add_ref_attributes_missing():
    """SUs in different sections aren't related"""
    with XMLBuilder("ROOT") as ctx:
        with ctx.SECTION():
            ctx.SU("1")
        with ctx.SECTION():
            ctx.SU("1")
            with ctx.FTNT():
                ctx.child_from_string('<P><SU>1</SU> note for one</P>')

    with XMLBuilder("ROOT") as ctx2:
        with ctx2.SECTION():
            ctx2.SU("1")
        with ctx2.SECTION():
            ctx2.SU("1", footnote="note for one")
            with ctx2.FTNT():
                ctx2.child_from_string('<P><SU>1</SU> note for one</P>')

    preprocessors.Footnotes().add_ref_attributes(ctx.xml)
    assert ctx.xml_str == ctx2.xml_str
コード例 #4
0
def test_add_ref_attributes():
    """The XML elements which reference footnotes should be modified to
    contain the contents of those footnotes"""
    with XMLBuilder("ROOT") as ctx:
        ctx.SU("1")
        ctx.SU("2")
        with ctx.FTNT():
            ctx.child_from_string('<P><SU>1</SU> note for one</P>')
        with ctx.TNOTE():
            ctx.child_from_string('<P><SU>2</SU> note for two</P>')

    with XMLBuilder("ROOT") as ctx2:
        ctx2.SU("1", footnote='note for one')
        ctx2.SU("2", footnote='note for two')
        with ctx2.FTNT():
            ctx2.child_from_string('<P><SU>1</SU> note for one</P>')
        with ctx2.TNOTE():
            ctx2.child_from_string('<P><SU>2</SU> note for two</P>')

    preprocessors.Footnotes().add_ref_attributes(ctx.xml)
    assert ctx.xml_str == ctx2.xml_str
 def setUp(self):
     super(FootnotesTests, self).setUp()
     self.fn = preprocessors.Footnotes()