Skip to content

Commit 592fa8f

Browse files
committed
modn: improve ruff compliance
Run `ruff format` on code base.
1 parent afa670a commit 592fa8f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+383
-906
lines changed

docs/conf.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -270,9 +270,7 @@
270270

271271
# Custom sidebar templates, maps document names to template names.
272272
# html_sidebars = {}
273-
html_sidebars = {
274-
"**": ["localtoc.html", "relations.html", "sidebarlinks.html", "searchbox.html"]
275-
}
273+
html_sidebars = {"**": ["localtoc.html", "relations.html", "sidebarlinks.html", "searchbox.html"]}
276274

277275
# Additional templates that should be rendered to pages, maps page names to
278276
# template names.

features/steps/block.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@
1313

1414
@given("a _Cell object with paragraphs and tables")
1515
def given_a_cell_with_paragraphs_and_tables(context: Context):
16-
context.cell = (
17-
Document(test_docx("blk-paras-and-tables")).tables[1].rows[0].cells[0]
18-
)
16+
context.cell = Document(test_docx("blk-paras-and-tables")).tables[1].rows[0].cells[0]
1917

2018

2119
@given("a Document object with paragraphs and tables")

features/steps/document.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -126,17 +126,13 @@ def when_add_picture_specifying_width_and_height(context):
126126
@when("I add a picture specifying a height of 1.5 inches")
127127
def when_add_picture_specifying_height(context):
128128
document = context.document
129-
context.picture = document.add_picture(
130-
test_file("monty-truth.png"), height=Inches(1.5)
131-
)
129+
context.picture = document.add_picture(test_file("monty-truth.png"), height=Inches(1.5))
132130

133131

134132
@when("I add a picture specifying a width of 1.5 inches")
135133
def when_add_picture_specifying_width(context):
136134
document = context.document
137-
context.picture = document.add_picture(
138-
test_file("monty-truth.png"), width=Inches(1.5)
139-
)
135+
context.picture = document.add_picture(test_file("monty-truth.png"), width=Inches(1.5))
140136

141137

142138
@when("I add a picture specifying only the image file")

features/steps/hyperlink.py

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,7 @@ def given_a_hyperlink_having_a_uri_fragment(context: Context):
2727

2828

