Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit fb9fe6b

Browse files
authored
Isolate command line tests from user-level config (psf#2851)
1 parent f3f3acc commit fb9fe6b

1 file changed

Lines changed: 15 additions & 10 deletions

File tree

tests/test_black.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
)
6464

6565
THIS_FILE = Path(__file__)
66+
EMPTY_CONFIG = THIS_DIR / "data" / "empty_pyproject.toml"
6667
PY36_ARGS = [f"--target-version={version.name.lower()}" for version in PY36_VERSIONS]
6768
DEFAULT_EXCLUDE = black.re_compile_maybe_verbose(black.const.DEFAULT_EXCLUDES)
6869
DEFAULT_INCLUDE = black.re_compile_maybe_verbose(black.const.DEFAULT_INCLUDES)
@@ -159,7 +160,12 @@ def test_piping(self) -> None:
159160
source, expected = read_data("src/black/__init__", data=False)
160161
result = BlackRunner().invoke(
161162
black.main,
162-
["-", "--fast", f"--line-length={black.DEFAULT_LINE_LENGTH}"],
163+
[
164+
"-",
165+
"--fast",
166+
f"--line-length={black.DEFAULT_LINE_LENGTH}",
167+
f"--config={EMPTY_CONFIG}",
168+
],
163169
input=BytesIO(source.encode("utf8")),
164170
)
165171
self.assertEqual(result.exit_code, 0)
@@ -175,13 +181,12 @@ def test_piping_diff(self) -> None:
175181
)
176182
source, _ = read_data("expression.py")
177183
expected, _ = read_data("expression.diff")
178-
config = THIS_DIR / "data" / "empty_pyproject.toml"
179184
args = [
180185
"-",
181186
"--fast",
182187
f"--line-length={black.DEFAULT_LINE_LENGTH}",
183188
"--diff",
184-
f"--config={config}",
189+
f"--config={EMPTY_CONFIG}",
185190
]
186191
result = BlackRunner().invoke(
187192
black.main, args, input=BytesIO(source.encode("utf8"))
@@ -193,14 +198,13 @@ def test_piping_diff(self) -> None:
193198

194199
def test_piping_diff_with_color(self) -> None:
195200
source, _ = read_data("expression.py")
196-
config = THIS_DIR / "data" / "empty_pyproject.toml"
197201
args = [
198202
"-",
199203
"--fast",
200204
f"--line-length={black.DEFAULT_LINE_LENGTH}",
201205
"--diff",
202206
"--color",
203-
f"--config={config}",
207+
f"--config={EMPTY_CONFIG}",
204208
]
205209
result = BlackRunner().invoke(
206210
black.main, args, input=BytesIO(source.encode("utf8"))
@@ -252,7 +256,6 @@ def test_expression_ff(self) -> None:
252256

253257
def test_expression_diff(self) -> None:
254258
source, _ = read_data("expression.py")
255-
config = THIS_DIR / "data" / "empty_pyproject.toml"
256259
expected, _ = read_data("expression.diff")
257260
tmp_file = Path(black.dump_to_file(source))
258261
diff_header = re.compile(
@@ -261,7 +264,7 @@ def test_expression_diff(self) -> None:
261264
)
262265
try:
263266
result = BlackRunner().invoke(
264-
black.main, ["--diff", str(tmp_file), f"--config={config}"]
267+
black.main, ["--diff", str(tmp_file), f"--config={EMPTY_CONFIG}"]
265268
)
266269
self.assertEqual(result.exit_code, 0)
267270
finally:
@@ -279,12 +282,12 @@ def test_expression_diff(self) -> None:
279282

280283
def test_expression_diff_with_color(self) -> None:
281284
source, _ = read_data("expression.py")
282-
config = THIS_DIR / "data" / "empty_pyproject.toml"
283285
expected, _ = read_data("expression.diff")
284286
tmp_file = Path(black.dump_to_file(source))
285287
try:
286288
result = BlackRunner().invoke(
287-
black.main, ["--diff", "--color", str(tmp_file), f"--config={config}"]
289+
black.main,
290+
["--diff", "--color", str(tmp_file), f"--config={EMPTY_CONFIG}"],
288291
)
289292
finally:
290293
os.unlink(tmp_file)
@@ -325,7 +328,9 @@ def test_skip_magic_trailing_comma(self) -> None:
325328
r"\d\d:\d\d:\d\d\.\d\d\d\d\d\d \+\d\d\d\d"
326329
)
327330
try:
328-
result = BlackRunner().invoke(black.main, ["-C", "--diff", str(tmp_file)])
331+
result = BlackRunner().invoke(
332+
black.main, ["-C", "--diff", str(tmp_file), f"--config={EMPTY_CONFIG}"]
333+
)
329334
self.assertEqual(result.exit_code, 0)
330335
finally:
331336
os.unlink(tmp_file)

0 commit comments

Comments
 (0)