]> www.average.org Git - loctrkd.git/commitdiff
unittest: type checking and formatting
authorEugene Crosser <crosser@average.org>
Mon, 30 May 2022 22:29:46 +0000 (00:29 +0200)
committerEugene Crosser <crosser@average.org>
Mon, 30 May 2022 22:29:46 +0000 (00:29 +0200)
debian/control
test/__init__.py [new file with mode: 0644]
test/test_black.py [new file with mode: 0644]
test/test_mypy.py [new file with mode: 0644]

index 5746142fe4460550183c528141faf81aa022e99e..1075b9cb770a3b29fc2f17d37392e0c06d7acd68 100644 (file)
@@ -5,10 +5,13 @@ Priority: optional
 Standards-Version: 4.5.1
 X-Python-Version: >= 3.6
 Homepage: http://www.average.org/gps303
-Build-Depends: debhelper-compat (= 12),
- dh-python,
- python3-all,
- python3-setuptools,
+Build-Depends: black,
+               debhelper-compat (= 12),
+               dh-python,
+               mypy,
+               pylint,
+               python3-all,
+               python3-setuptools,
 
 Package: python3-gps303
 Architecture: all
diff --git a/test/__init__.py b/test/__init__.py
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/test/test_black.py b/test/test_black.py
new file mode 100644 (file)
index 0000000..519bc23
--- /dev/null
@@ -0,0 +1,24 @@
+from glob import glob
+from subprocess import run
+from shutil import which
+from unittest import TestCase
+
+
+class BlackFormatter(TestCase):
+    def test_black(self):
+        if not which("black"):
+            self.fail(f"black not installed.")
+        cmd = (
+            ["black", "--check", "--diff", "-l", "79"]
+            + glob("gps303/**/*.py", recursive=True)
+            + glob("test/**/*.py", recursive=True)
+        )
+        output = run(cmd, capture_output=True)
+        if output.returncode == 1:
+            self.fail(
+                f"black found code that needs reformatting:\n{output.stdout.decode()}"
+            )
+        if output.returncode != 0:
+            self.fail(
+                f"black exited with code {output.returncode}:\n{output.stderr.decode()}"
+            )
diff --git a/test/test_mypy.py b/test/test_mypy.py
new file mode 100644 (file)
index 0000000..3b8eaaf
--- /dev/null
@@ -0,0 +1,15 @@
+from subprocess import run
+from shutil import which
+from unittest import TestCase
+
+
+class TypeCheck(TestCase):
+    def test_mypy(self):
+        if not which("mypy"):
+            self.fail(f"mypy not installed.")
+        cmd = ["mypy", "--strict", "--ignore-missing-imports", "gps303"]
+        output = run(cmd, capture_output=True)
+        if output.returncode != 0:
+            self.fail(
+                f"mypy exited with code {output.returncode}:\n{output.stderr.decode()}"
+            )