Beispiel #1
0
def test_build_cell__with_sep(cell_styles, expected):
    # .. note::
    #
    #   CALS default value for @colsep and @rowsep is "1".

    builder = CalsBuilder()

    # -- create a minimal <row> element
    row_elem = etree.XML("<row/>")

    # -- setup a minimal cell
    p_elem = etree.XML("<p>text</p>")
    cell_x1_y1 = Cell([p_elem], x=1, y=1, styles=cell_styles)
    cell_x2_y1 = Cell([p_elem], x=2, y=1, styles=cell_styles)
    cell_x1_y2 = Cell([p_elem], x=1, y=2, styles=cell_styles)
    cell_x2_y2 = Cell([p_elem], x=2, y=2, styles=cell_styles)
    builder.setup_table(Table([cell_x1_y1, cell_x2_y1, cell_x1_y2,
                               cell_x2_y2]))

    # -- build the cell
    builder.build_cell(row_elem, cell_x1_y1)

    # -- check the '<entry>' attributes
    entry_elem = row_elem[0]  # type: ElementType
    assert entry_elem.tag == u"entry"
    assert entry_elem.attrib == expected
    assert entry_elem[0] == p_elem
Beispiel #2
0
def test_build_cell__align(cell_styles, expected):
    builder = CalsBuilder()

    # -- create a minimal <row> element
    row_elem = etree.XML("<row/>")

    # -- setup a minimal cell
    p_elem = etree.XML("<p>text</p>")
    cell = Cell([p_elem], x=1, y=1, styles=cell_styles)
    builder.setup_table(Table([cell]))

    # -- build the cell
    builder.build_cell(row_elem, cell)

    # -- check the '<entry>' attributes
    entry_elem = row_elem[0]  # type: ElementType
    assert entry_elem.tag == u"entry"

    # we don't want to check @colsep/@rowsep here
    actual = dict(entry_elem.attrib)
    actual.pop("colsep", None)
    actual.pop("rowsep", None)

    assert actual == expected
    assert entry_elem[0] == p_elem
Beispiel #3
0
def test_build_tgroup__tgroup_sorting(tgroup_sorting, expected_tags):
    # -- create a table with different natures
    table = Table()
    row1 = table.rows[1]
    row2 = table.rows[2]
    row3 = table.rows[3]
    row1.nature = "header"
    row2.nature = "body"
    row3.nature = "footer"
    row1.insert_cell("a")
    row2.insert_cell("b")
    row3.insert_cell("c")

    # -- create a builder
    table_elem = etree.Element("table")
    builder = CalsBuilder(tgroup_sorting=tgroup_sorting)
    builder.setup_table(table)
    builder.build_tgroup(table_elem, table)

    # -- check the tgroup children name and order
    actual_tags = [elem.tag for elem in table_elem.xpath("tgroup/*")]
    assert actual_tags == expected_tags
Beispiel #4
0
def test_setup_table():
    builder = CalsBuilder()
    table = Table()
    result = builder.setup_table(table)
    assert result == table