Add mypy tests through ament_mypy

Signed-off-by: Christophe Bedard <bedard.christophe@gmail.com>
This commit is contained in:
Christophe Bedard 2020-03-01 11:50:31 -05:00
parent aa59950fe2
commit 9450bfeea9
15 changed files with 117 additions and 23 deletions

View file

@ -13,6 +13,7 @@
<test_depend>ament_copyright</test_depend>
<test_depend>ament_flake8</test_depend>
<test_depend>ament_mypy</test_depend>
<test_depend>ament_pep257</test_depend>
<test_depend>ament_xmllint</test_depend>
<test_depend>python3-pytest</test_depend>

View file

@ -0,0 +1,22 @@
# Copyright 2019 Canonical Ltd
#
# 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
import pytest
@pytest.mark.mypy
@pytest.mark.linter
def test_mypy():
assert main(argv=[]) == 0, 'Found errors'

View file

@ -31,14 +31,14 @@ class DefaultArgValueCompleter:
return self.list
def parse_args():
def parse_args() -> argparse.Namespace:
"""Parse args for tracing."""
parser = argparse.ArgumentParser(description='Setup and launch an LTTng tracing session.')
add_arguments(parser)
return parser.parse_args()
def add_arguments(parser: argparse.ArgumentParser):
def add_arguments(parser: argparse.ArgumentParser) -> None:
parser.add_argument(
'-s', '--session-name', dest='session_name',
default=path.append_timestamp('session'),
@ -47,27 +47,27 @@ def add_arguments(parser: argparse.ArgumentParser):
'-p', '--path', dest='path',
default=path.DEFAULT_BASE_PATH,
help='path of the base directory for trace data (default: %(default)s)')
arg = parser.add_argument(
events_ust_arg = parser.add_argument( # type: ignore
'-u', '--ust', nargs='*', dest='events_ust',
default=names.DEFAULT_EVENTS_ROS,
help='the ROS UST events to enable (default: see tracetools_trace.tools.names) '
'[to disable all UST events, '
'provide this flag without any event name]')
arg.completer = DefaultArgValueCompleter(arg)
arg = parser.add_argument(
events_ust_arg.completer = DefaultArgValueCompleter(events_ust_arg) # type: ignore
events_kernel_arg = parser.add_argument( # type: ignore
'-k', '--kernel', nargs='*', dest='events_kernel',
default=names.DEFAULT_EVENTS_KERNEL,
help='the kernel events to enable (default: see tracetools_trace.tools.names) '
'[to disable all kernel events, '
'provide this flag without any event name]')
arg.completer = DefaultArgValueCompleter(arg)
arg = parser.add_argument(
events_kernel_arg.completer = DefaultArgValueCompleter(events_kernel_arg) # type: ignore
context_arg = parser.add_argument( # type: ignore
'-c', '--context', nargs='*', dest='context_names',
default=names.DEFAULT_CONTEXT,
help='the context names to enable (default: see tracetools_trace.tools.names) '
'[to disable all context names, '
'provide this flag without any name]')
arg.completer = DefaultArgValueCompleter(arg)
context_arg.completer = DefaultArgValueCompleter(context_arg) # type: ignore
parser.add_argument(
'-l', '--list', dest='list', action='store_true',
help='display lists of enabled events and context names (default: %(default)s)')

View file

@ -22,7 +22,7 @@ from typing import Optional
try:
from . import lttng_impl
_lttng = lttng_impl
_lttng = lttng_impl # type: ignore
# Check lttng module version
from distutils.version import StrictVersion
@ -37,7 +37,7 @@ except ImportError:
# Fall back on stub functions so that this still passes linter checks
from . import lttng_stub
_lttng = lttng_stub
_lttng = lttng_stub # type: ignore
from .names import DEFAULT_CONTEXT
from .names import DEFAULT_EVENTS_KERNEL

View file

@ -41,7 +41,7 @@ def get_version() -> Union[StrictVersion, None]:
:return: the version as a StrictVersion object, or `None` if it cannot be extracted
"""
doc_lines = lttng.__doc__.split('\n')
first_line = list(filter(None, doc_lines))[0]
first_line: str = list(filter(None, doc_lines))[0]
version_string = first_line.split(' ')[1]
if not re.compile(r'^[0-9]+\.[0-9]+\.[0-9]+$').match(version_string):
return None
@ -144,7 +144,7 @@ def setup(
# TODO make it possible to add context in userspace and kernel separately, since some context
# types might only apply to userspace OR kernel; only consider userspace contexts for now
handles_context = [handle_ust]
enabled_handles = list(filter(None, handles_context))
enabled_handles: List[lttng.Handle] = list(filter(None, handles_context))
_add_context(enabled_handles, context_list)
return full_path