1
1
"""Step implementations for footnote-related features."""
2
2
3
- from behave import given , when , then
3
+ from behave import given , then , when
4
4
from behave .runner import Context
5
5
6
6
from docx import Document
@@ -44,7 +44,9 @@ def given_a_paragraph_in_a_document_without_footnotes(context: Context):
44
44
context .footnotes = document .footnotes
45
45
46
46
47
- @given ("a document with paragraphs[0] containing one, paragraphs[1] containing none, and paragraphs[2] containing two footnotes" )
47
+ @given (
48
+ "a document with paragraphs[0] containing one, paragraphs[1] containing none, and paragraphs[2] containing two footnotes"
49
+ )
48
50
def given_a_document_with_3_footnotes (context : Context ):
49
51
document = Document (test_docx ("footnotes" ))
50
52
context .paragraphs = document .paragraphs
@@ -64,14 +66,18 @@ def when_I_try_to_access_a_footnote_with_invalid_reference_id(context: Context):
64
66
65
67
66
68
@when ("I add a footnote to the paragraphs[{parId}] with text '{footnoteText}'" )
67
- def when_I_add_a_footnote_to_the_paragraph_with_text_text (context : Context , parId : str , footnoteText : str ):
69
+ def when_I_add_a_footnote_to_the_paragraph_with_text_text (
70
+ context : Context , parId : str , footnoteText : str
71
+ ):
68
72
par = context .paragraphs [int (parId )]
69
73
new_footnote = par .add_footnote ()
70
74
new_footnote .add_paragraph (footnoteText )
71
75
72
76
73
77
@when ("I change footnote property {propName} to {value}" )
74
- def when_I_change_footnote_property_propName_to_value (context : Context , propName : str , value : str ):
78
+ def when_I_change_footnote_property_propName_to_value (
79
+ context : Context , propName : str , value : str
80
+ ):
75
81
context .section .__setattr__ (propName , eval (value ))
76
82
77
83
@@ -81,7 +87,9 @@ def when_I_change_footnote_property_propName_to_value(context: Context, propName
81
87
@then ("len(footnotes) is {expectedLen}" )
82
88
def then_len_footnotes_is_len (context : Context , expectedLen : str ):
83
89
footnotes = context .footnotes
84
- assert len (footnotes ) == int (expectedLen ), f"expected len(footnotes) of { expectedLen } , got { len (footnotes )} "
90
+ assert len (footnotes ) == int (
91
+ expectedLen
92
+ ), f"expected len(footnotes) of { expectedLen } , got { len (footnotes )} "
85
93
86
94
87
95
@then ("I can access a footnote by footnote reference id" )
@@ -107,35 +115,57 @@ def then_it_trows_an_IndexError(context: Context, exceptionType: str):
107
115
108
116
109
117
@then ("I can access footnote property {propName} with value {value}" )
110
- def then_I_can_access_footnote_propery_name_with_value_value (context : Context , propName : str , value : str ):
118
+ def then_I_can_access_footnote_propery_name_with_value_value (
119
+ context : Context , propName : str , value : str
120
+ ):
111
121
actual_value = context .section .__getattribute__ (propName )
112
122
expected = eval (value )
113
- assert actual_value == expected , f"expected section.{ propName } { value } , got { expected } "
123
+ assert (
124
+ actual_value == expected
125
+ ), f"expected section.{ propName } { value } , got { expected } "
114
126
115
127
116
- @then ("the document contains a footnote with footnote reference id of {refId} with text '{footnoteText}'" )
117
- def then_the_document_contains_a_footnote_with_footnote_reference_id_of_refId_with_text_text (context : Context , refId : str , footnoteText : str ):
128
+ @then (
129
+ "the document contains a footnote with footnote reference id of {refId} with text '{footnoteText}'"
130
+ )
131
+ def then_the_document_contains_a_footnote_with_footnote_reference_id_of_refId_with_text_text (
132
+ context : Context , refId : str , footnoteText : str
133
+ ):
118
134
par = context .paragraphs [1 ]
119
135
f = par .footnotes [0 ]
120
136
assert f .id == int (refId ), f"expected { refId } , got { f .id } "
121
- assert f .paragraphs [0 ].text == footnoteText , f"expected { footnoteText } , got { f .paragraphs [0 ].text } "
137
+ assert (
138
+ f .paragraphs [0 ].text == footnoteText
139
+ ), f"expected { footnoteText } , got { f .paragraphs [0 ].text } "
122
140
123
141
124
- @then ("paragraphs[{parId}] has footnote reference ids of {refIds}, with footnote text {fText}" )
125
- def then_paragraph_has_footnote_reference_ids_of_refIds_with_footnote_text_text (context : Context , parId : str , refIds : str , fText : str ):
142
+ @then (
143
+ "paragraphs[{parId}] has footnote reference ids of {refIds}, with footnote text {fText}"
144
+ )
145
+ def then_paragraph_has_footnote_reference_ids_of_refIds_with_footnote_text_text (
146
+ context : Context , parId : str , refIds : str , fText : str
147
+ ):
126
148
par = context .paragraphs [int (parId )]
127
149
refIds = eval (refIds )
128
150
fText = eval (fText )
129
151
if refIds is not None :
130
152
if type (refIds ) is list :
131
153
for i in range (len (refIds )):
132
154
f = par .footnotes [i ]
133
- assert isinstance (f , Footnote ), f"expected to be instance of Footnote, got { type (f )} "
155
+ assert isinstance (
156
+ f , Footnote
157
+ ), f"expected to be instance of Footnote, got { type (f )} "
134
158
assert f .id == refIds [i ], f"expected { refIds [i ]} , got { f .id } "
135
- assert f .paragraphs [0 ].text == fText [i ], f"expected '{ fText [i ]} ', got '{ f .paragraphs [0 ].text } '"
159
+ assert (
160
+ f .paragraphs [0 ].text == fText [i ]
161
+ ), f"expected '{ fText [i ]} ', got '{ f .paragraphs [0 ].text } '"
136
162
else :
137
163
f = par .footnotes [0 ]
138
164
assert f .id == int (refIds ), f"expected { refIds } , got { f .id } "
139
- assert f .paragraphs [0 ].text == fText , f"expected '{ fText } ', got '{ f .paragraphs [0 ].text } '"
165
+ assert (
166
+ f .paragraphs [0 ].text == fText
167
+ ), f"expected '{ fText } ', got '{ f .paragraphs [0 ].text } '"
140
168
else :
141
- assert len (par .footnotes ) == 0 , f"expected an empty list, got { len (par .footnotes )} elements"
169
+ assert (
170
+ len (par .footnotes ) == 0
171
+ ), f"expected an empty list, got { len (par .footnotes )} elements"
0 commit comments