Skip to content

Commit 694f37b

Browse files
authored
Merge pull request #135 from 56kyle/fix-black-line-length
Fix black line length
2 parents 25e5db6 + 09e56a8 commit 694f37b

File tree

9 files changed

+41
-114
lines changed

9 files changed

+41
-114
lines changed

noxfile.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,7 @@ def activate_virtualenv_in_precommit_hooks(session: Session) -> None:
5353
# quoting rules for Python and bash, but strip the outermost quotes so we
5454
# can detect paths within the bindir, like <bindir>/python.
5555
bindirs = [
56-
bindir[1:-1] if bindir[0] in "'\"" else bindir
57-
for bindir in (repr(session.bin), shlex.quote(session.bin))
56+
bindir[1:-1] if bindir[0] in "'\"" else bindir for bindir in (repr(session.bin), shlex.quote(session.bin))
5857
]
5958

6059
virtualenv = session.env.get("VIRTUAL_ENV")
@@ -96,10 +95,7 @@ def activate_virtualenv_in_precommit_hooks(session: Session) -> None:
9695

9796
text = hook.read_text()
9897

99-
if not any(
100-
Path("A") == Path("a") and bindir.lower() in text.lower() or bindir in text
101-
for bindir in bindirs
102-
):
98+
if not any(Path("A") == Path("a") and bindir.lower() in text.lower() or bindir in text for bindir in bindirs):
10399
continue
104100

105101
lines = text.splitlines()

poetry.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ pytest-static = "pytest_static.__main__:main"
6464
[tool.poetry.plugins."pytest"]
6565
pytest-static= "pytest_static.plugin"
6666

67+
[tool.black]
68+
line-length = 120
69+
6770
[tool.coverage.paths]
6871
source = ["src", "*/site-packages"]
6972
tests = ["tests", "*/tests"]

src/pytest_static/exceptions.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,5 @@ class ExpandedTypeNotCallableError(TypeError):
77
"""Exception raised if a non-Callable base_type is being cast as Callable."""
88

99
def __init__(self, base_type: Any, *args: Any):
10-
msg: str = (
11-
f"Attempted to cast a non callable type of {type(base_type)} "
12-
f"as callable."
13-
)
10+
msg: str = f"Attempted to cast a non callable type of {type(base_type)} " f"as callable."
1411
super().__init__(msg, *args)

src/pytest_static/parametric.py

