def it_can_merge_a_range_of_cells(self, TcRange_, tc_range_): tbl = element("a:tbl/(a:tr/(a:tc,a:tc),a:tr/(a:tc,a:tc))") tc, other_tc = tbl.tc(0, 0), tbl.tc(1, 1) TcRange_.return_value = tc_range_ tc_range_.contains_merged_cell = False tc_range_.dimensions = 2, 2 def tcs(*rowcols): return (tbl.tc(*rowcol) for rowcol in rowcols) tc_range_.iter_top_row_tcs.return_value = tcs((0, 0), (0, 1)) tc_range_.iter_left_col_tcs.return_value = tcs((0, 0), (1, 0)) tc_range_.iter_except_left_col_tcs.return_value = tcs((0, 1), (1, 1)) tc_range_.iter_except_top_row_tcs.return_value = tcs((1, 0), (1, 1)) expected_xml = xml( "a:tbl/(a:tr/(a:tc{gridSpan=2,rowSpan=2},a:tc{rowSpan=2,hMerge=1" "}),a:tr/(a:tc{gridSpan=2,vMerge=1},a:tc{hMerge=1,vMerge=1}))" ) cell, other_cell = _Cell(tc, None), _Cell(other_tc, None) cell.merge(other_cell) TcRange_.assert_called_once_with(tc, other_tc) tc_range_.move_content_to_origin.assert_called_once_with() assert tbl.xml == expected_xml
def but_it_raises_when_cells_are_from_different_tables(self, TcRange_, tc_range_): TcRange_.return_value = tc_range_ tc_range_.in_same_table = False cell, other_cell = _Cell(None, None), _Cell(None, None) with pytest.raises(ValueError) as e: cell.merge(other_cell) assert "different table" in str(e.value)
def and_it_raises_when_range_contains_merged_cell(self, TcRange_, tc_range_): TcRange_.return_value = tc_range_ tc_range_.contains_merged_cell = True cell, other_cell = _Cell(None, None), _Cell(None, None) with pytest.raises(ValueError) as e: cell.merge(other_cell) assert "contains one or more merged cells" in str(e.value)
def it_is_equal_to_other_instance_having_same_tc(self): tc = element("a:tc") other_tc = element("a:tc") cell = _Cell(tc, None) cell_with_same_tc = _Cell(tc, None) cell_with_other_tc = _Cell(other_tc, None) assert cell == cell_with_same_tc assert cell != cell_with_other_tc
def and_it_raises_when_range_contains_merged_cell(self, TcRange_, tc_range_): TcRange_.return_value = tc_range_ tc_range_.contains_merged_cell = True cell, other_cell = _Cell(None, None), _Cell(None, None) with pytest.raises(ValueError) as e: cell.merge(other_cell) assert 'contains one or more merged cells' in str(e.value)
def but_it_raises_when_cells_are_from_different_tables( self, TcRange_, tc_range_): TcRange_.return_value = tc_range_ tc_range_.in_same_table = False cell, other_cell = _Cell(None, None), _Cell(None, None) with pytest.raises(ValueError) as e: cell.merge(other_cell) assert 'different table' in str(e.value)
def it_is_equal_to_other_instance_having_same_tc(self): tc = element('a:tc') other_tc = element('a:tc') cell = _Cell(tc, None) cell_with_same_tc = _Cell(tc, None) cell_with_other_tc = _Cell(other_tc, None) assert cell == cell_with_same_tc assert cell != cell_with_other_tc
def it_knows_whether_it_is_merge_origin_cell(self, origin_fixture): tc, expected_value = origin_fixture cell = _Cell(tc, None) is_merge_origin = cell.is_merge_origin assert is_merge_origin is expected_value
def it_can_change_its_text(self, text_frame_prop_, text_frame_): text_frame_prop_.return_value = text_frame_ cell = _Cell(None, None) cell.text = "føøbår" assert text_frame_.text == "føøbår"
def but_it_raises_when_cell_to_be_split_is_not_merge_origin(self): tc = element('a:tbl/a:tr/a:tc').xpath('//a:tc')[0] cell = _Cell(tc, None) with pytest.raises(ValueError) as e: cell.split() assert 'not a merge-origin cell' in str(e.value)
def but_it_raises_when_cell_to_be_split_is_not_merge_origin(self): tc = element("a:tbl/a:tr/a:tc").xpath("//a:tc")[0] cell = _Cell(tc, None) with pytest.raises(ValueError) as e: cell.split() assert "not a merge-origin cell" in str(e.value)
def it_knows_whether_it_is_spanned(self, spanned_fixture): tc, expected_value = spanned_fixture cell = _Cell(tc, None) is_spanned = cell.is_spanned assert is_spanned is expected_value
def it_knows_what_text_it_contains(self, text_frame_prop_, text_frame_): text_frame_prop_.return_value = text_frame_ text_frame_.text = "foobar" cell = _Cell(None, None) text = cell.text assert text == "foobar"
def it_can_split_a_merged_cell(self, split_fixture): origin_tc, range_tcs = split_fixture cell = _Cell(origin_tc, None) cell.split() assert all(tc.gridSpan == 1 for tc in range_tcs) assert all(tc.rowSpan == 1 for tc in range_tcs) assert all(not tc.hMerge for tc in range_tcs) assert all(not tc.vMerge for tc in range_tcs)
def it_can_merge_a_range_of_cells(self, TcRange_, tc_range_): tbl = element('a:tbl/(a:tr/(a:tc,a:tc),a:tr/(a:tc,a:tc))') tc, other_tc = tbl.tc(0, 0), tbl.tc(1, 1) TcRange_.return_value = tc_range_ tc_range_.contains_merged_cell = False tc_range_.dimensions = 2, 2 def tcs(*rowcols): return (tbl.tc(*rowcol) for rowcol in rowcols) tc_range_.iter_top_row_tcs.return_value = tcs((0, 0), (0, 1)) tc_range_.iter_left_col_tcs.return_value = tcs((0, 0), (1, 0)) tc_range_.iter_except_left_col_tcs.return_value = tcs((0, 1), (1, 1)) tc_range_.iter_except_top_row_tcs.return_value = tcs((1, 0), (1, 1)) expected_xml = xml( 'a:tbl/(a:tr/(a:tc{gridSpan=2,rowSpan=2},a:tc{rowSpan=2,hMerge=1' '}),a:tr/(a:tc{gridSpan=2,vMerge=1},a:tc{hMerge=1,vMerge=1}))') cell, other_cell = _Cell(tc, None), _Cell(other_tc, None) cell.merge(other_cell) TcRange_.assert_called_once_with(tc, other_tc) tc_range_.move_content_to_origin.assert_called_once_with() assert tbl.xml == expected_xml
def anchor_get_fixture(self, request): tc_cxml, expected_value = request.param cell = _Cell(element(tc_cxml), None) return cell, expected_value
def it_knows_how_many_columns_the_merge_spans(self, width_fixture): tc, expected_value = width_fixture cell = _Cell(tc, None) span_width = cell.span_width assert span_width == expected_value
def it_knows_how_many_rows_the_merge_spans(self, height_fixture): tc, expected_value = height_fixture cell = _Cell(tc, None) span_height = cell.span_height assert span_height == expected_value
def cell(self): return _Cell(element("a:tc"), None)
def margin_get_fixture(self, request): tc_cxml, margin_prop_name, expected_value = request.param cell = _Cell(element(tc_cxml), None) return cell, margin_prop_name, expected_value
def margin_raises_fixture(self, request): margin_prop_name = request.param cell = _Cell(element('a:tc'), None) val_of_invalid_type = 'foobar' return cell, margin_prop_name, val_of_invalid_type
def text_set_fixture(self, request): tc_cxml, new_text, expected_cxml = request.param cell = _Cell(element(tc_cxml), None) expected_xml = xml(expected_cxml) return cell, new_text, expected_xml
def anchor_set_fixture(self, request): tc_cxml, new_value, expected_tc_cxml = request.param cell = _Cell(element(tc_cxml), None) expected_xml = xml(expected_tc_cxml) return cell, new_value, expected_xml
def margin_set_fixture(self, request): tc_cxml, margin_prop_name, new_value, expected_tc_cxml = request.param cell = _Cell(element(tc_cxml), None) expected_xml = xml(expected_tc_cxml) return cell, margin_prop_name, new_value, expected_xml
def text_get_fixture(self, request): tc_cxml, expected_value = request.param cell = _Cell(element(tc_cxml), None) return cell, expected_value
def cell(self): return _Cell(element('a:tc'), None)
def margin_raises_fixture(self, request): margin_prop_name = request.param cell = _Cell(element("a:tc"), None) val_of_invalid_type = "foobar" return cell, margin_prop_name, val_of_invalid_type