Skip to content

Commit 12336e7

Browse files
author
Steve Canny
committed
img: final fixups to pass acceptance test
1 parent dde7784 commit 12336e7

File tree

7 files changed

+16
-11
lines changed

7 files changed

+16
-11
lines changed

docx/api.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class _Document(object):
3939
"""
4040
def __init__(self, package, document_part):
4141
super(_Document, self).__init__()
42-
self._document = document_part
42+
self._document_part = document_part
4343
self._package = package
4444

4545
def add_inline_picture(self, image_path_or_stream):
@@ -55,14 +55,14 @@ def body(self):
5555
"""
5656
Return a reference to the |_Body| instance for this document.
5757
"""
58-
return self._document.body
58+
return self._document_part.body
5959

6060
@property
6161
def inline_shapes(self):
6262
"""
6363
Return a reference to the |InlineShapes| instance for this document.
6464
"""
65-
return self._document.inline_shapes
65+
return self._document_part.inline_shapes
6666

6767
def save(self, file_):
6868
"""

docx/oxml/shape.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ class CT_Blip(OxmlBaseElement):
1414
``<a:blip>`` element, specifies image source and adjustments such as
1515
alpha and tint.
1616
"""
17+
@property
18+
def embed(self):
19+
return self.get(qn('r:embed'))
20+
1721
@property
1822
def link(self):
1923
return self.get(qn('r:link'))

docx/parts/image.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,8 +259,7 @@ def load(cls, partname, content_type, blob, package):
259259
Called by ``docx.opc.package.PartFactory`` to load an image part from
260260
a package being opened by ``Document(...)`` call.
261261
"""
262-
image_part = cls(partname, content_type, blob)
263-
return image_part
262+
return cls(partname, content_type, blob)
264263

265264
@property
266265
def sha1(self):

features/shp-add-inline-picture.feature

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ Feature: Add inline picture
33
As a python-docx developer
44
I need the ability to add an inline picture to a document
55

6-
@wip
76
Scenario: Add inline picture to document
87
Given a document
98
When I add an inline picture to the document

features/steps/shape.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,9 @@ def then_the_document_contains_the_inline_picture(context):
104104
picture_shape = document.inline_shapes[0]
105105
blip = picture_shape._inline.graphic.graphicData.pic.blipFill.blip
106106
rId = blip.embed
107-
image_part = document.related_parts[rId]
107+
image_part = document._document_part.related_parts[rId]
108108
image_sha1 = hashlib.sha1(image_part.blob).hexdigest()
109-
expected_sha1 = '92abcF0eab86674as0e029342309023423'
109+
expected_sha1 = '79769f1e202add2e963158b532e36c2c0f76a70c'
110110
assert image_sha1 == expected_sha1, (
111111
"image SHA1 doesn't match, expected %s, got %s" %
112112
(expected_sha1, image_sha1)

tests/test_api.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,11 @@ class Describe_Document(object):
7575

7676
def it_provides_access_to_the_document_body(self, document):
7777
body = document.body
78-
assert body is document._document.body
78+
assert body is document._document_part.body
7979

8080
def it_provides_access_to_the_document_inline_shapes(self, document):
8181
body = document.inline_shapes
82-
assert body is document._document.inline_shapes
82+
assert body is document._document_part.inline_shapes
8383

8484
def it_can_add_an_inline_picture(self, add_picture_fixture):
8585
document, inline_shapes, image_path_or_stream_, picture_shape_ = (

tests/test_package.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ class DescribePackage(object):
2121

2222
def it_gathers_package_image_parts_after_unmarshalling(self):
2323
package = Package.open(docx_path('having-images'))
24-
assert len(package.image_parts) == 3
24+
image_parts = package.image_parts
25+
assert len(image_parts) == 3
26+
for image_part in image_parts:
27+
assert isinstance(image_part, ImagePart)
2528

2629

2730
class DescribeImageParts(object):

0 commit comments

Comments
 (0)