WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit 0c516ef

Browse files
committed
Separate test for checking black replaces config with linked one
1 parent 22d902b commit 0c516ef

File tree

8 files changed

+46
-16
lines changed

8 files changed

+46
-16
lines changed

CHANGES.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
### _Black_
66

77
- Add new `--workers` parameter (#2514)
8-
- Bumped typed-ast version minimum to 1.4.3 for 3.10 compatibility (#2519)
8+
- Fixed feature detection for positional-only arguments in lambdas (#2532)
9+
- Bumped typed-ast version minimum to 1.4.3 for 3.10 compatiblity (#2519)
910
- Allow specifying `config` in config files (#2525)
1011

1112
### _Blackd_

docs/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Used by ReadTheDocs; pinned requirements for stability.
22

33
myst-parser==0.15.1
4-
Sphinx==4.1.2
4+
Sphinx==4.2.0
55
sphinxcontrib-programoutput==0.17
66
sphinx_copybutton==0.4.0

src/black/__init__.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1125,7 +1125,11 @@ def get_features_used(node: Node) -> Set[Feature]:
11251125
features.add(Feature.NUMERIC_UNDERSCORES)
11261126

11271127
elif n.type == token.SLASH:
1128-
if n.parent and n.parent.type in {syms.typedargslist, syms.arglist}:
1128+
if n.parent and n.parent.type in {
1129+
syms.typedargslist,
1130+
syms.arglist,
1131+
syms.varargslist,
1132+
}:
11291133
features.add(Feature.POS_ONLY_ARGUMENTS)
11301134

11311135
elif n.type == token.COLONEQUAL:
File renamed without changes.

tests/invalid_test.toml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,2 @@
11
[tool.black]
22
config = "tests/bazqux.toml"
3-
4-
[v1.0.0-syntax]
5-
# This shouldn't break Black.
6-
contributors = [
7-
"Foo Bar <[email protected]>",
8-
{ name = "Baz Qux", email = "[email protected]", url = "https://example.com/bazqux" }
9-
]

tests/test.toml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
[tool.black]
2-
config = "test_black.toml"
3-
verbose = 0
4-
color = false
2+
verbose = 1
3+
--check = "no"
4+
diff = "y"
5+
color = true
56
line-length = 79
7+
target-version = ["py36", "py37", "py38"]
8+
exclude='\.pyi?$'
9+
include='\.py?$'
610

711
[v1.0.0-syntax]
812
# This shouldn't break Black.

tests/test_black.py

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -805,6 +805,10 @@ def test_get_features_used(self) -> None:
805805
self.assertEqual(black.get_features_used(node), set())
806806
node = black.lib2to3_parse(expected)
807807
self.assertEqual(black.get_features_used(node), set())
808+
node = black.lib2to3_parse("lambda a, /, b: ...")
809+
self.assertEqual(black.get_features_used(node), {Feature.POS_ONLY_ARGUMENTS})
810+
node = black.lib2to3_parse("def fn(a, /, b): ...")
811+
self.assertEqual(black.get_features_used(node), {Feature.POS_ONLY_ARGUMENTS})
808812

809813
def test_get_future_imports(self) -> None:
810814
node = black.lib2to3_parse("\n")
@@ -1268,10 +1272,14 @@ def test_invalid_config_return_code(self) -> None:
12681272
def test_parse_pyproject_toml(self) -> None:
12691273
test_toml_file = THIS_DIR / "test.toml"
12701274
config = black.parse_pyproject_toml(str(test_toml_file))
1271-
self.assertEqual(config["verbose"], 0)
1272-
self.assertEqual(config["config"], "test_black.toml")
1273-
self.assertEqual(config["color"], False)
1275+
self.assertEqual(config["verbose"], 1)
1276+
self.assertEqual(config["check"], "no")
1277+
self.assertEqual(config["diff"], "y")
1278+
self.assertEqual(config["color"], True)
12741279
self.assertEqual(config["line_length"], 79)
1280+
self.assertEqual(config["target_version"], ["py36", "py37", "py38"])
1281+
self.assertEqual(config["exclude"], r"\.pyi?$")
1282+
self.assertEqual(config["include"], r"\.py?$")
12751283

12761284
def test_read_pyproject_toml(self) -> None:
12771285
test_toml_file = THIS_DIR / "test.toml"
@@ -1282,6 +1290,22 @@ def test_read_pyproject_toml(self) -> None:
12821290
self.assertEqual(config["check"], "no")
12831291
self.assertEqual(config["diff"], "y")
12841292
self.assertEqual(config["color"], "True")
1293+
self.assertEqual(config["line_length"], "79")
1294+
self.assertEqual(config["target_version"], ["py36", "py37", "py38"])
1295+
self.assertEqual(config["exclude"], r"\.pyi?$")
1296+
self.assertEqual(config["include"], r"\.py?$")
1297+
1298+
def test_black_replace_config(self) -> None:
1299+
test_toml_file = THIS_DIR / "test_replace.toml"
1300+
fake_ctx = FakeContext()
1301+
black.read_pyproject_toml(fake_ctx, FakeParameter(), str(test_toml_file))
1302+
config = fake_ctx.default_map
1303+
# `0` in `test_replace.toml` and `1` in `_black_config.toml`. Should be `1` as
1304+
# the one linked should overwrite the config
1305+
self.assertEqual(config["verbose"], "1")
1306+
self.assertEqual(config["check"], "no")
1307+
self.assertEqual(config["diff"], "y")
1308+
self.assertEqual(config["color"], "True")
12851309
self.assertEqual(config["line_length"], "88")
12861310
self.assertEqual(config["target_version"], ["py36", "py37", "py38"])
12871311
self.assertEqual(config["exclude"], r"\.pyi?$")

tests/test_replace.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[tool.black]
2+
config = "_black_config.toml"
3+
verbose = 0
4+
color = false

0 commit comments

Comments
 (0)