]> www.average.org Git - loctrkd.git/blobdiff - test/test_black.py
test: make unittests individually runnable
[loctrkd.git] / test / test_black.py
index 4c34a770813414c8c2a48e8fcb93206374ac509e..cc72eae03d88bfb2f954f824fbafcf68254787cc 100644 (file)
@@ -1,10 +1,21 @@
 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
+
+black_version = 0.0
+try:
+    vermatch = match("[\.\d]*", get_distribution("black").version)
+    if vermatch is not None:
+        black_version = float(vermatch.group())
+except DistributionNotFound:
+    pass
 
 
 class BlackFormatter(TestCase):
+    @skipUnless(black_version >= 21.1, "Do not trust earlier black versions")
     def test_black(self) -> None:
         if not which("black"):
             self.fail(f"black not installed.")
@@ -22,3 +33,7 @@ class BlackFormatter(TestCase):
             self.fail(
                 f"black exited with code {output.returncode}:\n{output.stderr.decode()}"
             )
+
+
+if __name__ == "__main__":
+    main()