Skip to content

Commit

Permalink
Separate test for checking black replaces config with linked one
Browse files Browse the repository at this point in the history
  • Loading branch information
Shivansh-007 committed Oct 21, 2021
1 parent 22d902b commit 88c80c2
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 13 deletions.
File renamed without changes.
7 changes: 0 additions & 7 deletions tests/invalid_test.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,2 @@
[tool.black]
config = "tests/bazqux.toml"

[v1.0.0-syntax]
# This shouldn't break Black.
contributors = [
"Foo Bar <foo@example.com>",
{ name = "Baz Qux", email = "bazqux@example.com", url = "https://example.com/bazqux" }
]
10 changes: 7 additions & 3 deletions tests/test.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
[tool.black]
config = "test_black.toml"
verbose = 0
color = false
verbose = 1
--check = "no"
diff = "y"
color = true
line-length = 79
target-version = ["py36", "py37", "py38"]
exclude='\.pyi?$'
include='\.py?$'

[v1.0.0-syntax]
# This shouldn't break Black.
Expand Down
26 changes: 23 additions & 3 deletions tests/test_black.py
Original file line number Diff line number Diff line change
Expand Up @@ -1268,10 +1268,14 @@ def test_invalid_config_return_code(self) -> None:
def test_parse_pyproject_toml(self) -> None:
test_toml_file = THIS_DIR / "test.toml"
config = black.parse_pyproject_toml(str(test_toml_file))
self.assertEqual(config["verbose"], 0)
self.assertEqual(config["config"], "test_black.toml")
self.assertEqual(config["color"], False)
self.assertEqual(config["verbose"], 1)
self.assertEqual(config["check"], "no")
self.assertEqual(config["diff"], "y")
self.assertEqual(config["color"], True)
self.assertEqual(config["line_length"], 79)
self.assertEqual(config["target_version"], ["py36", "py37", "py38"])
self.assertEqual(config["exclude"], r"\.pyi?$")
self.assertEqual(config["include"], r"\.py?$")

def test_read_pyproject_toml(self) -> None:
test_toml_file = THIS_DIR / "test.toml"
Expand All @@ -1282,6 +1286,22 @@ def test_read_pyproject_toml(self) -> None:
self.assertEqual(config["check"], "no")
self.assertEqual(config["diff"], "y")
self.assertEqual(config["color"], "True")
self.assertEqual(config["line_length"], "79")
self.assertEqual(config["target_version"], ["py36", "py37", "py38"])
self.assertEqual(config["exclude"], r"\.pyi?$")
self.assertEqual(config["include"], r"\.py?$")

def test_black_replace_config(self) -> None:
test_toml_file = THIS_DIR / "test_replace.toml"
fake_ctx = FakeContext()
black.read_pyproject_toml(fake_ctx, FakeParameter(), str(test_toml_file))
config = fake_ctx.default_map
# `0` in `test_replace.toml` and `1` in `_black_config.toml`. Should be `1` as
# the one linked should overwrite the config
self.assertEqual(config["verbose"], "1")
self.assertEqual(config["check"], "no")
self.assertEqual(config["diff"], "y")
self.assertEqual(config["color"], "True")
self.assertEqual(config["line_length"], "88")
self.assertEqual(config["target_version"], ["py36", "py37", "py38"])
self.assertEqual(config["exclude"], r"\.pyi?$")
Expand Down
4 changes: 4 additions & 0 deletions tests/test_replace.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[tool.black]
config = "_black_config.toml"
verbose = 0
color = false

0 comments on commit 88c80c2

Please sign in to comment.