Skip to content

Commit 88685d8

Browse files
authored
Black code formatting (#32)
* Black code formatting of all Python code
1 parent aecbdcf commit 88685d8

26 files changed

+1991
-1588
lines changed

.vscode/settings.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"restructuredtext.confPath": "${workspaceFolder}\\docs\\source",
3+
"python.formatting.blackArgs": [
4+
"--line-length",
5+
"79",
6+
"--skip-string-normalization"
7+
],
8+
"python.formatting.provider": "black",
9+
"editor.rulers": [79, 87]
10+
}

docs/source/conf.py

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@
1818
import os
1919
import sys
2020

21-
sys.path.insert(
22-
0, os.path.split(os.path.split(os.path.dirname(os.path.abspath(
23-
__file__)))[0])[0])
21+
sys.path.insert(0, os.path.abspath("../.."))
2422

2523
from pytest_order import __version__ # noqa: E402
2624

@@ -53,7 +51,7 @@
5351
master_doc = "index"
5452

5553
# General information about the project.
56-
project = u"pytest-order"
54+
project = "pytest-order"
5755

5856
# The version info for the project you"re documenting, acts as replacement for
5957
# |version| and |release|, also used in various other places throughout the
@@ -205,8 +203,13 @@
205203
# (source start file, target name, title,
206204
# author, documentclass [howto, manual, or own class]).
207205
latex_documents = [
208-
("index", "pytest-order.tex", u"pytest-order Documentation",
209-
u"Frank Tobia", "manual"),
206+
(
207+
"index",
208+
"pytest-order.tex",
209+
"pytest-order Documentation",
210+
"Frank Tobia",
211+
"manual",
212+
),
210213
]
211214

212215
# The name of an image file (relative to this directory) to place at the top of
@@ -235,8 +238,13 @@
235238
# One entry per manual page. List of tuples
236239
# (source start file, name, description, authors, manual section).
237240
man_pages = [
238-
("index", "pytest-order", u"pytest-order Documentation",
239-
[u"Frank Tobia"], 1)
241+
(
242+
"index",
243+
"pytest-order",
244+
"pytest-order Documentation",
245+
["Frank Tobia"],
246+
1,
247+
)
240248
]
241249

242250
# If true, show URL addresses after external links.
@@ -249,9 +257,15 @@
249257
# (source start file, target name, title, author,
250258
# dir menu entry, description, category)
251259
texinfo_documents = [
252-
("index", "pytest-order", u"pytest-order Documentation",
253-
u"Frank Tobia", "pytest-order", "One line description of project.",
254-
"Miscellaneous"),
260+
(
261+
"index",
262+
"pytest-order",
263+
"pytest-order Documentation",
264+
"Frank Tobia",
265+
"pytest-order",
266+
"One line description of project.",
267+
"Miscellaneous",
268+
),
255269
]
256270

257271
# Documents to append as an appendix to all manuals.

perf_tests/test_dependencies.py

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from unittest import mock
2+
from textwrap import dedent
23

34
import pytest
45
from perf_tests.util import TimedSorter
@@ -10,21 +11,23 @@
1011
def fixture_path_relative(testdir):
1112
for i_mod in range(10):
1213
test_name = testdir.tmpdir.join("test_dep_perf{}.py".format(i_mod))
13-
test_contents = """
14-
import pytest
15-
"""
14+
test_contents = "import pytest\n"
1615
for i in range(40):
17-
test_contents += """
18-
@pytest.mark.dependency(depends=["test_{}"])
19-
def test_{}():
20-
assert True
21-
""".format(i + 50, i)
16+
test_contents += dedent(
17+
"""
18+
@pytest.mark.dependency(depends=["test_{}"])
19+
def test_{}():
20+
assert True
21+
"""
22+
).format(i + 50, i)
2223
for i in range(60):
23-
test_contents += """
24-
@pytest.mark.dependency
25-
def test_{}():
26-
assert True
27-
""".format(i + 40)
24+
test_contents += dedent(
25+
"""
26+
@pytest.mark.dependency
27+
def test_{}():
28+
assert True
29+
"""
30+
).format(i + 40)
2831
test_name.write(test_contents)
2932
yield testdir
3033

perf_tests/test_ordinal.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from unittest import mock
2+
from textwrap import dedent
23

