|
17 | 17 | from docx.parts.document import DocumentPart, InlineShapes |
18 | 18 | from docx.parts.numbering import NumberingPart |
19 | 19 | from docx.parts.styles import StylesPart |
| 20 | +from docx.section import Section |
20 | 21 | from docx.table import Table |
21 | 22 | from docx.text import Paragraph, Run |
22 | 23 |
|
@@ -96,6 +97,14 @@ def it_can_add_a_picture(self, add_picture_fixture): |
96 | 97 | assert picture.height == expected_height |
97 | 98 | assert picture is picture_ |
98 | 99 |
|
| 100 | + def it_can_add_a_section(self, add_section_fixture): |
| 101 | + document, start_type_, section_ = add_section_fixture |
| 102 | + section = document.add_section(start_type_) |
| 103 | + document._document_part.add_section.assert_called_once_with( |
| 104 | + start_type_ |
| 105 | + ) |
| 106 | + assert section is section_ |
| 107 | + |
99 | 108 | def it_can_add_a_table(self, add_table_fixture): |
100 | 109 | document, rows, cols, style, document_part_, expected_style, table_ = ( |
101 | 110 | add_table_fixture |
@@ -200,6 +209,10 @@ def add_picture_fixture( |
200 | 209 | expected_width, expected_height, picture_ |
201 | 210 | ) |
202 | 211 |
|
| 212 | + @pytest.fixture |
| 213 | + def add_section_fixture(self, document, start_type_, section_): |
| 214 | + return document, start_type_, section_ |
| 215 | + |
203 | 216 | @pytest.fixture |
204 | 217 | def add_styled_paragraph_fixture(self, document, p_): |
205 | 218 | style = 'foobaresque' |
@@ -269,11 +282,13 @@ def document(self, open_): |
269 | 282 | return Document() |
270 | 283 |
|
271 | 284 | @pytest.fixture |
272 | | - def document_part_(self, request, p_, paragraphs_, table_, tables_): |
| 285 | + def document_part_( |
| 286 | + self, request, p_, paragraphs_, section_, table_, tables_): |
273 | 287 | document_part_ = instance_mock( |
274 | 288 | request, DocumentPart, content_type=CT.WML_DOCUMENT_MAIN |
275 | 289 | ) |
276 | 290 | document_part_.add_paragraph.return_value = p_ |
| 291 | + document_part_.add_section.return_value = section_ |
277 | 292 | document_part_.add_table.return_value = table_ |
278 | 293 | document_part_.paragraphs = paragraphs_ |
279 | 294 | document_part_.tables = tables_ |
@@ -336,6 +351,14 @@ def paragraphs_(self, request): |
336 | 351 | def r_(self, request): |
337 | 352 | return instance_mock(request, Run) |
338 | 353 |
|
| 354 | + @pytest.fixture |
| 355 | + def section_(self, request): |
| 356 | + return instance_mock(request, Section) |
| 357 | + |
| 358 | + @pytest.fixture |
| 359 | + def start_type_(self, request): |
| 360 | + return instance_mock(request, int) |
| 361 | + |
339 | 362 | @pytest.fixture |
340 | 363 | def StylesPart_(self, request, styles_part_): |
341 | 364 | StylesPart_ = class_mock(request, 'docx.api.StylesPart') |
|
0 commit comments