Esempio n. 1
0
def test_parse_cals_entry(attrib, styles, nature):
    # --without namespaces
    cals_entry = etree.Element("entry", attrib=attrib)
    parser = CalsParser(BaseBuilder())
    parser.setup_table()
    state = parser._state
    state.next_row()
    state.row = state.table.rows[state.row_pos]
    state.next_col()
    state = parser.parse_cals_entry(cals_entry)
    cell = state.table[(1, 1)]
    assert cell.styles == styles
    assert cell.nature == nature

    # --with default namespaces
    cals_entry_attrib = {cals(k): v for k, v in attrib.items()}
    cals_entry = etree.Element(cals("entry"),
                               attrib=cals_entry_attrib,
                               nsmap={None: CALS_NS})
    parser = CalsParser(BaseBuilder(), cals_ns=CALS_NS)
    parser.setup_table()
    state = parser._state
    state.next_row()
    state.row = state.table.rows[state.row_pos]
    state.next_col()
    state = parser.parse_cals_entry(cals_entry)
    cell = state.table[(1, 1)]
    assert cell.styles == styles
    assert cell.nature == nature
Esempio n. 2
0
def test_parse_cals_entry__spanning(attrib, size):
    # --without namespaces
    cals_entry = etree.Element("entry", attrib=attrib)
    parser = CalsParser(BaseBuilder())
    parser.setup_table()
    state = parser._state
    state.next_row()
    state.row = state.table.rows[state.row_pos]
    state.next_col()
    state = parser.parse_cals_entry(cals_entry)
    cell = state.table[(1, 1)]
    assert cell.size == size
Esempio n. 3
0
def test_parse_cals_entry(attrib, styles, nature):
    # --without namespaces
    cals_entry = etree.Element("entry", attrib=attrib)
    parser = CalsParser(BaseBuilder())
    parser.setup_table()
    state = parser._state
    state.next_row()
    state.row = state.table.rows[state.row_pos]
    state.next_col()
    state = parser.parse_cals_entry(cals_entry)
    cell = state.table[(1, 1)]
    # Ignore cell styles extensions (like 'x-cell-empty').
    actual = {
        k: v
        for k, v in cell.styles.items() if not k.startswith("x-cell-")
    }
    assert actual == styles
    assert cell.nature == nature

    # --with default namespaces
    cals_entry_attrib = {cals(k): v for k, v in attrib.items()}
    cals_entry = etree.Element(cals("entry"),
                               attrib=cals_entry_attrib,
                               nsmap={None: CALS_NS})
    parser = CalsParser(BaseBuilder(), cals_ns=CALS_NS)
    parser.setup_table()
    state = parser._state
    state.next_row()
    state.row = state.table.rows[state.row_pos]
    state.next_col()
    state = parser.parse_cals_entry(cals_entry)
    cell = state.table[(1, 1)]
    # Ignore cell styles extensions (like 'x-cell-empty').
    actual = {
        k: v
        for k, v in cell.styles.items() if not k.startswith("x-cell-")
    }
    assert actual == styles
    assert cell.nature == nature