|
8 | 8 |
|
9 | 9 | from docx import Document |
10 | 10 | from docx.enum.text import WD_ALIGN_PARAGRAPH |
11 | | -from docx.oxml import parse_xml |
12 | | -from docx.oxml.ns import nsdecls |
13 | | -from docx.text.paragraph import Paragraph |
14 | 11 |
|
15 | 12 | from helpers import saved_docx_path, test_docx, test_text |
16 | 13 |
|
17 | 14 |
|
18 | | -TEST_STYLE = 'Heading1' |
19 | | - |
20 | | - |
21 | 15 | # given =================================================== |
22 | 16 |
|
23 | 17 | @given('a document containing three paragraphs') |
@@ -56,17 +50,8 @@ def given_a_paragraph_having_style(context, style_state): |
56 | 50 |
|
57 | 51 | @given('a paragraph with content and formatting') |
58 | 52 | def given_a_paragraph_with_content_and_formatting(context): |
59 | | - p_xml = """\ |
60 | | - <w:p %s> |
61 | | - <w:pPr> |
62 | | - <w:pStyle w:val="%s"/> |
63 | | - </w:pPr> |
64 | | - <w:r> |
65 | | - <w:t>foobar</w:t> |
66 | | - </w:r> |
67 | | - </w:p>""" % (nsdecls('w'), TEST_STYLE) |
68 | | - p = parse_xml(p_xml) |
69 | | - context.paragraph = Paragraph(p, None) |
| 53 | + document = Document(test_docx('par-known-paragraphs')) |
| 54 | + context.paragraph = document.paragraphs[0] |
70 | 55 |
|
71 | 56 |
|
72 | 57 | # when ==================================================== |
@@ -144,7 +129,8 @@ def then_the_paragraph_alignment_prop_value_is_value(context, align_value): |
144 | 129 |
|
145 | 130 | @then('the paragraph formatting is preserved') |
146 | 131 | def then_the_paragraph_formatting_is_preserved(context): |
147 | | - assert context.paragraph.style == TEST_STYLE |
| 132 | + paragraph = context.paragraph |
| 133 | + assert paragraph.style.name == 'Heading 1' |
148 | 134 |
|
149 | 135 |
|
150 | 136 | @then('the paragraph has no content') |
|
0 commit comments