Lines changed: 16 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,8 @@ def parametrize_types(
8282
if len(argnames) != len(argtypes):
8383
raise ValueError("Parameter names and types count must match.")
8484

85-
parameter_sets: list[list[T]] = [
86-
list(get_all_possible_type_instances(t)) for t in argtypes
87-
]
88-
parameter_combinations: list[tuple[T, ...]] = list(
89-
itertools.product(*parameter_sets)
90-
)
85+
parameter_sets: list[list[T]] = [list(get_all_possible_type_instances(t)) for t in argtypes]
86+
parameter_combinations: list[tuple[T, ...]] = list(itertools.product(*parameter_sets))
9187

9288
if ids is None:
9389
ids = [", ".join(map(repr, pairs)) for pairs in parameter_combinations]
@@ -120,9 +116,7 @@ def iter_instances(typ: Any) -> Generator[Any, None, None]:
120116
base_type: Any = origin if origin is not None else typ
121117

122118
handler: (
123-
Callable[[Any, tuple[Any, ...]], Generator[Any, None, None]]
124-
| partial[Generator[Any, None, None]]
125-
| None
119+
Callable[[Any, tuple[Any, ...]], Generator[Any, None, None]] | partial[Generator[Any, None, None]] | None
126120
) = TYPE_HANDLERS.get(base_type, None)
127121

128122
if handler is None:
@@ -131,28 +125,20 @@ def iter_instances(typ: Any) -> Generator[Any, None, None]:
131125
yield from handler(base_type, type_args)
132126

133127

134-
def _iter_literal_instances(
135-
base_type: Any, type_args: tuple[Any, ...]
136-
) -> Generator[Any, None, None]:
128+
def _iter_literal_instances(base_type: Any, type_args: tuple[Any, ...]) -> Generator[Any, None, None]:
137129
yield from type_args
138130

139131

140-
def _iter_any_instances(
141-
base_type: Any, type_args: tuple[Any, ...]
142-
) -> Generator[Any, None, None]:
132+
def _iter_any_instances(base_type: Any, type_args: tuple[Any, ...]) -> Generator[Any, None, None]:
143133
for typ in PREDEFINED_INSTANCE_SETS.keys():
144134
yield from iter_instances(typ)
145135

146136

147-
def _iter_predefined_instances(
148-
base_type: Any, type_args: tuple[Any, ...]
149-
) -> Generator[Any, None, None]:
137+
def _iter_predefined_instances(base_type: Any, type_args: tuple[Any, ...]) -> Generator[Any, None, None]:
150138
yield from PREDEFINED_INSTANCE_SETS[base_type]
151139

152140

153-
def _iter_sum_instances(
154-
_: Any, type_args: tuple[Any, ...]
155-
) -> Generator[Any, None, None]:
141+
def _iter_sum_instances(_: Any, type_args: tuple[Any, ...]) -> Generator[Any, None, None]:
156142
for arg in type_args:
157143
yield from get_all_possible_type_instances(arg)
158144

@@ -166,25 +152,16 @@ def _iter_product_instances_with_constructor(
166152
if Ellipsis in type_args:
167153
type_args = type_args[:-1]
168154

169-
combinations: Iterable[Iterable[Any]] = itertools.product(
170-
*(iter_instances(arg) for arg in type_args)
171-
)
155+
combinations: Iterable[Iterable[Any]] = itertools.product(*(iter_instances(arg) for arg in type_args))
172156
yield from map(type_constructor, map(tuple, combinations))
173157

174158

175-
def _validate_combination_length(
176-
combination: tuple[Any, ...], expected_length: int, typ: type[Any]
177-
) -> None:
159+
def _validate_combination_length(combination: tuple[Any, ...], expected_length: int, typ: type[Any]) -> None:
178160
if len(combination) != expected_length:
179-
raise TypeError(
180-
f"Expected combination of length {expected_length} for "
181-
f"type {typ}. Got {len(combination)}"
182-
)
161+
raise TypeError(f"Expected combination of length {expected_length} for " f"type {typ}. Got {len(combination)}")
183162

184163

185-
def _iter_custom_instances(
186-
base_type: Any, type_args: tuple[Any, ...]
187-
) -> Generator[Any, None, None]:
164+
def _iter_custom_instances(base_type: Any, type_args: tuple[Any, ...]) -> Generator[Any, None, None]:
188165
"""Planned for future, but not yet implemented."""
189166
raise NotImplementedError
190167

@@ -205,9 +182,7 @@ def _set_constructor(combination: tuple[T]) -> set[T]:
205182

206183

207184
def _frozenset_constructor(combination: tuple[T]) -> frozenset[T]:
208-
_validate_combination_length(
209-
combination=combination, expected_length=1, typ=frozenset
210-
)
185+
_validate_combination_length(combination=combination, expected_length=1, typ=frozenset)
211186
return frozenset(combination)
212187

213188

@@ -240,15 +215,14 @@ def _tuple_constructor(combination: T) -> T:
240215
)
241216

242217

243-
PREDEFINED_TYPE_SET_HANDLERS: dict[
244-
type[Any], Callable[[Any, tuple[Any, ...]], Generator[Any, None, None]]
245-
] = {typ: _iter_predefined_instances for typ in PREDEFINED_INSTANCE_SETS.keys()}
218+
PREDEFINED_TYPE_SET_HANDLERS: dict[type[Any], Callable[[Any, tuple[Any, ...]], Generator[Any, None, None]]] = {
219+
typ: _iter_predefined_instances for typ in PREDEFINED_INSTANCE_SETS.keys()
220+
}
246221

247222

248223
TYPE_HANDLERS: dict[
249224
Any,
250-
Callable[[Any, tuple[Any, ...]], Generator[Any, None, None]]
251-
| partial[Generator[Any, None, None]],
225+
Callable[[Any, tuple[Any, ...]], Generator[Any, None, None]] | partial[Generator[Any, None, None]],
252226
] = {
253227
**PREDEFINED_TYPE_SET_HANDLERS,
254228
Literal: _iter_literal_instances,

tests/test_util.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,5 @@
2121
(Dict[int, int], "Dict"),
2222
],
2323
)
24-
def test__get_origin_string_with_special_generic_alias(
25-
annotation: Any, expected: str
26-
) -> None:
24+
def test__get_origin_string_with_special_generic_alias(annotation: Any, expected: str) -> None:
2725
assert _get_origin_string(annotation) == expected

