1111import pytest
1212
1313from docx .document import _Body , Document
14+ from docx .enum .text import WD_BREAK
1415from docx .parts .document import DocumentPart
1516from docx .text .paragraph import Paragraph
17+ from docx .text .run import Run
1618
1719from .unitutil .cxml import element
1820from .unitutil .mock import (
@@ -35,6 +37,14 @@ def it_raises_on_heading_level_out_of_range(self):
3537 with pytest .raises (ValueError ):
3638 document .add_heading (level = 10 )
3739
40+ def it_can_add_a_page_break (self , add_page_break_fixture ):
41+ document , paragraph_ , run_ = add_page_break_fixture
42+ paragraph = document .add_page_break ()
43+ document .add_paragraph .assert_called_once_with ()
44+ paragraph_ .add_run .assert_called_once_with ()
45+ run_ .add_break .assert_called_once_with (WD_BREAK .PAGE )
46+ assert paragraph is paragraph_
47+
3848 def it_can_add_a_paragraph (self , add_paragraph_fixture ):
3949 document , text , style , paragraph_ = add_paragraph_fixture
4050 paragraph = document .add_paragraph (text , style )
@@ -66,6 +76,13 @@ def add_heading_fixture(self, request, add_paragraph_, paragraph_):
6676 add_paragraph_ .return_value = paragraph_
6777 return document , text , level , style , paragraph_
6878
79+ @pytest .fixture
80+ def add_page_break_fixture (self , add_paragraph_ , paragraph_ , run_ ):
81+ document = Document (None , None )
82+ add_paragraph_ .return_value = paragraph_
83+ paragraph_ .add_run .return_value = run_
84+ return document , paragraph_ , run_
85+
6986 @pytest .fixture (params = [
7087 ('' , None ),
7188 ('' , 'Heading 1' ),
@@ -114,3 +131,7 @@ def document_part_(self, request):
114131 @pytest .fixture
115132 def paragraph_ (self , request ):
116133 return instance_mock (request , Paragraph )
134+
135+ @pytest .fixture
136+ def run_ (self , request ):
137+ return instance_mock (request , Run )
0 commit comments