]>
git.madduck.net Git - etc/vim.git/blobdiff - tests/test_black.py
madduck's git repository
Every one of the projects in this repository is available at the canonical
URL git://git.madduck.net/madduck/pub/<projectpath> — see
each project's metadata for the exact URL.
All patches and comments are welcome. Please squash your changes to logical
commits before using git-format-patch and git-send-email to
patches@ git. madduck. net .
If you'd read over the Git project's submission guidelines and adhered to them,
I'd be especially grateful.
SSH access, as well as push access can be individually
arranged .
If you use my repositories frequently, consider adding the following
snippet to ~/.gitconfig and using the third clone URL listed for each
project:
[url "git://git.madduck.net/madduck/"]
insteadOf = madduck:
from io import BytesIO, TextIOWrapper
import os
from pathlib import Path
from io import BytesIO, TextIOWrapper
import os
from pathlib import Path
import sys
from tempfile import TemporaryDirectory
from typing import Any, List, Tuple, Iterator
import unittest
from unittest.mock import patch
import sys
from tempfile import TemporaryDirectory
from typing import Any, List, Tuple, Iterator
import unittest
from unittest.mock import patch
from click import unstyle
from click.testing import CliRunner
import black
from click import unstyle
from click.testing import CliRunner
import black
ll = 88
ff = partial(black.format_file_in_place, line_length=ll, fast=True)
fs = partial(black.format_str, line_length=ll)
ll = 88
ff = partial(black.format_file_in_place, line_length=ll, fast=True)
fs = partial(black.format_str, line_length=ll)
black.assert_stable(source, actual, line_length=ll)
def test_piping_diff(self) -> None:
black.assert_stable(source, actual, line_length=ll)
def test_piping_diff(self) -> None:
+ diff_header = re.compile(
+ rf"(STDIN|STDOUT)\t\d\d\d\d-\d\d-\d\d "
+ rf"\d\d:\d\d:\d\d\.\d\d\d\d\d\d \+\d\d\d\d"
+ )
source, _ = read_data("expression.py")
expected, _ = read_data("expression.diff")
hold_stdin, hold_stdout = sys.stdin, sys.stdout
try:
sys.stdin = TextIOWrapper(BytesIO(source.encode("utf8")), encoding="utf8")
sys.stdout = TextIOWrapper(BytesIO(), encoding="utf8")
source, _ = read_data("expression.py")
expected, _ = read_data("expression.diff")
hold_stdin, hold_stdout = sys.stdin, sys.stdout
try:
sys.stdin = TextIOWrapper(BytesIO(source.encode("utf8")), encoding="utf8")
sys.stdout = TextIOWrapper(BytesIO(), encoding="utf8")
- sys.stdin.buffer.name = "<stdin>" # type: ignore
black.format_stdin_to_stdout(
line_length=ll, fast=True, write_back=black.WriteBack.DIFF
)
sys.stdout.seek(0)
actual = sys.stdout.read()
black.format_stdin_to_stdout(
line_length=ll, fast=True, write_back=black.WriteBack.DIFF
)
sys.stdout.seek(0)
actual = sys.stdout.read()
+ actual = diff_header.sub("[Deterministic header]", actual)
finally:
sys.stdin, sys.stdout = hold_stdin, hold_stdout
actual = actual.rstrip() + "\n" # the diff output has a trailing space
finally:
sys.stdin, sys.stdout = hold_stdin, hold_stdout
actual = actual.rstrip() + "\n" # the diff output has a trailing space
source, _ = read_data("expression.py")
expected, _ = read_data("expression.diff")
tmp_file = Path(black.dump_to_file(source))
source, _ = read_data("expression.py")
expected, _ = read_data("expression.diff")
tmp_file = Path(black.dump_to_file(source))
+ diff_header = re.compile(
+ rf"{re.escape(str(tmp_file))}\t\d\d\d\d-\d\d-\d\d "
+ rf"\d\d:\d\d:\d\d\.\d\d\d\d\d\d \+\d\d\d\d"
+ )
hold_stdout = sys.stdout
try:
sys.stdout = TextIOWrapper(BytesIO(), encoding="utf8")
self.assertTrue(ff(tmp_file, write_back=black.WriteBack.DIFF))
sys.stdout.seek(0)
actual = sys.stdout.read()
hold_stdout = sys.stdout
try:
sys.stdout = TextIOWrapper(BytesIO(), encoding="utf8")
self.assertTrue(ff(tmp_file, write_back=black.WriteBack.DIFF))
sys.stdout.seek(0)
actual = sys.stdout.read()
- actual = actual.replace(str(tmp_file), "<stdin>" )
+ actual = diff_header.sub("[Deterministic header]", actual )
finally:
sys.stdout = hold_stdout
os.unlink(tmp_file)
finally:
sys.stdout = hold_stdout
os.unlink(tmp_file)