Skip to content

Commit

Permalink
CLI: introduce a non-strict mode to all tools
Browse files Browse the repository at this point in the history
using the non-strict mode is more robust regarding incorrect input
files, bugs and unimplemented features in odxtools, but it might cause
undefined behaviour.

Signed-off-by: Andreas Lauser <[email protected]>
Signed-off-by: Katja Köhler <[email protected]>
  • Loading branch information
andlaus committed Jan 29, 2024
1 parent 5b45927 commit 763d003
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
2 changes: 1 addition & 1 deletion odxtools/cli/browse.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import logging
import sys
from typing import List, Optional, Union
from tabulate import tabulate # TODO: switch to rich tables

import PyInquirer.prompt as PI_prompt
from tabulate import tabulate # TODO: switch to rich tables

from ..database import Database
from ..dataobjectproperty import DataObjectProperty
Expand Down
19 changes: 18 additions & 1 deletion odxtools/cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import importlib
from typing import Any, List

import odxtools

from ..version import __version__ as odxtools_version
from .dummy_sub_parser import DummyTool

Expand Down Expand Up @@ -31,6 +33,14 @@ def start_cli() -> None:
formatter_class=argparse.RawTextHelpFormatter,
)

argparser.add_argument(
"--no-strict",
action="store_true",
default=False,
required=False,
help="Load the dataset in non-strict mode (which is more robust but might lead to undefined behavior)",
)

argparser.add_argument(
"--version", required=False, action="store_true", help="Print the odxtools version")

Expand All @@ -50,4 +60,11 @@ def start_cli() -> None:

for tool in tool_modules:
if tool._odxtools_tool_name_ == args.subparser_name:
tool.run(args)
odxtools.exceptions.strict_mode = not args.no_strict
try:
tool.run(args)
except:
raise
finally:
odxtools.exceptions.strict_mode = False
return
12 changes: 9 additions & 3 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class UtilFunctions:

@staticmethod
def run_list_tool(path_to_pdx_file: str = "./examples/somersault.pdx",
no_strict: bool = False,
ecu_variants: Optional[List[str]] = None,
print_neg_responses: bool = False,
ecu_services: Optional[List[str]] = None,
Expand All @@ -30,6 +31,7 @@ def run_list_tool(path_to_pdx_file: str = "./examples/somersault.pdx",
dump_database: bool = False) -> None:
list_args = Namespace(
pdx_file=path_to_pdx_file,
no_strict=no_strict,
variants=ecu_variants,
global_negative_responses=print_neg_responses,
services=ecu_services,
Expand Down Expand Up @@ -71,12 +73,14 @@ def run_find_tool(service_names: List[str],

@staticmethod
def run_compare_tool(path_to_pdx_file: str = "./examples/somersault.pdx",
no_strict: bool = False,
ecu_variants: Optional[List[str]] = None,
database: Optional[List[str]] = None,
no_details: bool = True) -> None:

compare_args = Namespace(
pdx_file=path_to_pdx_file,
no_strict=no_strict,
variants=ecu_variants,
database=database,
no_details=no_details)
Expand All @@ -89,6 +93,7 @@ class TestCommandLineTools(unittest.TestCase):
def test_list_tool(self) -> None:

UtilFunctions.run_list_tool()
UtilFunctions.run_list_tool(no_strict=True)
UtilFunctions.run_list_tool(ecu_variants=["somersault"])
UtilFunctions.run_list_tool(print_neg_responses=True)
UtilFunctions.run_list_tool(print_params=True)
Expand All @@ -114,11 +119,12 @@ def test_find_tool(self) -> None:
def test_compare_tool(self) -> None:

UtilFunctions.run_compare_tool()
UtilFunctions.run_compare_tool(database=[r"./examples/somersault_modified.pdx"])
UtilFunctions.run_compare_tool(database=["./examples/somersault_modified.pdx"])
UtilFunctions.run_compare_tool(no_strict=True)
UtilFunctions.run_compare_tool(
database=[r"./examples/somersault_modified.pdx"], no_details=False)
database=["./examples/somersault_modified.pdx"], no_details=False)
UtilFunctions.run_compare_tool(
database=[r"./examples/somersault_modified.pdx"], ecu_variants=["somersault_lazy"])
database=["./examples/somersault_modified.pdx"], ecu_variants=["somersault_lazy"])
UtilFunctions.run_compare_tool(ecu_variants=[
"somersault_lazy", "somersault_assiduous", "somersault_young", "somersault_old"
])
Expand Down

0 comments on commit 763d003

Please sign in to comment.