Merge branch 'add-ament-mypy-tests' into 'master'
Add mypy tests through ament_mypy See merge request micro-ROS/ros_tracing/ros2_tracing!147
This commit is contained in:
commit
a6432f958f
15 changed files with 120 additions and 23 deletions
|
@ -14,6 +14,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>
|
||||
|
|
22
ros2trace/test/test_mypy.py
Normal file
22
ros2trace/test/test_mypy.py
Normal 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'
|
|
@ -15,6 +15,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>
|
||||
|
|
22
tracetools_launch/test/test_mypy.py
Normal file
22
tracetools_launch/test/test_mypy.py
Normal 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'
|
|
@ -12,6 +12,7 @@
|
|||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from typing import List
|
||||
import unittest
|
||||
|
||||
from tracetools_launch.action import Trace
|
||||
|
@ -26,7 +27,7 @@ class TestTraceAction(unittest.TestCase):
|
|||
)
|
||||
|
||||
def test_has_profiling_events(self) -> None:
|
||||
events_lists_match = [
|
||||
events_lists_match: List[List[str]] = [
|
||||
[
|
||||
'lttng_ust_cyg_profile_fast:func_entry',
|
||||
'hashtag:yopo',
|
||||
|
@ -37,7 +38,7 @@ class TestTraceAction(unittest.TestCase):
|
|||
'lttng_ust_cyg_profile:func_exit',
|
||||
],
|
||||
]
|
||||
events_lists_no_match = [
|
||||
events_lists_no_match: List[List[str]] = [
|
||||
[
|
||||
'lttng_ust_statedump:bin_info',
|
||||
'ros2:event',
|
||||
|
@ -50,7 +51,7 @@ class TestTraceAction(unittest.TestCase):
|
|||
self.assertFalse(Trace.has_profiling_events(events))
|
||||
|
||||
def test_has_ust_memory_events(self) -> None:
|
||||
events_lists_match = [
|
||||
events_lists_match: List[List[str]] = [
|
||||
[
|
||||
'hashtag:yopo',
|
||||
'lttng_ust_libc:malloc',
|
||||
|
@ -60,7 +61,7 @@ class TestTraceAction(unittest.TestCase):
|
|||
'lttng_ust_libc:still_a_match',
|
||||
],
|
||||
]
|
||||
events_lists_no_match = [
|
||||
events_lists_no_match: List[List[str]] = [
|
||||
[],
|
||||
[
|
||||
'my_random:event',
|
||||
|
|
|
@ -77,7 +77,7 @@ class Trace(Action):
|
|||
self.__context_names = context_names
|
||||
self.__profile_fast = profile_fast
|
||||
self.__logger = logging.get_logger(__name__)
|
||||
self.__ld_preload_actions = []
|
||||
self.__ld_preload_actions: List[LdPreload] = []
|
||||
# Add LD_PRELOAD actions if corresponding events are enabled
|
||||
if self.has_profiling_events(self.__events_ust):
|
||||
self.__ld_preload_actions.append(
|
||||
|
|
|
@ -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>
|
||||
|
|
22
tracetools_read/test/test_mypy.py
Normal file
22
tracetools_read/test/test_mypy.py
Normal 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'
|
|
@ -23,9 +23,6 @@ import babeltrace
|
|||
from . import DictEvent
|
||||
|
||||
|
||||
BabeltraceEvent = babeltrace.babeltrace.Event
|
||||
|
||||
|
||||
def is_trace_directory(path: str) -> bool:
|
||||
"""
|
||||
Check recursively if a path is a trace directory.
|
||||
|
@ -42,7 +39,7 @@ def is_trace_directory(path: str) -> bool:
|
|||
return traces is not None and len(traces) > 0
|
||||
|
||||
|
||||
def get_trace_ctf_events(trace_directory: str) -> Iterable[BabeltraceEvent]:
|
||||
def get_trace_ctf_events(trace_directory: str) -> Iterable[babeltrace.babeltrace.Event]:
|
||||
"""
|
||||
Get the events of a trace.
|
||||
|
||||
|
@ -61,7 +58,10 @@ def get_trace_events(trace_directory: str) -> List[DictEvent]:
|
|||
:param trace_directory: the path to the main/top trace directory
|
||||
:return: events
|
||||
"""
|
||||
return [event_to_dict(event) for event in get_trace_ctf_events(trace_directory)]
|
||||
events: List[DictEvent] = [
|
||||
event_to_dict(event) for event in get_trace_ctf_events(trace_directory)
|
||||
]
|
||||
return events
|
||||
|
||||
|
||||
# List of ignored CTF fields
|
||||
|
@ -82,7 +82,7 @@ _IGNORED_FIELDS = [
|
|||
_DISCARD = 'events_discarded'
|
||||
|
||||
|
||||
def event_to_dict(event: BabeltraceEvent) -> DictEvent:
|
||||
def event_to_dict(event: babeltrace.babeltrace.Event) -> DictEvent:
|
||||
"""
|
||||
Convert name, timestamp, and all other keys except those in IGNORED_FIELDS into a dictionary.
|
||||
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
<exec_depend>std_msgs</exec_depend>
|
||||
<exec_depend>std_srvs</exec_depend>
|
||||
|
||||
<test_depend>ament_cmake_mypy</test_depend>
|
||||
<test_depend>ament_cmake_pytest</test_depend>
|
||||
<test_depend>ament_lint_auto</test_depend>
|
||||
<test_depend>ament_lint_common</test_depend>
|
||||
|
|
|
@ -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>
|
||||
|
|
22
tracetools_trace/test/test_mypy.py
Normal file
22
tracetools_trace/test/test_mypy.py
Normal 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'
|
|
@ -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)')
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -41,7 +41,10 @@ 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]
|
||||
filtered_doc_lines: List[str] = list(filter(None, doc_lines))
|
||||
if len(filtered_doc_lines) == 0:
|
||||
return None
|
||||
first_line = filtered_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 +147,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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue