diff options
author | aqua <aqua@iserlohn-fortress.net> | 2024-08-18 18:08:25 +0300 |
---|---|---|
committer | aqua <aqua@iserlohn-fortress.net> | 2024-08-18 18:08:25 +0300 |
commit | 0d352b6ff19ea87980c4248554d6665f98908338 (patch) | |
tree | 3d579e7151f79941f1b1a76d2c0ed2f22d6ef49e /tools/interface_generator | |
parent | Moved interface_generator script to bin (diff) | |
download | kernel-0d352b6ff19ea87980c4248554d6665f98908338.tar.xz |
Run python tests using pytest
Diffstat (limited to 'tools/interface_generator')
-rw-r--r-- | tools/interface_generator/.bazelrc | 2 | ||||
-rw-r--r-- | tools/interface_generator/bin/BUILD.bazel | 16 | ||||
-rwxr-xr-x | tools/interface_generator/bin/interface_generator.py | 4 | ||||
-rw-r--r-- | tools/interface_generator/bin/templates.py | 13 | ||||
-rwxr-xr-x | tools/interface_generator/bin/templates_unittest.py | 22 | ||||
-rw-r--r-- | tools/interface_generator/private/BUILD.bazel | 6 | ||||
-rw-r--r-- | tools/interface_generator/private/defs.bzl | 15 | ||||
-rw-r--r-- | tools/interface_generator/private/mypyrc | 2 | ||||
-rw-r--r-- | tools/interface_generator/private/pylintrc | 0 |
9 files changed, 50 insertions, 30 deletions
diff --git a/tools/interface_generator/.bazelrc b/tools/interface_generator/.bazelrc new file mode 100644 index 0000000..71d2e60 --- /dev/null +++ b/tools/interface_generator/.bazelrc @@ -0,0 +1,2 @@ +build --cxxopt=-std=c++20 + diff --git a/tools/interface_generator/bin/BUILD.bazel b/tools/interface_generator/bin/BUILD.bazel index c593b93..df23387 100644 --- a/tools/interface_generator/bin/BUILD.bazel +++ b/tools/interface_generator/bin/BUILD.bazel @@ -16,13 +16,6 @@ py_library( data = glob(["templates/*"]), ) -py_test( - name = "templates_unittest", - srcs = ["templates_unittest.py"], - imports = ["."], - deps = [":templates"], -) - """ interface_generator """ py_binary( @@ -31,7 +24,6 @@ py_binary( "interface_generator.py", "templates.py", ], - data = ["//:LICENSE.md"], imports = ["."], visibility = ["//visibility:public"], deps = [ @@ -45,13 +37,9 @@ py_binary( py_pytest( name = "pytest", - srcs = [ - "interface_definition.py", - "interface_generator.py", - "templates.py", - ], + srcs = glob(["*.py"]), + data = glob(["templates/*"]), deps = [ - ":interface_generator", requirement("mako"), ], ) diff --git a/tools/interface_generator/bin/interface_generator.py b/tools/interface_generator/bin/interface_generator.py index 90d03ba..04553e3 100755 --- a/tools/interface_generator/bin/interface_generator.py +++ b/tools/interface_generator/bin/interface_generator.py @@ -9,7 +9,7 @@ from pathlib import Path import sys from mako.lookup import TemplateLookup from interface_definition import parse as parse_interface -from templates import get_templates +from templates import get_templates, get_templates_dir PROG = { "name": "interface_generator", @@ -51,7 +51,7 @@ def main(): "-t", "--templates", type=Path, - default=Path(sys.argv[0]).parent / "templates", + default=get_templates_dir(), help="templates location", ) parser.add_argument( diff --git a/tools/interface_generator/bin/templates.py b/tools/interface_generator/bin/templates.py index d6a6bb5..9f7539e 100644 --- a/tools/interface_generator/bin/templates.py +++ b/tools/interface_generator/bin/templates.py @@ -4,9 +4,16 @@ from pathlib import Path import re -def get_templates(path: Path): +TEMPLATE_PATTERN = re.compile(r"^[^_]\S+\.mako$") + + +def get_templates_dir(name="templates") -> Path: + """get the templates directory""" + return Path(__file__).parent / name + + +def get_templates(path: Path) -> list[Path]: """list templates in given path""" - template_pattern = re.compile(r"^[^_]\S+\.mako$") result = list(path.glob("*.mako")) - result = [item for item in result if template_pattern.match(item.name)] + result = [item for item in result if TEMPLATE_PATTERN.match(item.name)] return result diff --git a/tools/interface_generator/bin/templates_unittest.py b/tools/interface_generator/bin/templates_unittest.py index feb418a..a5adf0f 100755 --- a/tools/interface_generator/bin/templates_unittest.py +++ b/tools/interface_generator/bin/templates_unittest.py @@ -1,18 +1,28 @@ #!/usr/bin/env python3 -import sys +""" +templates unit tests +""" + import unittest -import templates from pathlib import Path +import templates class Templates(unittest.TestCase): - def test_templates_dir_in_argv_0(self): - path = Path(sys.argv[0]).parent - self.assertTrue("templates" in [ item.name for item in path.iterdir() ]) + """templates unit tests""" + + def test_get_templates_dir_is_valid(self): + """verify that default templates dir is valid""" + path = templates.get_templates_dir() + + self.assertTrue(isinstance(path, Path)) + self.assertTrue(path.exists()) + self.assertTrue(path.is_dir()) def test_get_templates(self): - path = Path(sys.argv[0]).parent / "templates" + """verify that templates are available by default""" + path = templates.get_templates_dir() result = templates.get_templates(path) self.assertGreater(len(result), 0) diff --git a/tools/interface_generator/private/BUILD.bazel b/tools/interface_generator/private/BUILD.bazel index 46436ee..3012bcb 100644 --- a/tools/interface_generator/private/BUILD.bazel +++ b/tools/interface_generator/private/BUILD.bazel @@ -2,4 +2,8 @@ package(default_visibility = ["//:__pkg__"]) -exports_files(["pytest_wrapper.py"]) +exports_files([ + "mypyrc", + "pylintrc", + "pytest_wrapper.py", +]) diff --git a/tools/interface_generator/private/defs.bzl b/tools/interface_generator/private/defs.bzl index 080f19a..8e2ae8d 100644 --- a/tools/interface_generator/private/defs.bzl +++ b/tools/interface_generator/private/defs.bzl @@ -1,15 +1,19 @@ load("@pip//:requirements.bzl", "requirement") -def py_pytest(name, srcs, deps = [], **kwargs): +def py_pytest(name, srcs, deps = [], data = [], **kwargs): native.py_test( name = name, srcs = ["//private:pytest_wrapper.py"], main = "//private:pytest_wrapper.py", - data = srcs, + legacy_create_init = False, + imports = ["."], args = [ + "--capture=no", "--black", "--pylint", - #"--mypy", + "--pylint-rcfile=$(location //private:pylintrc)", + "--mypy", + "--mypy-config-file=$(location //private:mypyrc)", ] + ["$(location :%s)" % x for x in srcs], deps = [ requirement("pytest"), @@ -17,6 +21,9 @@ def py_pytest(name, srcs, deps = [], **kwargs): requirement("pytest-pylint"), requirement("pytest-mypy"), ] + deps, + data = [ + "//private:mypyrc", + "//private:pylintrc", + ] + srcs + data, **kwargs ) - diff --git a/tools/interface_generator/private/mypyrc b/tools/interface_generator/private/mypyrc new file mode 100644 index 0000000..d787271 --- /dev/null +++ b/tools/interface_generator/private/mypyrc @@ -0,0 +1,2 @@ +[mypy] +disable_error_code = import-untyped diff --git a/tools/interface_generator/private/pylintrc b/tools/interface_generator/private/pylintrc new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/tools/interface_generator/private/pylintrc |