2929
@given("a hyperlink having address {address} and fragment {fragment}")
30-
def given_a_hyperlink_having_address_and_fragment(
31-
context: Context, address: str, fragment: str
32-
):
30+
def given_a_hyperlink_having_address_and_fragment(context: Context, address: str, fragment: str):
3331
paragraph_idxs: Dict[Tuple[str, str], int] = {
3432
("''", "linkedBookmark"): 1,
3533
("https://foo.com", "''"): 2,
@@ -73,60 +71,46 @@ def given_a_hyperlink_having_one_or_more_runs(context: Context, one_or_more: str
7371
def then_hyperlink_address_is_the_URL_of_the_hyperlink(context: Context):
7472
actual_value = context.hyperlink.address
7573
expected_value = "http://yahoo.com/"
76-
assert (
77-
actual_value == expected_value
78-
), f"expected: {expected_value}, got: {actual_value}"
74+
assert actual_value == expected_value, f"expected: {expected_value}, got: {actual_value}"
7975

8076

8177
@then("hyperlink.contains_page_break is {value}")
8278
def then_hyperlink_contains_page_break_is_value(context: Context, value: str):
8379
actual_value = context.hyperlink.contains_page_break
8480
expected_value = {"True": True, "False": False}[value]
85-
assert (
86-
actual_value == expected_value
87-
), f"expected: {expected_value}, got: {actual_value}"
81+
assert actual_value == expected_value, f"expected: {expected_value}, got: {actual_value}"
8882

8983

9084
@then("hyperlink.fragment is the URI fragment of the hyperlink")
9185
def then_hyperlink_fragment_is_the_URI_fragment_of_the_hyperlink(context: Context):
9286
actual_value = context.hyperlink.fragment
9387
expected_value = "linkedBookmark"
94-
assert (
95-
actual_value == expected_value
96-
), f"expected: {expected_value}, got: {actual_value}"
88+
assert actual_value == expected_value, f"expected: {expected_value}, got: {actual_value}"
9789

9890

9991
@then("hyperlink.runs contains only Run instances")
10092
def then_hyperlink_runs_contains_only_Run_instances(context: Context):
10193
actual_value = [type(item).__name__ for item in context.hyperlink.runs]
10294
expected_value = ["Run" for _ in context.hyperlink.runs]
103-
assert (
104-
actual_value == expected_value
105-
), f"expected: {expected_value}, got: {actual_value}"
95+
assert actual_value == expected_value, f"expected: {expected_value}, got: {actual_value}"
10696

10797

10898
@then("hyperlink.runs has length {value}")
10999
def then_hyperlink_runs_has_length(context: Context, value: str):
110100
actual_value = len(context.hyperlink.runs)
111101
expected_value = int(value)
112-
assert (
113-
actual_value == expected_value
114-
), f"expected: {expected_value}, got: {actual_value}"
102+
assert actual_value == expected_value, f"expected: {expected_value}, got: {actual_value}"
115103

116104

117105
@then("hyperlink.text is the visible text of the hyperlink")
118106
def then_hyperlink_text_is_the_visible_text_of_the_hyperlink(context: Context):
119107
actual_value = context.hyperlink.text
120108
expected_value = "awesome hyperlink"
121-
assert (
122-
actual_value == expected_value
123-
), f"expected: {expected_value}, got: {actual_value}"
109+
assert actual_value == expected_value, f"expected: {expected_value}, got: {actual_value}"
124110

125111

126112
@then("hyperlink.url is {value}")
127113
def then_hyperlink_url_is_value(context: Context, value: str):
128114
actual_value = context.hyperlink.url
129115
expected_value = "" if value == "''" else value
130-
assert (
131-
actual_value == expected_value
132-
), f"expected: {expected_value}, got: {actual_value}"
116+
assert actual_value == expected_value, f"expected: {expected_value}, got: {actual_value}"

features/steps/pagebreak.py

Lines changed: 18 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -38,33 +38,23 @@ def then_rendered_page_break_preceding_paragraph_fragment_includes_the_hyperlink
3838

3939
actual_value = type(para_frag).__name__
4040
expected_value = "Paragraph"
41-
assert (
42-
actual_value == expected_value
43-
), f"expected: '{expected_value}', got: '{actual_value}'"
41+
assert actual_value == expected_value, f"expected: '{expected_value}', got: '{actual_value}'"
4442

4543
actual_value = para_frag.text
4644
expected_value = "Page break in>><<this hyperlink"
47-
assert (
48-
actual_value == expected_value
49-
), f"expected: '{expected_value}', got: '{actual_value}'"
45+
assert actual_value == expected_value, f"expected: '{expected_value}', got: '{actual_value}'"
5046

5147
actual_value = para_frag.alignment
5248
expected_value = WD_PARAGRAPH_ALIGNMENT.RIGHT # pyright: ignore
53-
assert (
54-
actual_value == expected_value
55-
), f"expected: '{expected_value}', got: '{actual_value}'"
49+
assert actual_value == expected_value, f"expected: '{expected_value}', got: '{actual_value}'"
5650

5751
actual_value = para_frag.hyperlinks[0].runs[0].style.name
5852
expected_value = "Hyperlink"
59-
assert (
60-
actual_value == expected_value
61-
), f"expected: '{expected_value}', got: '{actual_value}'"
53+
assert actual_value == expected_value, f"expected: '{expected_value}', got: '{actual_value}'"
6254

6355
actual_value = para_frag.hyperlinks[0].address
6456
expected_value = "http://google.com/"
65-
assert (
66-
actual_value == expected_value
67-
), f"expected: '{expected_value}', got: '{actual_value}'"
57+
assert actual_value == expected_value, f"expected: '{expected_value}', got: '{actual_value}'"
6858

6959

7060
@then("rendered_page_break.preceding_paragraph_fragment is the content before break")
@@ -75,27 +65,19 @@ def then_rendered_page_break_preceding_paragraph_fragment_is_the_content_before_
7565

7666
actual_value = type(para_frag).__name__
7767
expected_value = "Paragraph"
78-
assert (
79-
actual_value == expected_value
80-
), f"expected: '{expected_value}', got: '{actual_value}'"
68+
assert actual_value == expected_value, f"expected: '{expected_value}', got: '{actual_value}'"
8169

8270
actual_value = para_frag.text
8371
expected_value = "Page break here>>"
84-
assert (
85-
actual_value == expected_value
86-
), f"expected: '{expected_value}', got: '{actual_value}'"
72+
assert actual_value == expected_value, f"expected: '{expected_value}', got: '{actual_value}'"
8773

8874
actual_value = para_frag.alignment
8975
expected_value = WD_PARAGRAPH_ALIGNMENT.CENTER # pyright: ignore
90-
assert (
91-
actual_value == expected_value
92-
), f"expected: '{expected_value}', got: '{actual_value}'"
76+
assert actual_value == expected_value, f"expected: '{expected_value}', got: '{actual_value}'"
9377

9478
actual_value = para_frag.runs[0].style.name
9579
expected_value = "Default Paragraph Font"
96-
assert (
97-
actual_value == expected_value
98-
), f"expected: '{expected_value}', got: '{actual_value}'"
80+
assert actual_value == expected_value, f"expected: '{expected_value}', got: '{actual_value}'"
9981

10082

10183
@then("rendered_page_break.following_paragraph_fragment excludes the hyperlink")
@@ -107,37 +89,27 @@ def then_rendered_page_break_following_paragraph_fragment_excludes_the_hyperlink
10789
# -- paragraph fragment is a Paragraph object --
10890
actual_value = type(para_frag).__name__
10991
expected_value = "Paragraph"
110-
assert (
111-
actual_value == expected_value
112-
), f"expected: '{expected_value}', got: '{actual_value}'"
92+
assert actual_value == expected_value, f"expected: '{expected_value}', got: '{actual_value}'"
11393

11494
# -- paragraph text is only the fragment after the page-break --
11595
actual_value = para_frag.text
11696
expected_value = " and another one here>><<with text following"
117-
assert (
118-
actual_value == expected_value
119-
), f"expected: '{expected_value}', got: '{actual_value}'"
97+
assert actual_value == expected_value, f"expected: '{expected_value}', got: '{actual_value}'"
12098

12199
# -- paragraph properties are preserved --
122100
actual_value = para_frag.alignment
123101
expected_value = WD_PARAGRAPH_ALIGNMENT.RIGHT # pyright: ignore
124-
assert (
125-
actual_value == expected_value
126-
), f"expected: '{expected_value}', got: '{actual_value}'"
102+
assert actual_value == expected_value, f"expected: '{expected_value}', got: '{actual_value}'"
127103

128104
# -- paragraph has no hyperlinks --
129105
actual_value = para_frag.hyperlinks
130106
expected_value = []
131-
assert (
132-
actual_value == expected_value
133-
), f"expected: '{expected_value}', got: '{actual_value}'"
107+
assert actual_value == expected_value, f"expected: '{expected_value}', got: '{actual_value}'"
134108

135109
# -- following paragraph fragment retains any remaining page-breaks --
136110
actual_value = [type(rpb).__name__ for rpb in para_frag.rendered_page_breaks]
137111
expected_value = ["RenderedPageBreak"]
138-
assert (
139-
actual_value == expected_value
140-
), f"expected: '{expected_value}', got: '{actual_value}'"
112+
assert actual_value == expected_value, f"expected: '{expected_value}', got: '{actual_value}'"
141113

142114

143115
@then("rendered_page_break.following_paragraph_fragment is the content after break")
@@ -148,24 +120,16 @@ def then_rendered_page_break_following_paragraph_fragment_is_the_content_after_b
148120

149121
actual_value = type(para_frag).__name__
150122
expected_value = "Paragraph"
151-
assert (
152-
actual_value == expected_value
153-
), f"expected: '{expected_value}', got: '{actual_value}'"
123+
assert actual_value == expected_value, f"expected: '{expected_value}', got: '{actual_value}'"
154124

155125
actual_value = para_frag.text
156126
expected_value = "<<followed by more text."
157-
assert (
158-
actual_value == expected_value
159-
), f"expected: '{expected_value}', got: '{actual_value}'"
127+
assert actual_value == expected_value, f"expected: '{expected_value}', got: '{actual_value}'"
160128

161129
actual_value = para_frag.alignment
162130
expected_value = WD_PARAGRAPH_ALIGNMENT.CENTER # pyright: ignore
163-
assert (
164-
actual_value == expected_value
165-
), f"expected: '{expected_value}', got: '{actual_value}'"
131+
assert actual_value == expected_value, f"expected: '{expected_value}', got: '{actual_value}'"
166132

167133
actual_value = para_frag.runs[0].style.name
168134
expected_value = "Default Paragraph Font"
169-
assert (
170-
actual_value == expected_value
171-
), f"expected: '{expected_value}', got: '{actual_value}'"
135+
assert actual_value == expected_value, f"expected: '{expected_value}', got: '{actual_value}'"

features/steps/paragraph.py

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -120,16 +120,12 @@ def when_I_set_the_paragraph_text(context: Context):
120120
def then_paragraph_contains_page_break_is_value(context: Context, value: str):
121121
actual_value = context.paragraph.contains_page_break
122122
expected_value = {"True": True, "False": False}[value]
123-
assert (
124-
actual_value == expected_value
125-
), f"expected: {expected_value}, got: {actual_value}"
123+
assert actual_value == expected_value, f"expected: {expected_value}, got: {actual_value}"
126124

127125

128126
@then("paragraph.hyperlinks contains only Hyperlink instances")
129127
def then_paragraph_hyperlinks_contains_only_Hyperlink_instances(context: Context):
130-
assert all(
131-
type(item).__name__ == "Hyperlink" for item in context.paragraph.hyperlinks
132-
)
128+
assert all(type(item).__name__ == "Hyperlink" for item in context.paragraph.hyperlinks)
133129

134130

135131
@then("paragraph.hyperlinks has length {value}")
@@ -163,9 +159,7 @@ def then_paragraph_paragraph_format_is_its_parfmt_object(context: Context):
163159
def then_paragraph_rendered_page_breaks_has_length(context: Context, value: str):
164160
actual_value = len(context.paragraph.rendered_page_breaks)
165161
expected_value = int(value)
166-
assert (
167-
actual_value == expected_value
168-
), f"got: {actual_value}, expected: {expected_value}"
162+
assert actual_value == expected_value, f"got: {actual_value}, expected: {expected_value}"
169163

170164

171165
@then("paragraph.rendered_page_breaks contains only RenderedPageBreak instances")
@@ -216,9 +210,7 @@ def then_document_contains_text_I_added(context: Context):
216210

217211

218212
@then("the paragraph alignment property value is {align_value}")
219-
def then_the_paragraph_alignment_prop_value_is_value(
220-
context: Context, align_value: str
221-
):
213+
def then_the_paragraph_alignment_prop_value_is_value(context: Context, align_value: str):
222214
expected_value: Any = {
223215
"None": None,
224216
"WD_ALIGN_PARAGRAPH.LEFT": WD_PARAGRAPH_ALIGNMENT.LEFT, # pyright: ignore

features/steps/parfmt.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,9 +160,7 @@ def then_paragraph_format_alignment_is_value(context, value):
160160

161161
@then("paragraph_format.line_spacing is {value}")
162162
def then_paragraph_format_line_spacing_is_value(context, value):
163-
expected_value = (
164-
None if value == "None" else float(value) if "." in value else int(value)
165-
)
163+
expected_value = None if value == "None" else float(value) if "." in value else int(value)
166164
paragraph_format = context.paragraph_format
167165

168166
if expected_value is None or isinstance(expected_value, int):

features/steps/section.py

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,7 @@ def given_a_section_having_known_orientation(context: Context, orientation: str)
7373

7474

7575
@when("I assign {bool_val} to section.different_first_page_header_footer")
76-
def when_I_assign_value_to_section_different_first_page_hdrftr(
77-
context: Context, bool_val: str
78-
):
76+
def when_I_assign_value_to_section_different_first_page_hdrftr(context: Context, bool_val: str):
7977
context.section.different_first_page_header_footer = eval(bool_val)
8078

8179

@@ -158,9 +156,7 @@ def then_len_sections_is_3(context: Context):
158156
def then_section_different_first_page_header_footer_is(context: Context, bool_val: str):
159157
actual = context.section.different_first_page_header_footer
160158
expected = eval(bool_val)
161-
assert actual == expected, (
162-
"section.different_first_page_header_footer is %s" % actual
163-
)
159+
assert actual == expected, "section.different_first_page_header_footer is %s" % actual
164160

165161

166162
@then("section.even_page_footer is a _Footer object")
@@ -213,9 +209,7 @@ def step_impl(context: Context):
213209

214210

215211
@then("section.{propname}.is_linked_to_previous is True")
216-
def then_section_hdrftr_prop_is_linked_to_previous_is_True(
217-
context: Context, propname: str
218-
):
212+
def then_section_hdrftr_prop_is_linked_to_previous_is_True(context: Context, propname: str):
219213
actual = getattr(context.section, propname).is_linked_to_previous
220214
expected = True
221215
assert actual == expected, "section.%s.is_linked_to_previous is %s" % (
@@ -241,9 +235,7 @@ def then_the_reported_margin_is_inches(context: Context, margin_side: str, inche
241235

242236

243237
@then("the reported page orientation is {orientation}")
244-
def then_the_reported_page_orientation_is_orientation(
245-
context: Context, orientation: str
246-
):
238+
def then_the_reported_page_orientation_is_orientation(context: Context, orientation: str):
247239
expected_value = {
248240
"WD_ORIENT.LANDSCAPE": WD_ORIENT.LANDSCAPE,
249241
"WD_ORIENT.PORTRAIT": WD_ORIENT.PORTRAIT,

features/steps/settings.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@ def given_a_document_having_no_settings_part(context):
2222

2323
@given("a Settings object {with_or_without} odd and even page headers as settings")
2424
def given_a_Settings_object_with_or_without_odd_and_even_hdrs(context, with_or_without):
25-
testfile_name = {"with": "doc-odd-even-hdrs", "without": "sct-section-props"}[
26-
with_or_without
27-
]
25+
testfile_name = {"with": "doc-odd-even-hdrs", "without": "sct-section-props"}[with_or_without]
2826
context.settings = Document(test_docx(testfile_name)).settings
2927

3028

@@ -49,6 +47,4 @@ def then_document_settings_is_a_Settings_object(context):
4947
def then_settings_odd_and_even_pages_header_footer_is(context, bool_val):
5048
actual = context.settings.odd_and_even_pages_header_footer
5149
expected = eval(bool_val)
52-
assert actual == expected, (
53-
"settings.odd_and_even_pages_header_footer is %s" % actual
54-
)
50+
assert actual == expected, "settings.odd_and_even_pages_header_footer is %s" % actual

features/steps/shape.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,10 @@ def then_the_document_contains_the_inline_picture(context):
111111
image_part = document.part.related_parts[rId]
112112
image_sha1 = hashlib.sha1(image_part.blob).hexdigest()
113113
expected_sha1 = "79769f1e202add2e963158b532e36c2c0f76a70c"
114-
assert (
115-
image_sha1 == expected_sha1
116-
), "image SHA1 doesn't match, expected %s, got %s" % (expected_sha1, image_sha1)
114+
assert image_sha1 == expected_sha1, "image SHA1 doesn't match, expected %s, got %s" % (
115+
expected_sha1,
116+
image_sha1,
117+
)
117118

118119

119120
@then("the length of the inline shape collection is 5")

0 commit comments

Comments
 (0)