Skip to content

Commit

Permalink
fix: add max_construction_order to the command line argument (#173)
Browse files Browse the repository at this point in the history
* Add max_construction_order to the command line argument to use Architecture().

Signed-off-by: ISP akm <[email protected]>

* max_construction_order=0 means unlimited

Signed-off-by: ISP akm <[email protected]>

* for pytest

Signed-off-by: ISP akm <[email protected]>

* Review response: name the argument max_callback_construction_order_on_path_searching.

Signed-off-by: ISP akm <[email protected]>

* Corrected help messages

Signed-off-by: ISP akm <[email protected]>

* Changed argument name to max_callback_construction_order_on_path_searching.

Signed-off-by: ISP akm <[email protected]>

* PEP8 compatible

Signed-off-by: ISP akm <[email protected]>

* Changed construction order thresholds to be taken from caret_analyze. Changed help messages and argument checks accordingly.

Signed-off-by: ISP akm <[email protected]>

* for pytest

Signed-off-by: ISP akm <[email protected]>

* for pytest

Signed-off-by: ISP akm <[email protected]>

* for pytest

Signed-off-by: ISP akm <[email protected]>

* Use MAX_CALLBACK_CONSTRUCTION_ORDER_ON_PATH_SEARCHING in the test code.

Signed-off-by: ISP akm <[email protected]>

* for pytest

Signed-off-by: ISP akm <[email protected]>

* for pytest

Signed-off-by: ISP akm <[email protected]>

* for pytest

Signed-off-by: ISP akm <[email protected]>

* for pytest

Signed-off-by: ISP akm <[email protected]>

* DEFAULT_MAX_CALLBACK_CONSTRUCTION_ORDER_ON_PATH_SEARCHING

Signed-off-by: ISP akm <[email protected]>

* for pytest

Signed-off-by: ISP akm <[email protected]>

* fixed

Signed-off-by: ISP akm <[email protected]>

* fixed

Signed-off-by: ISP akm <[email protected]>

* fixed

Signed-off-by: ISP akm <[email protected]>

---------

Signed-off-by: ISP akm <[email protected]>
  • Loading branch information
xygyo77 authored Mar 5, 2024
1 parent a7aeedc commit c84d4dd
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 15 deletions.
31 changes: 26 additions & 5 deletions ros2caret/verb/check_ctf.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@

from logging import getLogger

from caret_analyze import Architecture, Lttng
from caret_analyze.exceptions import Error
from caret_analyze import (Architecture,
DEFAULT_MAX_CALLBACK_CONSTRUCTION_ORDER_ON_PATH_SEARCHING,
Lttng)
from ros2caret.verb import VerbExtension

logger = getLogger(__name__)
Expand All @@ -28,10 +29,30 @@ def add_arguments(self, parser, cli_name):
parser.add_argument(
'trace_dir', type=str,
help='the path to the trace directory to be checked')
parser.add_argument(
'-m', '--max_callback_construction_order_on_path_searching',
type=int, dest='max_callback_construction_order_on_path_searching',
help='callbacks whose construction_order are greater than'
' this value are ignored on path searching.'
' The value must be positive integer or "0". "0" means unlimited.'
' Default: %(default)s',
required=False, default=DEFAULT_MAX_CALLBACK_CONSTRUCTION_ORDER_ON_PATH_SEARCHING,
)

def main(self, *, args):
try:
Lttng(args.trace_dir)
Architecture('lttng', args.trace_dir)
except Error as e:
if args.max_callback_construction_order_on_path_searching >= 0:
Lttng(args.trace_dir)
Architecture(
'lttng',
args.trace_dir,
args.max_callback_construction_order_on_path_searching
)
else:
raise ValueError(
'error: argument',
'-m/--max_callback_construction_order_on_path_searching',
'(%s)' % args.max_callback_construction_order_on_path_searching
)
except Exception as e:
logger.warning(e)
34 changes: 31 additions & 3 deletions ros2caret/verb/create_architecture.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

try:
import caret_analyze
from caret_analyze import DEFAULT_MAX_CALLBACK_CONSTRUCTION_ORDER_ON_PATH_SEARCHING
Architecture = caret_analyze.Architecture
Error = caret_analyze.exceptions.Error
CatchErrors = (OSError, Error)
Expand Down Expand Up @@ -66,23 +67,50 @@ def add_arguments(self, parser, cli_name):
help='allow overwrite of architecture file',
required=False, default=False
)
parser.add_argument(
'-m', '--max_callback_construction_order_on_path_searching',
type=int, dest='max_callback_construction_order_on_path_searching',
help='callbacks whose construction_order are greater than'
' this value are ignored on path searching.'
' The value must be positive integer or "0". "0" means unlimited.'
' Default: %(default)s',
required=False, default=DEFAULT_MAX_CALLBACK_CONSTRUCTION_ORDER_ON_PATH_SEARCHING,
)

def main(self, *, args):
create_arch = CreateArchitecture(args.trace_dir)
create_arch.create(args.output_path, args.force)
try:
create_arch = CreateArchitecture(
args.trace_dir,
args.max_callback_construction_order_on_path_searching
)
create_arch.create(args.output_path, args.force)
except Exception as e:
logger.warning(e)


class CreateArchitecture:

