From 9ca9720f22e6c7563c71aabfc3d76566c618ad94 Mon Sep 17 00:00:00 2001 From: grdddj Date: Fri, 27 May 2022 16:15:21 +0200 Subject: [PATCH] feat(tests): add test for supporting older python versions --- Makefile | 3 ++ ci/test.yml | 7 +++++ docs/ci/jobs.md | 10 +++--- tests/test_python_support.py | 60 ++++++++++++++++++++++++++++++++++++ 4 files changed, 76 insertions(+), 4 deletions(-) create mode 100755 tests/test_python_support.py diff --git a/Makefile b/Makefile index 72ee6e849..77b2c91e5 100644 --- a/Makefile +++ b/Makefile @@ -92,6 +92,9 @@ ruststyle_check: @echo [RUSTFMT] @cd core/embed/rust ; cargo fmt -- --check +python_support_check: + ./tests/test_python_support.py + ## code generation commands: mocks: ## generate mock python headers from C modules diff --git a/ci/test.yml b/ci/test.yml index 4fa40da5c..b5b421ef6 100644 --- a/ci/test.yml +++ b/ci/test.yml @@ -623,6 +623,13 @@ python test: # https://github.com/NixOS/nixpkgs/pull/98915 - nix-shell --arg fullDeps true --run "unset _PYTHON_SYSCONFIGDATA_NAME && cd python && poetry run tox | ts -s" +python support test: + stage: test + <<: *gitlab_caching + needs: [] + script: + - nix-shell --run "poetry run make python_support_check | ts -s" + # Storage diff --git a/docs/ci/jobs.md b/docs/ci/jobs.md index cfb8e9518..a9e4418e5 100644 --- a/docs/ci/jobs.md +++ b/docs/ci/jobs.md @@ -141,7 +141,7 @@ Bitcoin-only version. ## TEST stage - [test.yml](../../ci/test.yml) All the tests run test cases on the freshly built emulators from the previous `BUILD` stage. -Consists of **34 jobs** below: +Consists of **35 jobs** below: ### [core unit test](https://github.com/trezor/trezor-firmware/blob/master/ci/test.yml#L15) Python and rust unit tests, checking TT functionality. @@ -219,11 +219,13 @@ Persistence tests. ### [python test](https://github.com/trezor/trezor-firmware/blob/master/ci/test.yml#L600) -### [storage test](https://github.com/trezor/trezor-firmware/blob/master/ci/test.yml#L629) +### [python support test](https://github.com/trezor/trezor-firmware/blob/master/ci/test.yml#L626) -### [core unix memory profiler](https://github.com/trezor/trezor-firmware/blob/master/ci/test.yml#L653) +### [storage test](https://github.com/trezor/trezor-firmware/blob/master/ci/test.yml#L636) -### [connect test core](https://github.com/trezor/trezor-firmware/blob/master/ci/test.yml#L677) +### [core unix memory profiler](https://github.com/trezor/trezor-firmware/blob/master/ci/test.yml#L660) + +### [connect test core](https://github.com/trezor/trezor-firmware/blob/master/ci/test.yml#L684) --- ## TEST-HW stage - [test-hw.yml](../../ci/test-hw.yml) diff --git a/tests/test_python_support.py b/tests/test_python_support.py new file mode 100755 index 000000000..f0082804e --- /dev/null +++ b/tests/test_python_support.py @@ -0,0 +1,60 @@ +#!/usr/bin/env python3 +""" +Verifying that all the tools can be run even by older python versions. + +Uses `pyright --pythonversion 3.X ` output to check for substrings that +indicate the type-hints in the code are not compatible with this version. +""" + +import os +import subprocess +import sys +from pathlib import Path + +HERE = Path(__file__).resolve().parent +ROOT_DIR = HERE.parent + +EXIT_CODE = 0 + +os.chdir(ROOT_DIR) + +versions_to_check = [ + "3.7", + "3.8", + "3.9", +] + +dirs_to_check = [ + "tools", + "common", + "core/tools", +] + +signs_of_issues = [ + "is unknown import symbol", # we need to import some stuff from typing_extensions instead of typing + "will generate runtime exception", # happens when using `dict` or `list` as a type alias +] + + +def check_directory(path: str, python_version: str) -> None: + global EXIT_CODE + cmd = ( + "pyright", + "--pythonversion", + python_version, + path, + ) + + result = subprocess.run(cmd, stdout=subprocess.PIPE, text=True) + for line in result.stdout.splitlines(): + if any(sign in line for sign in signs_of_issues): + print(line) + EXIT_CODE = 1 + + +for version in versions_to_check: + print(f"Checking python version {version}") + for dir_to_check in dirs_to_check: + check_directory(dir_to_check, version) + +sys.exit(EXIT_CODE)