tests/unit_tests/test_parametric.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,7 @@ def assert_len(iterable: Iterable[Any], expected: int) -> None:
4040

4141

4242
def test_get_all_possible_type_instances(monkeypatch: MonkeyPatch) -> None:
43-
monkeypatch.setattr(
44-
pytest_static.parametric, "iter_instances", dummy_iter_instances
45-
)
43+
monkeypatch.setattr(pytest_static.parametric, "iter_instances", dummy_iter_instances)
4644
assert get_all_possible_type_instances(int) == (1, 2, 3)
4745

4846

tests/unit_tests/test_plugin.py

Lines changed: 11 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,10 @@ def argtypes(request: FixtureRequest) -> Sequence[str]:
3838

3939

4040
@pytest.fixture
41-
def parametrize_types_test(
42-
pytester: Pytester, conftest: Path, argtypes: Sequence[str]
43-
) -> Path:
41+
def parametrize_types_test(pytester: Pytester, conftest: Path, argtypes: Sequence[str]) -> Path:
4442
argnames: list[str] = [f"arg{i}" for i in range(len(argtypes))]
4543
argtypes_formatted: str = ", ".join([f"{argtype}" for argtype in argtypes])
46-
signature: str = ", ".join(
47-
[f"{argname}" for argname, argtype in zip(argnames, argtypes)]
48-
)
44+
signature: str = ", ".join([f"{argname}" for argname, argtype in zip(argnames, argtypes)])
4945

