Skip to content

Commit 08703b6

Browse files
author
Steve Canny
committed
acpt: migrate doc-add-picture.feature
1 parent 99c713f commit 08703b6

File tree

4 files changed

+63
-63
lines changed

4 files changed

+63
-63
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,30 @@
1-
Feature: Append an inline picture on its own paragraph
1+
Feature: Append an inline picture in its own paragraph
22
In order add an image to a document
3-
As a programmer using the basic python-docx API
4-
I need a method that adds a picture in its own paragraph
3+
As a developer using python-docx
4+
I need a way to add a picture in its own paragraph
5+
56

67
Scenario: Add a picture at native size
7-
Given a document
8+
Given a blank document
89
When I add a picture specifying only the image file
910
Then the document contains the inline picture
1011
And the picture has its native width and height
1112

13+
1214
Scenario: Add a picture specifying both width and height
13-
Given a document
15+
Given a blank document
1416
When I add a picture specifying 1.75" width and 2.5" height
15-
Then the picture width is 1.75 inches
16-
And the picture height is 2.5 inches
17+
Then picture.width is 1.75 inches
18+
And picture.height is 2.5 inches
19+
1720

1821
Scenario: Add a picture specifying only width
19-
Given a document
22+
Given a blank document
2023
When I add a picture specifying a width of 1.5 inches
21-
Then the picture height is 2.14 inches
24+
Then picture.height is 2.14 inches
25+
2226

2327
Scenario: Add a picture specifying only height
24-
Given a document
28+
Given a blank document
2529
When I add a picture specifying a height of 1.5 inches
26-
Then the picture width is 1.05 inches
30+
Then picture.width is 1.05 inches

features/steps/api.py

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,9 @@
99
import docx
1010

1111
from docx import DocumentNew
12-
from docx.shared import Inches
1312
from docx.table import Table
1413

15-
from helpers import test_docx, test_file
14+
from helpers import test_docx
1615

1716

1817
# given ====================================================
@@ -36,37 +35,6 @@ def when_add_2x2_table_specifying_style_name(context, style_name):
3635
document.add_table(rows=2, cols=2, style=style_name)
3736

3837

39-
@when('I add a picture specifying 1.75" width and 2.5" height')
40-
def when_add_picture_specifying_width_and_height(context):
41-
document = context.document
42-
context.picture = document.add_picture(
43-
test_file('monty-truth.png'),
44-
width=Inches(1.75), height=Inches(2.5)
45-
)
46-
47-
48-
@when('I add a picture specifying a height of 1.5 inches')
49-
def when_add_picture_specifying_height(context):
50-
document = context.document
51-
context.picture = document.add_picture(
52-
test_file('monty-truth.png'), height=Inches(1.5)
53-
)
54-
55-
56-
@when('I add a picture specifying a width of 1.5 inches')
57-
def when_add_picture_specifying_width(context):
58-
document = context.document
59-
context.picture = document.add_picture(
60-
test_file('monty-truth.png'), width=Inches(1.5)
61-
)
62-
63-
64-
@when('I add a picture specifying only the image file')
65-
def when_add_picture_specifying_only_image_file(context):
66-
document = context.document
67-
context.picture = document.add_picture(test_file('monty-truth.png'))
68-
69-
7038
@when('I call docx.Document() with no arguments')
7139
def when_I_call_docx_Document_with_no_arguments(context):
7240
context.document = DocumentNew()

features/steps/document.py

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@
1212
from docx.enum.section import WD_ORIENT, WD_SECTION
1313
from docx.parts.document import Sections
1414
from docx.section import Section
15+
from docx.shared import Inches
1516

16-
from helpers import test_docx
17+
from helpers import test_docx, test_file
1718

1819

1920
# given ===================================================
@@ -85,6 +86,37 @@ def when_add_paragraph_without_specifying_text_or_style(context):
8586
document.add_paragraph()
8687

8788

89+
@when('I add a picture specifying 1.75" width and 2.5" height')
90+
def when_add_picture_specifying_width_and_height(context):
91+
document = context.document
92+
context.picture = document.add_picture(
93+
test_file('monty-truth.png'),
94+
width=Inches(1.75), height=Inches(2.5)
95+
)
96+
97+
98+
@when('I add a picture specifying a height of 1.5 inches')
99+
def when_add_picture_specifying_height(context):
100+
document = context.document
101+
context.picture = document.add_picture(
102+
test_file('monty-truth.png'), height=Inches(1.5)
103+
)
104+
105+
106+
@when('I add a picture specifying a width of 1.5 inches')
107+
def when_add_picture_specifying_width(context):
108+
document = context.document
109+
context.picture = document.add_picture(
110+
test_file('monty-truth.png'), width=Inches(1.5)
111+
)
112+
113+
114+
@when('I add a picture specifying only the image file')
115+
def when_add_picture_specifying_only_image_file(context):
116+
document = context.document
117+
context.picture = document.add_picture(test_file('monty-truth.png'))
118+
119+
88120
@when('I add an even-page section to the document')
89121
def when_I_add_an_even_page_section_to_the_document(context):
90122
context.section = context.document.add_section(WD_SECTION.EVEN_PAGE)

features/steps/shape.py

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -164,25 +164,21 @@ def then_picture_has_native_width_and_height(context):
164164
assert picture.height == 2717800, 'got %d' % picture.height
165165

166166

167-
@then('the picture height is 2.14 inches')
168-
def then_picture_height_is_value_2(context):
169-
picture = context.picture
170-
assert picture.height == 1956816, 'got %d' % picture.height
171-
172-
173-
@then('the picture height is 2.5 inches')
174-
def then_picture_height_is_value(context):
175-
picture = context.picture
176-
assert picture.height == 2286000, 'got %d' % picture.height
177-
178-
179-
@then('the picture width is 1.05 inches')
180-
def then_picture_width_is_value_2(context):
167+
@then('picture.height is {inches} inches')
168+
def then_picture_height_is_value(context, inches):
169+
expected_value = {
170+
'2.14': 1956816,
171+
'2.5': 2286000,
172+
}[inches]
181173
picture = context.picture
182-
assert picture.width == 961402, 'got %d' % picture.width
174+
assert picture.height == expected_value, 'got %d' % picture.height
183175

184176

185-
@then('the picture width is 1.75 inches')
186-
def then_picture_width_is_value(context):
177+
@then('picture.width is {inches} inches')
178+
def then_picture_width_is_value(context, inches):
179+
expected_value = {
180+
'1.05': 961402,
181+
'1.75': 1600200,
182+
}[inches]
187183
picture = context.picture
188-
assert picture.width == 1600200, 'got %d' % picture.width
184+
assert picture.width == expected_value, 'got %d' % picture.width

0 commit comments

Comments
 (0)