|
13 | 13 | from docx.document import _Body, Document |
14 | 14 | from docx.enum.text import WD_BREAK |
15 | 15 | from docx.parts.document import DocumentPart |
| 16 | +from docx.shape import InlineShape |
16 | 17 | from docx.text.paragraph import Paragraph |
17 | 18 | from docx.text.run import Run |
18 | 19 |
|
@@ -51,6 +52,12 @@ def it_can_add_a_paragraph(self, add_paragraph_fixture): |
51 | 52 | document._body.add_paragraph.assert_called_once_with(text, style) |
52 | 53 | assert paragraph is paragraph_ |
53 | 54 |
|
| 55 | + def it_can_add_a_picture(self, add_picture_fixture): |
| 56 | + document, path, width, height, run_, picture_ = add_picture_fixture |
| 57 | + picture = document.add_picture(path, width, height) |
| 58 | + run_.add_picture.assert_called_once_with(path, width, height) |
| 59 | + assert picture is picture_ |
| 60 | + |
54 | 61 | def it_provides_access_to_the_document_part(self, part_fixture): |
55 | 62 | document, part_ = part_fixture |
56 | 63 | assert document.part is part_ |
@@ -94,6 +101,14 @@ def add_paragraph_fixture(self, request, body_prop_, paragraph_): |
94 | 101 | body_prop_.return_value.add_paragraph.return_value = paragraph_ |
95 | 102 | return document, text, style, paragraph_ |
96 | 103 |
|
| 104 | + @pytest.fixture |
| 105 | + def add_picture_fixture(self, request, add_paragraph_, run_, picture_): |
| 106 | + document = Document(None, None) |
| 107 | + path, width, height = 'foobar.png', 100, 200 |
| 108 | + add_paragraph_.return_value.add_run.return_value = run_ |
| 109 | + run_.add_picture.return_value = picture_ |
| 110 | + return document, path, width, height, run_, picture_ |
| 111 | + |
97 | 112 | @pytest.fixture |
98 | 113 | def body_fixture(self, _Body_, body_): |
99 | 114 | document_elm = element('w:document/w:body') |
@@ -132,6 +147,10 @@ def document_part_(self, request): |
132 | 147 | def paragraph_(self, request): |
133 | 148 | return instance_mock(request, Paragraph) |
134 | 149 |
|
| 150 | + @pytest.fixture |
| 151 | + def picture_(self, request): |
| 152 | + return instance_mock(request, InlineShape) |
| 153 | + |
135 | 154 | @pytest.fixture |
136 | 155 | def run_(self, request): |
137 | 156 | return instance_mock(request, Run) |
0 commit comments