34
import pytest
45
from perf_tests.util import TimedSorter
@@ -10,15 +11,15 @@
1011
def fixture_path_ordinal(testdir):
1112
for i_mod in range(10):
1213
test_name = testdir.tmpdir.join("test_performance{}.py".format(i_mod))
13-
test_contents = """
14-
import pytest
15-
"""
14+
test_contents = "import pytest\n"
1615
for i in range(100):
17-
test_contents += """
18-
@pytest.mark.order({})
19-
def test_{}():
20-
assert True
21-
""".format(50 - i, i)
16+
test_contents += dedent(
17+
"""
18+
@pytest.mark.order({})
19+
def test_{}():
20+
assert True
21+
"""
22+
).format(50 - i, i)
2223
test_name.write(test_contents)
2324
yield testdir
2425

perf_tests/test_relative.py

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from unittest import mock
2+
from textwrap import dedent
23

34
import pytest
45
from perf_tests.util import TimedSorter
@@ -10,21 +11,24 @@
1011
def fixture_path_relative(testdir):
1112
for i_mod in range(10):
1213
test_name = testdir.tmpdir.join(
13-
"test_relative_perf{}.py".format(i_mod))
14-
test_contents = """
15-
import pytest
16-
"""
14+
"test_relative_perf{}.py".format(i_mod)
15+
)
16+
test_contents = "import pytest\n"
1717
for i in range(40):
18-
test_contents += """
19-
@pytest.mark.order(after="test_{}")
20-
def test_{}():
21-
assert True
22-
""".format(i + 50, i)
18+
test_contents += dedent(
19+
"""
20+
@pytest.mark.order(after="test_{}")
21+
def test_{}():
22+
assert True
23+
"""
24+
).format(i + 50, i)
2325
for i in range(60):
24-
test_contents += """
25-
def test_{}():
26-
assert True
27-
""".format(i + 40)
26+
test_contents += dedent(
27+
"""
28+
def test_{}():
29+
assert True
30+
"""
31+
).format(i + 40)
2832
test_name.write(test_contents)
2933
yield testdir
3034

perf_tests/test_relative_dense.py

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from unittest import mock
2+
from textwrap import dedent
23

34
import pytest
45
from perf_tests.util import TimedSorter
@@ -10,21 +11,24 @@
1011
def fixture_path_relative_dense(testdir):
1112
for i_mod in range(10):
1213
test_name = testdir.tmpdir.join(
13-
"test_relative_dense_perf{}.py".format(i_mod))
14-
test_contents = """
15-
import pytest
16-
"""
14+
"test_relative_dense_perf{}.py".format(i_mod)
15+
)
16+
test_contents = "import pytest\n"
1717
for i in range(90):
18-
test_contents += """
19-
@pytest.mark.order(after="test_{}")
20-
def test_{}():
21-
assert True
22-
""".format(i + 10, i)
18+
test_contents += dedent(
19+
"""
20+
@pytest.mark.order(after="test_{}")
21+
def test_{}():
22+
assert True
23+
"""
24+
).format(i + 10, i)
2325
for i in range(10):
24-
test_contents += """
25-
def test_{}():
26-
assert True
27-
""".format(i + 90)
26+
test_contents += dedent(
27+
"""
28+
def test_{}():
29+
assert True
30+
"""
31+
).format(i + 90)
2832
test_name.write(test_contents)
2933
yield testdir
3034

perf_tests/util.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ def sort_items(self):
1111
self.__class__.elapsed = 0
1212
start_time = time.time()
1313
items = super().sort_items()
14-
self.__class__.elapsed = ((time.time() - start_time)
15-
/ self.nr_marks * 1000)
14+
self.__class__.elapsed = (
15+
(time.time() - start_time) / self.nr_marks * 1000
16+
)
1617
print("\nTime per test: {:.3f} ms".format(self.__class__.elapsed))
1718
return items

pytest_order/item.py

Lines changed: 46 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
from _pytest.python import Function
55

6-
from pytest_order.settings import Scope, Settings
6+
from .settings import Scope, Settings
77

88

99
class Item:
@@ -41,10 +41,14 @@ def node_id(self) -> str:
4141
class ItemList:
4242
"""Handles a group of items with the same scope."""
4343

44-
def __init__(self, items: List[Item],
45-
settings: Settings, scope: Scope,
46-
rel_marks: List["RelativeMark"],
47-
dep_marks: List["RelativeMark"]) -> None:
44+
def __init__(
45+
self,
46+
items: List[Item],
47+
settings: Settings,
48+
scope: Scope,
49+
rel_marks: List["RelativeMark"],
50+
dep_marks: List["RelativeMark"],
51+
) -> None:
4852
self.items = items
4953
self.settings = settings
5054
self.scope = scope
@@ -95,30 +99,37 @@ def sort_numbered_items(self) -> List[Item]:
9599
return sorted_list
96100

