Ejemplo n.º 1
0
def test_parse_fmx_colspec(attrib, styles, nature):
    cals_colspec = etree.Element("colspec", attrib=attrib)
    parser = FormexParser(BaseBuilder())
    parser.setup_table()
    state = parser._state
    state.next_col()
    state = parser.parse_fmx_colspec(cals_colspec)
    col_pos = int(attrib.get("colnum", 1))
    col = state.table.cols[col_pos]
    assert col.styles == styles
    assert col.nature == nature
Ejemplo n.º 2
0
def test_parse_fmx_cell__with_cals():
    E = ElementMaker()
    fmx_cell = E.CELL(
        colsep="1",
        rowsep="1",
        namest="c1",
        nameend="c3",
        bgcolor="#00007f",
        morerows="1",
        align="center",
        valign="middle",
    )
    parser = FormexParser(BaseBuilder())
    state = parser.setup_table()
    state.next_row()
    state.row = state.table.rows[state.row_pos]
    parser.parse_fmx_cell(fmx_cell)
    table = state.table
    cell = table[(1, 1)]
    assert cell.styles == {
        'align': 'center',
        'background-color': '#00007f',
        'vertical-align': 'middle',
        'x-cell-border-bottom': 'solid 1pt black',
        'x-cell-border-right': 'solid 1pt black',
    }
    assert cell.nature is None
    assert cell.size == (3, 2)
Ejemplo n.º 3
0
def test_parse_fmx_sti_blk__level1():
    fmx_blk = etree.Element("BLK")
    fmx_sti_blk = etree.XML(
        """<STI.BLK COL.START="2" COL.END="2" valign="top" rowsep="1" bgcolor="blue">text</STI.BLK>"""
    )
    fmx_blk.append(fmx_sti_blk)
    parser = FormexParser(BaseBuilder())
    state = parser.setup_table()
    state.next_row()
    state = parser.parse_fmx_sti_blk(fmx_sti_blk)
    row = state.row
    assert row.styles == {
        'background-color': 'blue',
        'border-bottom': 'solid 1pt black',
        'rowstyle': 'STI.BLK-level1',
        'vertical-align': 'top',
    }
    assert row.nature == "body"
    table = state.table
    cell1 = table[(1, 1)]
    assert cell1.content is None
    cell2 = table[(2, 1)]
    assert cell2.styles == {}
    assert cell2.nature == "body"
    assert cell2.width == 1
    assert cell2.height == 1
    assert cell2.content[0] == "text"
Ejemplo n.º 4
0
def test_parse_fmx_ti_blk__level2__with_namespace():
    def fmx(name):
        return etree.QName(FORMEX_NS, name).text

    BLK = fmx("BLK")
    TI_BLK = fmx("TI.BLK")
    IE = fmx("IE")

    fmx_blk1 = etree.Element(BLK, nsmap={None: FORMEX_NS})
    fmx_blk2 = etree.SubElement(fmx_blk1, BLK, nsmap={None: FORMEX_NS})
    fmx_ti_blk = etree.SubElement(fmx_blk2, TI_BLK, nsmap={None: FORMEX_NS})
    etree.SubElement(fmx_ti_blk, IE, nsmap={None: FORMEX_NS})

    parser = FormexParser(BaseBuilder(),
                          formex_ns=FORMEX_NS,
                          cals_prefix=CALS_PREFIX,
                          cals_ns=CALS_NS)
    state = parser.setup_table()
    state.next_row()
    state = parser.parse_fmx_ti_blk(fmx_ti_blk)

    row = state.row
    assert row.styles == {"rowstyle": "TI.BLK-level2"}
    assert row.nature == "body"
    table = state.table
    cell = table[(1, 1)]
    assert cell.styles == {}
    assert cell.nature == "body"
    assert cell.width == 1
    assert cell.height == 1
    assert cell.content == ""
