From 1ef3b4c92b54bf0530efb01424b65856b44a25ef Mon Sep 17 00:00:00 2001 From: Michael Carlstrom Date: Fri, 9 Aug 2024 14:25:29 -0400 Subject: [PATCH] Add ament_mypy unit test and export types (#95) * add ament_mypy unit test Signed-off-by: Michael Carlstrom * skip docs Signed-off-by: Michael Carlstrom * fixes conf.py Signed-off-by: Michael Carlstrom --------- Signed-off-by: Michael Carlstrom --- ament_index_python/ament_index_python/cli.py | 4 ++-- ament_index_python/docs/source/conf.py | 8 +++++--- ament_index_python/package.xml | 1 + ament_index_python/py.typed | 0 ament_index_python/test/test_mypy.py | 20 ++++++++++++++++++++ 5 files changed, 28 insertions(+), 5 deletions(-) create mode 100644 ament_index_python/py.typed create mode 100644 ament_index_python/test/test_mypy.py diff --git a/ament_index_python/ament_index_python/cli.py b/ament_index_python/ament_index_python/cli.py index 4fa8f67..775eeea 100644 --- a/ament_index_python/ament_index_python/cli.py +++ b/ament_index_python/ament_index_python/cli.py @@ -27,11 +27,11 @@ def main(argv: List[str] = sys.argv[1:]) -> Optional[str]: arg = parser.add_argument( 'resource_type', nargs='?', metavar='TYPE', help='The type of the resource') - arg.completer = resource_type_completer + arg.completer = resource_type_completer # type: ignore[attr-defined] arg = parser.add_argument( 'resource_name', nargs='?', metavar='NAME', help='The name of the resource') - arg.completer = resource_name_completer + arg.completer = resource_name_completer # type: ignore[attr-defined] try: from argcomplete import autocomplete diff --git a/ament_index_python/docs/source/conf.py b/ament_index_python/docs/source/conf.py index ffcb7f9..052cc8a 100644 --- a/ament_index_python/docs/source/conf.py +++ b/ament_index_python/docs/source/conf.py @@ -30,6 +30,8 @@ # import sys # sys.path.insert(0, os.path.abspath('.')) +# -- Imports ----------------------------------------------------- +from typing import Dict, List, Sequence # -- Project information ----------------------------------------------------- @@ -82,7 +84,7 @@ # List of patterns, relative to source directory, that match files and # directories to ignore when looking for source files. # This pattern also affects html_static_path and html_extra_path. -exclude_patterns = [] +exclude_patterns: Sequence[str] = [] # The name of the Pygments (syntax highlighting) style to use. pygments_style = None @@ -104,7 +106,7 @@ # Add any paths that contain custom static files (such as style sheets) here, # relative to this directory. They are copied after the builtin static files, # so a file named "default.css" will overwrite the builtin "default.css". -html_static_path = [] +html_static_path: List[str] = [] # Custom sidebar templates, must be a dictionary that maps document names # to template names. @@ -125,7 +127,7 @@ # -- Options for LaTeX output ------------------------------------------------ -latex_elements = { +latex_elements: Dict[str, str] = { # The paper size ('letterpaper' or 'a4paper'). # # 'papersize': 'letterpaper', diff --git a/ament_index_python/package.xml b/ament_index_python/package.xml index bc15f95..dc2646e 100644 --- a/ament_index_python/package.xml +++ b/ament_index_python/package.xml @@ -18,6 +18,7 @@ ament_copyright ament_flake8 ament_pep257 + ament_mypy python3-pytest diff --git a/ament_index_python/py.typed b/ament_index_python/py.typed new file mode 100644 index 0000000..e69de29 diff --git a/ament_index_python/test/test_mypy.py b/ament_index_python/test/test_mypy.py new file mode 100644 index 0000000..16d0794 --- /dev/null +++ b/ament_index_python/test/test_mypy.py @@ -0,0 +1,20 @@ +# Copyright 2024 Open Source Robotics Foundation, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from ament_mypy.main import main + + +def test_mypy() -> None: + rc = main(argv=['--exclude', 'test']) + assert rc == 0, 'Found code style errors / warnings'