def __init__(
self,
trace_dir: str,
max_callback_construction_order_on_path_searching: int,
architecture: Optional[Architecture] = None
) -> None:
if architecture:
self._arch = architecture
else:
self._arch = Architecture('lttng', trace_dir)
if max_callback_construction_order_on_path_searching >= 0:
self._arch = Architecture(
'lttng',
trace_dir,
max_callback_construction_order_on_path_searching
)
else:
raise ValueError(
'error: argument',
'-m/--max_callback_construction_order_on_path_searching',
'(%s)' % max_callback_construction_order_on_path_searching
)

def create(self, output_path: str, force: bool) -> None:
try:
Expand Down
32 changes: 29 additions & 3 deletions ros2caret/verb/verify_paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

try:
import caret_analyze
from caret_analyze import DEFAULT_MAX_CALLBACK_CONSTRUCTION_ORDER_ON_PATH_SEARCHING
Architecture = caret_analyze.Architecture
except ModuleNotFoundError as e:
if 'GITHUB_ACTION' in os.environ:
Expand Down Expand Up @@ -55,23 +56,48 @@ def add_arguments(self, parser, cli_name):
help='path names to be verified.',
required=False,
)
parser.add_argument(
'-m', '--max_callback_construction_order_on_path_searching',
type=int, dest='max_callback_construction_order_on_path_searching',
help='callbacks whose construction_order are greater than'
' this value are ignored on path searching.'
' The value must be positive integer or "0". "0" means unlimited.'
' Default: %(default)s',
required=False, default=DEFAULT_MAX_CALLBACK_CONSTRUCTION_ORDER_ON_PATH_SEARCHING,
)

def main(self, *, args):
verify_paths = VerifyPaths(args.arch_path)
verify_paths.verify(args.verified_path_names)
try:
verify_paths = VerifyPaths(args.arch_path,
args.max_callback_construction_order_on_path_searching)
verify_paths.verify(args.verified_path_names)
except Exception as e:
logger.info(e)


class VerifyPaths:

def __init__(
self,
arch_path: str,
max_callback_construction_order_on_path_searching: int,
architecture: Optional[Architecture] = None
) -> None:
if architecture:
self._arch = architecture
else:
self._arch = Architecture('yaml', arch_path)
if max_callback_construction_order_on_path_searching >= 0:
self._arch = Architecture(
'yaml',
arch_path,
max_callback_construction_order_on_path_searching
)
else:
raise ValueError(
'error: argument',
'-m/--max_callback_construction_order_on_path_searching',
'(%s)' % max_callback_construction_order_on_path_searching
)

def verify(
self,
Expand Down
16 changes: 14 additions & 2 deletions test/verb/test_create_architecture.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@

from logging import ERROR, INFO

try:
import os
from caret_analyze import DEFAULT_MAX_CALLBACK_CONSTRUCTION_ORDER_ON_PATH_SEARCHING
except ModuleNotFoundError as e:
if 'GITHUB_ACTION' in os.environ:
DEFAULT_MAX_CALLBACK_CONSTRUCTION_ORDER_ON_PATH_SEARCHING = 10
else:
raise e
from ros2caret.verb.create_architecture import CreateArchitecture


Expand All @@ -22,7 +30,9 @@ class TestCreateArchitecture:
def test_create_success_case(self, caplog, mocker):
architecture_mock = mocker.Mock()
mocker.patch.object(architecture_mock, 'export', return_value=None)
create_arch = CreateArchitecture('', architecture_mock)
create_arch = CreateArchitecture('',
DEFAULT_MAX_CALLBACK_CONSTRUCTION_ORDER_ON_PATH_SEARCHING,
architecture_mock)

create_arch.create('output_path', True)
assert len(caplog.records) == 1
Expand All @@ -34,7 +44,9 @@ def test_create_fail_case(self, caplog, mocker):
mocker.patch.object(architecture_mock,
'export',
side_effect=OSError(''))
create_arch = CreateArchitecture('', architecture_mock)
create_arch = CreateArchitecture('',
DEFAULT_MAX_CALLBACK_CONSTRUCTION_ORDER_ON_PATH_SEARCHING,
architecture_mock)

create_arch.create('output_path', True)
assert len(caplog.records) == 1
Expand Down
17 changes: 15 additions & 2 deletions test/verb/test_verify_paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@

from logging import INFO

try:
import os
from caret_analyze import DEFAULT_MAX_CALLBACK_CONSTRUCTION_ORDER_ON_PATH_SEARCHING
except ModuleNotFoundError as e:
if 'GITHUB_ACTION' in os.environ:
DEFAULT_MAX_CALLBACK_CONSTRUCTION_ORDER_ON_PATH_SEARCHING = 10
else:
raise e

from ros2caret.verb.verify_paths import VerifyPaths


Expand All @@ -27,7 +36,9 @@ def test_verify_ok_case(self, caplog, mocker):
'get_path',
return_value=path_mock)

verify_paths = VerifyPaths('', architecture_mock)
verify_paths = VerifyPaths('',
DEFAULT_MAX_CALLBACK_CONSTRUCTION_ORDER_ON_PATH_SEARCHING,
architecture_mock)
verify_paths.verify(['verified_path_name'])
assert len(caplog.records) == 1
record = caplog.records[0]
Expand All @@ -41,6 +52,8 @@ def test_verify_ng_case(self, caplog, mocker):
'get_path',
return_value=path_mock)

verify_paths = VerifyPaths('', architecture_mock)
verify_paths = VerifyPaths('',
DEFAULT_MAX_CALLBACK_CONSTRUCTION_ORDER_ON_PATH_SEARCHING,
architecture_mock)
verify_paths.verify(['verified_path_name'])
assert len(caplog.records) == 0

0 comments on commit c84d4dd

Please sign in to comment.