From 1b109c45da2da912776aaa44826ed06e7f8209cf Mon Sep 17 00:00:00 2001 From: JensDiemer Date: Tue, 16 Jan 2024 19:42:35 +0100 Subject: [PATCH] Use typeguard in tests --- README.md | 1 + inventory_project/__main__.py | 10 ++++++++++ pyproject.toml | 1 + requirements.dev.txt | 5 +++++ 4 files changed, 17 insertions(+) diff --git a/README.md b/README.md index 3f36c13..fbe47f4 100644 --- a/README.md +++ b/README.md @@ -162,6 +162,7 @@ To make a new release, do this: [comment]: <> (✂✂✂ auto generated history start ✂✂✂) * [**dev**](https://github.com/jedie/PyInventory/compare/v0.19.3...main) + * 2024-01-16 - Use typeguard in tests * 2024-01-16 - Update requirements * [v0.19.3](https://github.com/jedie/PyInventory/compare/v0.19.2...v0.19.3) * 2023-11-01 - Auto generate README history diff --git a/inventory_project/__main__.py b/inventory_project/__main__.py index 6a970ca..a918056 100644 --- a/inventory_project/__main__.py +++ b/inventory_project/__main__.py @@ -2,7 +2,11 @@ Allow your-cool-package to be executable through `python -m inventory`. """ + +import sys + from manage_django_project.manage import execute_django_from_command_line +from typeguard import install_import_hook def main(): @@ -10,6 +14,12 @@ def main(): entrypoint installed via pyproject.toml and [project.scripts] section. Must be set in ./manage.py and PROJECT_SHELL_SCRIPT """ + + if 'test' in sys.argv: + # Install typeguard import hook to check for missing type annotations. + # Sadly we can't add this into: cli_base/tests/__init__.py + install_import_hook(packages=('inventory', 'inventory_project')) + execute_django_from_command_line() diff --git a/pyproject.toml b/pyproject.toml index 7691e8b..96a6cd4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -51,6 +51,7 @@ dev = [ "safety", # https://github.com/pyupio/safety "mypy", # https://github.com/python/mypy "twine", # https://github.com/pypa/twine + "typeguard", # https://github.com/agronholm/typeguard/ # https://github.com/akaihola/darker # https://github.com/ikamensh/flynt diff --git a/requirements.dev.txt b/requirements.dev.txt index ddf9bb2..9e9174c 100644 --- a/requirements.dev.txt +++ b/requirements.dev.txt @@ -1411,6 +1411,10 @@ twine==4.0.2 \ --hash=sha256:929bc3c280033347a00f847236564d1c52a3e61b1ac2516c97c48f3ceab756d8 \ --hash=sha256:9e102ef5fdd5a20661eb88fad46338806c3bd32cf1db729603fe3697b1bc83c8 # via PyInventory (pyproject.toml) +typeguard==4.1.5 \ + --hash=sha256:8923e55f8873caec136c892c3bed1f676eae7be57cdb94819281b3d3bc9c0953 \ + --hash=sha256:ea0a113bbc111bcffc90789ebb215625c963411f7096a7e9062d4e4630c155fd + # via PyInventory (pyproject.toml) types-python-dateutil==2.8.19.20240106 \ --hash=sha256:1f8db221c3b98e6ca02ea83a58371b22c374f42ae5bbdf186db9c9a76581459f \ --hash=sha256:efbbdc54590d0f16152fa103c9879c7d4a00e82078f6e2cf01769042165acaa2 @@ -1425,6 +1429,7 @@ typing-extensions==4.9.0 \ # mypy # pyee # rich-click + # typeguard urllib3==2.1.0 \ --hash=sha256:55901e917a5896a349ff771be919f8bd99aff50b79fe58fec595eb37bbc56bb3 \ --hash=sha256:df7aa8afb0148fa78488e7899b2c59b5f4ffcfa82e6c54ccb9dd37c1d7b52d54