From de3e5908f79f5122f9c58376b03a8dee61515d32 Mon Sep 17 00:00:00 2001
From: Peter Cock
Date: Fri, 25 Feb 2022 10:42:11 +0000
Subject: [PATCH] Adding test case for skip-magic-trailing-comma
Functionality added in pull request #48
---
tests/run_tests.sh | 5 +++++
tests/test_changes/commas.py | 24 ++++++++++++++++++++++++
tests/with_pyproject_toml/pyproject.toml | 1 +
3 files changed, 30 insertions(+)
create mode 100644 tests/test_changes/commas.py
diff --git a/tests/run_tests.sh b/tests/run_tests.sh
index 3902d80..6d66ecd 100755
--- a/tests/run_tests.sh
+++ b/tests/run_tests.sh
@@ -42,4 +42,9 @@ diff test_changes/hello_world_EOF.txt <(flake8 --select BLK test_changes/hello_w
diff with_bad_toml/hello_world.txt <(flake8 --select BLK with_bad_toml/hello_world.py)
diff with_pyproject_toml/ignoring_toml.txt <(flake8 with_pyproject_toml/ --select BLK --black-config '')
+# no changes by default,
+flake8 --select BLK test_changes/commas.py
+# will make changes if we ignore the magic trailing comma:
+diff test_changes/commas.txt <(flake8 --select BLK test_changes/commas.py --black-config with_pyproject_toml/pyproject.toml)
+
echo "Tests passed."
diff --git a/tests/test_changes/commas.py b/tests/test_changes/commas.py
new file mode 100644
index 0000000..a1db0bc
--- /dev/null
+++ b/tests/test_changes/commas.py
@@ -0,0 +1,24 @@
+"""Example of black and magic commas."""
+
+vegetables = {
+ "carrot",
+ "parsnip",
+ "potato",
+ "swede",
+ "leak",
+ "aubergine",
+ "tomato",
+ "peas",
+ "beans",
+}
+
+# This set would easily fit on one line, but a trailing comma
+# after the final entry tells black (by default) to leave this
+# with one entry per line:
+yucky = {
+ "aubergine",
+ "squid",
+ "snails",
+}
+
+print("I dislike these vegetables: %s." % ", ".join(vegetables.intersection(yucky)))
diff --git a/tests/with_pyproject_toml/pyproject.toml b/tests/with_pyproject_toml/pyproject.toml
index 0097e9f..da38ae0 100644
--- a/tests/with_pyproject_toml/pyproject.toml
+++ b/tests/with_pyproject_toml/pyproject.toml
@@ -1,2 +1,3 @@
[tool.black]
skip-string-normalization = true
+skip-magic-trailing-comma = true