5046
return pytester.makepyfile(
5147
f"""
@@ -66,9 +62,7 @@ def test_func({signature}) -> None:
6662
)
6763

6864

69-
def test_parametrize_types_with_unequal_names_and_types(
70-
pytester: Pytester, conftest: Path
71-
) -> None:
65+
def test_parametrize_types_with_unequal_names_and_types(pytester: Pytester, conftest: Path) -> None:
7266
test_path: Path = pytester.makepyfile(
7367
"""
7468
import pytest
@@ -88,9 +82,7 @@ def test_func(a, b) -> None:
8882
result.assert_outcomes(errors=1)
8983

9084

91-
def test_parametrize_types_with_no_ids_provided(
92-
pytester: Pytester, conftest: Path
93-
) -> None:
85+
def test_parametrize_types_with_no_ids_provided(pytester: Pytester, conftest: Path) -> None:
9486
test_path: Path = pytester.makepyfile(
9587
"""
9688
import pytest
@@ -110,9 +102,7 @@ def test_func(a, b) -> None:
110102
result.assert_outcomes(passed=4)
111103

112104

113-
def test_parametrize_types_with_argnames_as_string(
114-
pytester: Pytester, conftest: Path
115-
) -> None:
105+
def test_parametrize_types_with_argnames_as_string(pytester: Pytester, conftest: Path) -> None:
116106
test_path: Path = pytester.makepyfile(
117107
"""
118108
import pytest
@@ -145,9 +135,7 @@ def test_func(a, b) -> None:
145135
ids=lambda x: str(x) if isinstance(x, Iterable) else x,
146136
indirect=["argtypes"],
147137
)
148-
def test_parametrize_types_with_single_basic(
149-
pytester: Pytester, parametrize_types_test: Path, expected: int
150-
) -> None:
138+
def test_parametrize_types_with_single_basic(pytester: Pytester, parametrize_types_test: Path, expected: int) -> None:
151139
result: pytest.RunResult = pytester.runpytest(parametrize_types_test)
152140
result.assert_outcomes(passed=expected)
153141

@@ -160,9 +148,7 @@ def test_parametrize_types_with_single_basic(
160148
ids=lambda x: str(x) if isinstance(x, Iterable) else x,
161149
indirect=["argtypes"],
162150
)
163-
def test_parametrize_types_with_multiple_basic(
164-
pytester: Pytester, parametrize_types_test: Path, expected: int
165-
) -> None:
151+
def test_parametrize_types_with_multiple_basic(pytester: Pytester, parametrize_types_test: Path, expected: int) -> None:
166152
result: pytest.RunResult = pytester.runpytest(parametrize_types_test)
167153
result.assert_outcomes(passed=expected)
168154

@@ -211,10 +197,7 @@ def test_parametrize_types_with_multiple_expanded(
211197

212198
@pytest.mark.parametrize(
213199
argnames=["argtypes", "expected"],
214-
argvalues=[
215-
((type_annotation_to_string(typ),), expected)
216-
for typ, expected in SPECIAL_TYPE_EXPECTED_EXAMPLES
217-
],
200+
argvalues=[((type_annotation_to_string(typ),), expected) for typ, expected in SPECIAL_TYPE_EXPECTED_EXAMPLES],
218201
ids=lambda x: str(x) if isinstance(x, Iterable) else x,
219202
indirect=["argtypes"],
220203
)
@@ -227,10 +210,7 @@ def test_parametrize_types_with_special_type_expected_examples(
227210

228211
@pytest.mark.parametrize(
229212
argnames=["argtypes", "expected"],
230-
argvalues=[
231-
((type_annotation_to_string(typ),), expected)
232-
for typ, expected in BASIC_TYPE_EXPECTED_EXAMPLES
233-
],
213+
argvalues=[((type_annotation_to_string(typ),), expected) for typ, expected in BASIC_TYPE_EXPECTED_EXAMPLES],
234214
ids=lambda x: str(x) if isinstance(x, Iterable) else x,
235215
indirect=["argtypes"],
236216
)
@@ -243,10 +223,7 @@ def test_parametrize_types_with_basic_type_expected_examples(
243223

244224
@pytest.mark.parametrize(
245225
argnames=["argtypes", "expected"],
246-
argvalues=[
247-
((type_annotation_to_string(typ),), expected)
248-
for typ, expected in SUM_TYPE_EXPECTED_EXAMPLES
249-
],
226+
argvalues=[((type_annotation_to_string(typ),), expected) for typ, expected in SUM_TYPE_EXPECTED_EXAMPLES],
250227
ids=lambda x: str(x) if isinstance(x, Iterable) else x,
251228
indirect=["argtypes"],
252229
)
@@ -259,10 +236,7 @@ def test_parametrize_types_with_sum_type_expected_examples(
259236

260237
@pytest.mark.parametrize(
261238
argnames=["argtypes", "expected"],
262-
argvalues=[
263-
((type_annotation_to_string(typ),), expected)
264-
for typ, expected in PRODUCT_TYPE_EXPECTED_EXAMPLES
265-
],
239+
argvalues=[((type_annotation_to_string(typ),), expected) for typ, expected in PRODUCT_TYPE_EXPECTED_EXAMPLES],
266240
ids=lambda x: str(x) if isinstance(x, Iterable) else x,
267241
indirect=["argtypes"],
268242
)

tests/util.py

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,7 @@
2828
BYTES_LEN: int = len(PREDEFINED_INSTANCE_SETS[bytes])
2929
NONE_LEN: int = 1
3030
ELLIPSIS_LEN: int = 0
31-
ANY_LEN: int = (
32-
BOOL_LEN
33-
+ INT_LEN
34-
+ FLOAT_LEN
35-
+ COMPLEX_LEN
36-
+ STR_LEN
37-
+ BYTES_LEN
38-
+ NONE_LEN
39-
+ ELLIPSIS_LEN
40-
)
31+
ANY_LEN: int = BOOL_LEN + INT_LEN + FLOAT_LEN + COMPLEX_LEN + STR_LEN + BYTES_LEN + NONE_LEN + ELLIPSIS_LEN
4132

4233

4334
SPECIAL_TYPE_EXPECTED_EXAMPLES: list[tuple[Any, int]] = [
@@ -151,15 +142,11 @@ def _get_origin_string(annotation: Any) -> str:
151142
annotation_name = annotation.__name__
152143
elif origin is not None:
153144
annotation_name_with_generics: str = str(annotation)
154-
annotation_name = annotation_name_with_generics.split("[")[
155-
0
156-
] # Should never not be a generic here
145+
annotation_name = annotation_name_with_generics.split("[")[0] # Should never not be a generic here
157146
else:
158147
annotation_name = str(annotation)
159148

160-
annotation_name_without_module: str = _remove_typing_module_from_str(
161-
annotation_name
162-
)
149+
annotation_name_without_module: str = _remove_typing_module_from_str(annotation_name)
163150
if annotation_name_without_module == "Optional":
164151
return "Union"
165152
return annotation_name_without_module

0 commit comments

Comments
 (0)