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/bin | |
parent | Moved interface_generator script to bin (diff) | |
download | kernel-0d352b6ff19ea87980c4248554d6665f98908338.tar.xz |
Run python tests using pytest
Diffstat (limited to 'tools/interface_generator/bin')
-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 |
4 files changed, 30 insertions, 25 deletions
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) |