From b84a40a485b0563d572d14e748ad324185584344 Mon Sep 17 00:00:00 2001 From: Eugene Crosser Date: Tue, 31 May 2022 00:29:46 +0200 Subject: [PATCH] unittest: type checking and formatting --- debian/control | 11 +++++++---- test/__init__.py | 0 test/test_black.py | 24 ++++++++++++++++++++++++ test/test_mypy.py | 15 +++++++++++++++ 4 files changed, 46 insertions(+), 4 deletions(-) create mode 100644 test/__init__.py create mode 100644 test/test_black.py create mode 100644 test/test_mypy.py 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()}" + ) -- 2.39.2