11"""Step implementations for footnote-related features."""
22
3- from behave import given , when , then
3+ from behave import given , then , when
44from behave .runner import Context
55
66from docx import Document
@@ -44,7 +44,9 @@ def given_a_paragraph_in_a_document_without_footnotes(context: Context):
4444 context .footnotes = document .footnotes
4545
4646
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+ )
4850def given_a_document_with_3_footnotes (context : Context ):
4951 document = Document (test_docx ("footnotes" ))
5052 context .paragraphs = document .paragraphs
@@ -64,14 +66,18 @@ def when_I_try_to_access_a_footnote_with_invalid_reference_id(context: Context):
6466
6567
6668@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+ ):
6872 par = context .paragraphs [int (parId )]
6973 new_footnote = par .add_footnote ()
7074 new_footnote .add_paragraph (footnoteText )
7175
7276
7377@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+ ):
7581 context .section .__setattr__ (propName , eval (value ))
7682
7783
@@ -81,7 +87,9 @@ def when_I_change_footnote_property_propName_to_value(context: Context, propName
8187@then ("len(footnotes) is {expectedLen}" )
8288def then_len_footnotes_is_len (context : Context , expectedLen : str ):
8389 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 )} "
8593
8694
8795@then ("I can access a footnote by footnote reference id" )
@@ -107,35 +115,57 @@ def then_it_trows_an_IndexError(context: Context, exceptionType: str):
107115
108116
109117@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+ ):
111121 actual_value = context .section .__getattribute__ (propName )
112122 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 } "
114126
115127
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+ ):
118134 par = context .paragraphs [1 ]
119135 f = par .footnotes [0 ]
120136 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 } "
122140
123141
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+ ):
126148 par = context .paragraphs [int (parId )]
127149 refIds = eval (refIds )
128150 fText = eval (fText )
129151 if refIds is not None :
130152 if type (refIds ) is list :
131153 for i in range (len (refIds )):
132154 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 )} "
134158 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 } '"
136162 else :
137163 f = par .footnotes [0 ]
138164 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 } '"
140168 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