|
15 | 15 | from docx.text import Paragraph |
16 | 16 |
|
17 | 17 | from .oxml.unitdata.table import ( |
18 | | - a_gridCol, a_tbl, a_tblGrid, a_tblPr, a_tblStyle, a_tc, a_tr |
| 18 | + a_gridCol, a_tbl, a_tblGrid, a_tblPr, a_tblStyle, a_tc, a_tcPr, a_tr |
19 | 19 | ) |
20 | | -from .oxml.unitdata.text import a_p |
| 20 | +from .oxml.unitdata.text import a_p, a_t, an_r |
21 | 21 |
|
22 | 22 |
|
23 | 23 | class DescribeTable(object): |
@@ -93,8 +93,37 @@ def it_provides_access_to_the_paragraphs_it_contains( |
93 | 93 | for p in paragraphs: |
94 | 94 | assert isinstance(p, Paragraph) |
95 | 95 |
|
| 96 | + def it_can_replace_its_content_with_a_string_of_text( |
| 97 | + self, cell_text_fixture): |
| 98 | + cell, text, expected_xml = cell_text_fixture |
| 99 | + cell.text = text |
| 100 | + assert cell._tc.xml == expected_xml |
| 101 | + |
96 | 102 | # fixtures ------------------------------------------------------- |
97 | 103 |
|
| 104 | + @pytest.fixture |
| 105 | + def cell_text_fixture(self): |
| 106 | + # cell ------------------------- |
| 107 | + tc = ( |
| 108 | + a_tc().with_nsdecls().with_child( |
| 109 | + a_tcPr()).with_child( |
| 110 | + a_p()).with_child( |
| 111 | + a_tbl()).with_child( |
| 112 | + a_p()) |
| 113 | + ).element |
| 114 | + cell = _Cell(tc) |
| 115 | + # text ------------------------- |
| 116 | + text = 'foobar' |
| 117 | + # expected_xml ----------------- |
| 118 | + expected_xml = ( |
| 119 | + a_tc().with_nsdecls().with_child( |
| 120 | + a_tcPr()).with_child( |
| 121 | + a_p().with_child( |
| 122 | + an_r().with_child( |
| 123 | + a_t().with_text(text)))) |
| 124 | + ).xml() |
| 125 | + return cell, text, expected_xml |
| 126 | + |
98 | 127 | @pytest.fixture |
99 | 128 | def cell_with_paragraphs(self): |
100 | 129 | tc = ( |
|
0 commit comments