Ejemplo n.º 5
0
def test_parse_fmx_ti_blk__level1():
    fmx_blk = etree.Element("BLK")
    fmx_ti_blk = etree.XML(
        """<TI.BLK COL.START="1" COL.END="2" valign="top" rowsep="1" bgcolor="blue"><P>paragraph</P></TI.BLK>"""
    )
    fmx_blk.append(fmx_ti_blk)
    parser = FormexParser(BaseBuilder())
    state = parser.setup_table()
    state.next_row()
    state = parser.parse_fmx_ti_blk(fmx_ti_blk)
    row = state.row
    assert row.styles == {
        'background-color': 'blue',
        'border-bottom': 'solid 1pt black',
        'rowstyle': 'TI.BLK-level1',
        'vertical-align': 'top',
    }
    assert row.nature == "body"
    table = state.table
    cell = table[(1, 1)]
    assert cell.styles == {}
    assert cell.nature == "body"
    assert cell.width == 2
    assert cell.height == 1
    assert etree.tounicode(cell.content[0]) == "<P>paragraph</P>"
Ejemplo n.º 6
0
def test_parse_fmx_row(attrib, styles, nature):
    E = ElementMaker()
    fmx_row = E.ROW(**attrib)
    parser = FormexParser(BaseBuilder())
    state = parser.setup_table()
    state.next_row()
    state.row = state.table.rows[state.row_pos]
    state = parser.parse_fmx_row(fmx_row)
    row = state.row
    assert row.styles == styles
    assert row.nature == nature
Ejemplo n.º 7
0
def test_parse_fmx_cell(attrib, styles, nature, size):
    E = ElementMaker()
    fmx_cell = E.CELL(**attrib)
    parser = FormexParser(BaseBuilder())
    state = parser.setup_table()
    state.next_row()
    state.row = state.table.rows[state.row_pos]
    parser.parse_fmx_cell(fmx_cell)
    table = state.table
    cell = table[(1, 1)]
    assert cell.styles == styles
    assert cell.nature == nature
    assert cell.size == size
Ejemplo n.º 8
0
def test_parse_fmx_ti_blk__level2():
    fmx_blk = etree.Element("BLK")
    fmx_blk = etree.SubElement(fmx_blk, "BLK")
    fmx_ti_blk = etree.XML("""<TI.BLK><IE/></TI.BLK>""")
    fmx_blk.append(fmx_ti_blk)
    parser = FormexParser(BaseBuilder())
    state = parser.setup_table()
    state.next_row()
    state = parser.parse_fmx_ti_blk(fmx_ti_blk)
    row = state.row
    assert row.styles == {"rowstyle": "TI.BLK-level2"}
    assert row.nature == "body"
    table = state.table
    cell = table[(1, 1)]
    assert cell.styles == {}
    assert cell.nature == "body"
    assert cell.width == 1
    assert cell.height == 1
    assert cell.content == ""
Ejemplo n.º 9
0
def test_parse_fmx_gr_notes():
    # fmt: off
    fmx_gr_notes = etree.XML("""\
    <GR.NOTES valign="top" rowsep="1" bgcolor="blue">
      <TITLE><TI><P>GR.NOTES Title</P></TI></TITLE>
      <NOTE NOTE.ID="N0001"><P>Table note</P></NOTE>
    </GR.NOTES>""")
    # fmt: on

    parser = FormexParser(BaseBuilder())
    state = parser.setup_table()
    # -- insert at least one ROW for testing
    state.next_row()
    state.row = state.table.rows[state.row_pos]
    state.row.insert_cell("text1")
    state.row.insert_cell("text2")
    state.row.insert_cell("text3")
    # -- then add the footer
    state.next_row()
    state = parser.parse_gr_notes(fmx_gr_notes)
    row = state.row
    assert row.styles == {}
    assert row.nature == "footer"
    # -- the cell is in the row 2
    cell = state.table[(1, 2)]
    assert cell.styles == {
        'background-color': 'blue',
        'border-bottom': 'solid 1pt black',
        'vertical-align': 'top'
    }
    assert cell.nature == "footer"
    assert cell.width == 3
    assert cell.height == 1
    content = [
        node for node in cell.content if isinstance(node, etree._Element)
    ]
    assert etree.tounicode(
        content[0],
        with_tail=False) == "<TITLE><TI><P>GR.NOTES Title</P></TI></TITLE>"
    assert etree.tounicode(
        content[1],
        with_tail=False) == '<NOTE NOTE.ID="N0001"><P>Table note</P></NOTE>'