]> www.average.org Git - loctrkd.git/blob - test/test_black.py
unittest: type checking and formatting
[loctrkd.git] / test / test_black.py
1 from glob import glob
2 from subprocess import run
3 from shutil import which
4 from unittest import TestCase
5
6
7 class BlackFormatter(TestCase):
8     def test_black(self):
9         if not which("black"):
10             self.fail(f"black not installed.")
11         cmd = (
12             ["black", "--check", "--diff", "-l", "79"]
13             + glob("gps303/**/*.py", recursive=True)
14             + glob("test/**/*.py", recursive=True)
15         )
16         output = run(cmd, capture_output=True)
17         if output.returncode == 1:
18             self.fail(
19                 f"black found code that needs reformatting:\n{output.stdout.decode()}"
20             )
21         if output.returncode != 0:
22             self.fail(
23                 f"black exited with code {output.returncode}:\n{output.stderr.decode()}"
24             )