2 from pkg_resources import get_distribution, DistributionNotFound
4 from subprocess import run
5 from shutil import which
6 from unittest import TestCase, skipUnless
10 vermatch = match("[\.\d]*", get_distribution("black").version)
11 if vermatch is not None:
12 black_version = float(vermatch.group())
13 except DistributionNotFound:
17 class BlackFormatter(TestCase):
18 @skipUnless(black_version >= 21.1, "Do not trust earlier black versions")
19 def test_black(self) -> None:
20 if not which("black"):
21 self.fail(f"black not installed.")
23 ["black", "--check", "--diff", "-l", "79"]
24 + glob("gps303/**/*.py", recursive=True)
25 + glob("test/**/*.py", recursive=True)
27 output = run(cmd, capture_output=True)
28 if output.returncode == 1:
30 f"black found code that needs reformatting:\n{output.stdout.decode()}"
32 if output.returncode != 0:
34 f"black exited with code {output.returncode}:\n{output.stderr.decode()}"