From: Eugene Crosser Date: Mon, 30 May 2022 22:29:46 +0000 (+0200) Subject: unittest: type checking and formatting X-Git-Tag: 0.96~1 X-Git-Url: http://www.average.org/gitweb/?p=loctrkd.git;a=commitdiff_plain;h=b84a40a485b0563d572d14e748ad324185584344 unittest: type checking and formatting --- diff --git a/debian/control b/debian/control index 5746142..1075b9c 100644 --- a/debian/control +++ b/debian/control @@ -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 index 0000000..e69de29 diff --git a/test/test_black.py b/test/test_black.py new file mode 100644 index 0000000..519bc23 --- /dev/null +++ b/test/test_black.py @@ -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 index 0000000..3b8eaaf --- /dev/null +++ b/test/test_mypy.py @@ -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()}" + )