Skip to content

Commit c617f18

Browse files
author
Steve Canny
committed
api: remove old Document.add_picture()
1 parent 253b179 commit c617f18

File tree

2 files changed

+2
-38
lines changed

2 files changed

+2
-38
lines changed

docx/api.py

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -61,22 +61,8 @@ def add_page_break(self):
6161
def add_paragraph(self, text='', style=None):
6262
return self._document.add_paragraph(text, style)
6363

64-
def add_picture(self, image_path_or_stream, width=None, height=None):
65-
"""
66-
Return a new picture shape added in its own paragraph at the end of
67-
the document. The picture contains the image at
68-
*image_path_or_stream*, scaled based on *width* and *height*. If
69-
neither width nor height is specified, the picture appears at its
70-
native size. If only one is specified, it is used to compute
71-
a scaling factor that is then applied to the unspecified dimension,
72-
preserving the aspect ratio of the image. The native size of the
73-
picture is calculated using the dots-per-inch (dpi) value specified
74-
in the image file, defaulting to 72 dpi if no value is specified, as
75-
is often the case.
76-
"""
77-
run = self.add_paragraph().add_run()
78-
picture = run.add_picture(image_path_or_stream, width, height)
79-
return picture
64+
def add_picture(self, image_descriptor, width=None, height=None):
65+
return self._document.add_picture(image_descriptor, width, height)
8066

8167
def add_section(self, start_type=WD_SECTION.NEW_PAGE):
8268
"""

tests/test_api.py

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
from docx.parts.document import DocumentPart, InlineShapes
2020
from docx.parts.numbering import NumberingPart
2121
from docx.section import Section
22-
from docx.shape import InlineShape
2322
from docx.styles.styles import Styles
2423
from docx.table import Table
2524
from docx.text.run import Run
@@ -90,14 +89,6 @@ def Package_(self, request):
9089

9190
class DescribeDocumentOld(object):
9291

93-
def it_can_add_a_picture(self, add_picture_fixture):
94-
document, image_path_, width, height, run_, picture_ = (
95-
add_picture_fixture
96-
)
97-
picture = document.add_picture(image_path_, width, height)
98-
run_.add_picture.assert_called_once_with(image_path_, width, height)
99-
assert picture is picture_
100-
10192
def it_can_add_a_section(self, add_section_fixture):
10293
document, start_type_, section_ = add_section_fixture
10394
section = document.add_section(start_type_)
@@ -167,15 +158,6 @@ def it_creates_numbering_part_on_first_access_if_not_present(
167158

168159
# fixtures -------------------------------------------------------
169160

170-
@pytest.fixture
171-
def add_picture_fixture(self, request, run_, picture_):
172-
document = Document()
173-
image_path_ = instance_mock(request, str, name='image_path_')
174-
width, height = 100, 200
175-
class_mock(request, 'docx.text.paragraph.Run', return_value=run_)
176-
run_.add_picture.return_value = picture_
177-
return (document, image_path_, width, height, run_, picture_)
178-
179161
@pytest.fixture
180162
def add_section_fixture(self, document, start_type_, section_):
181163
return document, start_type_, section_
@@ -295,10 +277,6 @@ def package_(self, request, document_part_):
295277
def paragraphs_(self, request):
296278
return instance_mock(request, list)
297279

298-
@pytest.fixture
299-
def picture_(self, request):
300-
return instance_mock(request, InlineShape)
301-
302280
@pytest.fixture
303281
def run_(self, request):
304282
return instance_mock(request, Run)

0 commit comments

Comments
 (0)