97101
def print_unhandled_items(self) -> None:
98-
msg = " ".join([mark.item.node_id for mark in self.rel_marks] +
99-
[mark.item.node_id for mark in self.dep_marks])
102+
msg = " ".join(
103+
[mark.item.node_id for mark in self.rel_marks]
104+
+ [mark.item.node_id for mark in self.dep_marks]
105+
)
100106
if msg:
101107
sys.stdout.write(
102-
"\nWARNING: cannot execute test relative to others: ")
108+
"\nWARNING: cannot execute test relative to others: "
109+
)
103110
sys.stdout.write(msg)
104-
sys.stdout.write("- ignoring the marker.\n")
111+
sys.stdout.write(" - ignoring the marker.\n")
105112
sys.stdout.flush()
106113

107114
def number_of_rel_groups(self) -> int:
108115
return len(self.rel_marks) + len(self.dep_marks)
109116

110117
def handle_rel_marks(self, sorted_list: List[Item]) -> None:
111-
self.handle_relative_marks(self.rel_marks, sorted_list,
112-
self.all_rel_marks)
118+
self.handle_relative_marks(
119+
self.rel_marks, sorted_list, self.all_rel_marks
120+
)
113121

114122
def handle_dep_marks(self, sorted_list: List[Item]) -> None:
115-
self.handle_relative_marks(self.dep_marks, sorted_list,
116-
self.all_dep_marks)
123+
self.handle_relative_marks(
124+
self.dep_marks, sorted_list, self.all_dep_marks
125+
)
117126

118127
@staticmethod
119-
def handle_relative_marks(marks: List["RelativeMark"],
120-
sorted_list: List[Item],
121-
all_marks: List["RelativeMark"]):
128+
def handle_relative_marks(
129+
marks: List["RelativeMark"],
130+
sorted_list: List[Item],
131+
all_marks: List["RelativeMark"],
132+
):
122133
for mark in reversed(marks):
123134
if move_item(mark, sorted_list):
124135
marks.remove(mark)
@@ -136,8 +147,9 @@ class ItemGroup:
136147
Used for sorting groups similar to Item for sorting items.
137148
"""
138149

139-
def __init__(self, items: Optional[List[Item]] = None,
140-
order: Optional[int] = None) -> None:
150+
def __init__(
151+
self, items: Optional[List[Item]] = None, order: Optional[int] = None
152+
) -> None:
141153
self.items = items or []
142154
self.order = order
143155
self.nr_rel_items = 0
@@ -161,17 +173,20 @@ class RelativeMark:
161173
Holds two related items or groups and their relationship.
162174
"""
163175

164-
def __init__(self, item: Union[Item, ItemGroup],
165-
item_to_move: Union[Item, ItemGroup],
166-
move_after: bool) -> None:
176+
def __init__(
177+
self,
178+
item: Union[Item, ItemGroup],
179+
item_to_move: Union[Item, ItemGroup],
180+
move_after: bool,
181+
) -> None:
167182
self.item: Item = item
168183
self.item_to_move: Item = item_to_move
169184
self.move_after: bool = move_after
170185

171186

172187
def filter_marks(
173-
marks: List[RelativeMark],
174-
all_items: List[Item]) -> List[RelativeMark]:
188+
marks: List[RelativeMark], all_items: List[Item]
189+
) -> List[RelativeMark]:
175190
result = []
176191
for mark in marks:
177192
if mark.item in all_items and mark.item_to_move in all_items:
@@ -181,11 +196,14 @@ def filter_marks(
181196
return result
182197

183198

184-
def move_item(mark: RelativeMark,
185-
sorted_items: List[Union[Item, ItemGroup]]) -> bool:
186-
if (mark.item not in sorted_items or
187-
mark.item_to_move not in sorted_items or
188-
mark.item.nr_rel_items):
199+
def move_item(
200+
mark: RelativeMark, sorted_items: List[Union[Item, ItemGroup]]
201+
) -> bool:
202+
if (
203+
mark.item not in sorted_items
204+
or mark.item_to_move not in sorted_items
205+
or mark.item.nr_rel_items
206+
):
189207
return False
190208
pos_item = sorted_items.index(mark.item)
191209
pos_item_to_move = sorted_items.index(mark.item_to_move)

0 commit comments

Comments
 (0)