]> www.average.org Git - loctrkd.git/blobdiff - test/test_black.py
Update changelog for 2.00 release
[loctrkd.git] / test / test_black.py
index 519bc23deea55bdcbd3e80fdf6e96ec29f686641..76275af47918482a706ffdebd64edf9dc8a1c0ff 100644 (file)
@@ -1,16 +1,34 @@
 from glob import glob
+from pkg_resources import get_distribution, DistributionNotFound
+from re import match
 from subprocess import run
 from shutil import which
-from unittest import TestCase
+from unittest import main, TestCase, skipUnless
+
+from . import no_less_than
+
+is_acceptable_verison = no_less_than("21.1")
+
+black_version = "0.0"
+try:
+    vermatch = match("[\.\d]*", get_distribution("black").version)
+    if vermatch is not None:
+        black_version = vermatch.group()
+except DistributionNotFound:
+    pass
 
 
 class BlackFormatter(TestCase):
-    def test_black(self):
+    @skipUnless(
+        is_acceptable_verison(black_version),
+        "Do not trust earlier black versions",
+    )
+    def test_black(self) -> None:
         if not which("black"):
             self.fail(f"black not installed.")
         cmd = (
             ["black", "--check", "--diff", "-l", "79"]
-            + glob("gps303/**/*.py", recursive=True)
+            + glob("loctrkd/**/*.py", recursive=True)
             + glob("test/**/*.py", recursive=True)
         )
         output = run(cmd, capture_output=True)
@@ -22,3 +40,7 @@ class BlackFormatter(TestCase):
             self.fail(
                 f"black exited with code {output.returncode}:\n{output.stderr.decode()}"
             )
+
+
+if __name__ == "__main__":
+    main()