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.
There's three optimizations in this commit:
1. Don't check if Black's output is stable or equivalant if no changes
were made in the first place. It's not like passing the same code
(for both source and actual) through black.assert_equivalent or
black.assert_stable is useful. It's not a big deal for the smaller
tests, but it eats a lot of time in tests/test_format.py since
its test cases are big. This is also closer to how Black works IRL.
2. Use a smaller file for `test_root_logger_not_used_directly` since
the logging it's checking happens during blib2to3's startup so the
file doesn't really matter.
3. If we're checking a file is formatting (i.e. test_source_is_formatted)
don't run Black over it again with `black.format_file_in_place`.
`tests/test_format.py::TestSimpleFormat.check_file` is good enough.
)
self.assertEqual(result.exit_code, 0)
self.assertFormatEqual(expected, result.output)
)
self.assertEqual(result.exit_code, 0)
self.assertFormatEqual(expected, result.output)
- black.assert_equivalent(source, result.output)
- black.assert_stable(source, result.output, DEFAULT_MODE)
+ if source != result.output:
+ black.assert_equivalent(source, result.output)
+ black.assert_stable(source, result.output, DEFAULT_MODE)
def test_piping_diff(self) -> None:
diff_header = re.compile(
def test_piping_diff(self) -> None:
diff_header = re.compile(
critical=fail,
log=fail,
):
critical=fail,
log=fail,
):
+ ff(THIS_DIR / "util.py")
def test_invalid_config_return_code(self) -> None:
tmp_file = Path(black.dump_to_file())
def test_invalid_config_return_code(self) -> None:
tmp_file = Path(black.dump_to_file())
from tests.util import (
BlackBaseTestCase,
fs,
from tests.util import (
BlackBaseTestCase,
fs,
DEFAULT_MODE,
dump_to_stderr,
read_data,
DEFAULT_MODE,
dump_to_stderr,
read_data,
def test_source_is_formatted(self, filename: str) -> None:
path = THIS_DIR.parent / filename
self.check_file(str(path), DEFAULT_MODE, data=False)
def test_source_is_formatted(self, filename: str) -> None:
path = THIS_DIR.parent / filename
self.check_file(str(path), DEFAULT_MODE, data=False)
- self.assertFalse(ff(path))
def check_file(self, filename: str, mode: black.Mode, *, data: bool = True) -> None:
source, expected = read_data(filename, data=data)
actual = fs(source, mode=mode)
self.assertFormatEqual(expected, actual)
def check_file(self, filename: str, mode: black.Mode, *, data: bool = True) -> None:
source, expected = read_data(filename, data=data)
actual = fs(source, mode=mode)
self.assertFormatEqual(expected, actual)
- black.assert_equivalent(source, actual)
- black.assert_stable(source, actual, mode)
+ if source != actual:
+ black.assert_equivalent(source, actual)
+ black.assert_stable(source, actual, mode)