Skip to content

Commit

Permalink
Merge pull request #257 from andlaus/non_strict_mode
Browse files Browse the repository at this point in the history
CLI: introduce a non-strict mode to all tools
  • Loading branch information
andlaus authored Jan 30, 2024
2 parents 64bf799 + 09af3f9 commit 6a52b40
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
18 changes: 17 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,10 @@ def start_cli() -> None:

for tool in tool_modules:
if tool._odxtools_tool_name_ == args.subparser_name:
tool.run(args)
orig_strict = odxtools.exceptions.strict_mode
odxtools.exceptions.strict_mode = not args.no_strict
try:
tool.run(args)
finally:
odxtools.exceptions.strict_mode = orig_strict
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 6a52b40

Please sign in to comment.