2 from pkg_resources import get_distribution, DistributionNotFound
4 from subprocess import run
5 from shutil import which
6 from unittest import main, TestCase, skipUnless
8 from . import no_less_than
10 is_acceptable_verison = no_less_than("21.1")
14 vermatch = match("[\.\d]*", get_distribution("black").version)
15 if vermatch is not None:
16 black_version = vermatch.group()
17 except DistributionNotFound:
21 class BlackFormatter(TestCase):
23 is_acceptable_verison(black_version),
24 "Do not trust earlier black versions",
26 def test_black(self) -> None:
27 if not which("black"):
28 self.fail(f"black not installed.")
30 ["black", "--check", "--diff", "-l", "79"]
31 + glob("loctrkd/**/*.py", recursive=True)
32 + glob("test/**/*.py", recursive=True)
34 output = run(cmd, capture_output=True)
35 if output.returncode == 1:
37 f"black found code that needs reformatting:\n{output.stdout.decode()}"
39 if output.returncode != 0:
41 f"black exited with code {output.returncode}:\n{output.stderr.decode()}"
45 if __name__ == "__main__":