Skip to content

Commit

Permalink
Set indices to empty-dict if not given. Add test for arg indices. Fix…
Browse files Browse the repository at this point in the history
… typo in assertions filename.
  • Loading branch information
Corey committed Jul 2, 2023
1 parent 5213de7 commit 6784940
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 13 deletions.
4 changes: 4 additions & 0 deletions python/origen/origen/boot.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ def run_cmd(command,

if args is None:
args = {}
if arg_indices is None:
arg_indices = {}

if command == dispatch_plugin_cmd:
cmd_src = "plugin"
Expand Down Expand Up @@ -144,6 +146,8 @@ def call_user_cmd(cmd_type):
subcmds = []
if ext_args is None:
ext_args = {}
if ext_arg_indices is None:
ext_arg_indices = {}
if extensions is None:
extensions = []
current_ext = None
Expand Down
11 changes: 0 additions & 11 deletions test_apps/python_no_app/tests/cmd_exts/tests__extending_cmds.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,6 @@ class TestExtensionOpts(Common):
ext_mvd = ["mvd0", "mvd1"]
ext_rv = ["no_action"]

def get_action_results(self, output, actions):
retn = {}
for action in actions:
a = {}
r = output.split(f"Start Action Before CMD: {action}")[1].strip()
a["Before"], r = r.split(f"End Action Before CMD: {action}")
r = output.split(f"Start Action After CMD: {action}")[1].strip()
a["After"], r = r.split(f"End Action After CMD: {action}")
retn[action] = a
return retn

def test_help_msg(self):
help = self.cmd.get_help_msg()
help.assert_args(self.sa, self.ma)
Expand Down
38 changes: 38 additions & 0 deletions test_apps/python_no_app/tests/test_current_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,44 @@ def test_current_command_from_pl_cmd(self):
{}
)

def test_arg_indices(self):
cmd = CLIShared.python_plugin.plugin_test_args.extend(
CLIShared.exts.exts["plugin.python_plugin.plugin_test_args"]["exts"],
from_configs=CLIShared.exts.exts_workout_cfg
)

ext_flag = cmd.flag_extension
ext_ha = cmd.hidden_opt
ext_action = cmd.exts_workout_action

args = "show_arg_indices"
exts = "show_ext_arg_indices"
# Index 0 is the command name
# NOTE: per the clap API, when flags (options not accepting values) are used, only the last index is given
out = cmd.run(
"sv", "m0", "m1", "m2", # indices 1, 2-4
ext_flag.ln_to_cli(), # 5
cmd.opt_taking_value.ln_to_cli(), "opt_val", # 6 (opt name), 7 (value)
ext_flag.sn_to_cli(), # 8
ext_ha.ln_to_cli(), # 9
ext_action.ln_to_cli(), args, exts, # 10 (opt name), 11, 12 (values)
cmd.multi_val_delim_opt.ln_to_cli(), "d0,d1,d2"
)
parsed = self.get_action_results(out, [args, exts])
assert eval(parsed[args]["Before"]) == {
cmd.single_arg.name: [1],
cmd.multi_arg.name: [2, 3, 4],
cmd.opt_taking_value.name: [7]
}
assert eval(parsed[exts]["Before"]) == {
"aux.exts_workout": {
ext_flag.name: [8],
ext_ha.name: [9],
ext_action.name: [11, 12],
cmd.multi_val_delim_opt.name: [14, 15, 16],
}
}

@pytest.mark.skip
def test_current_command_from_aux_cmd(self):
# TEST_NEEDED Current Command core case
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from .cmd_models.plugins import Plugins
from .error_cases import ErrorCases

from .asertions import AssertionHelpers
from .assertions import AssertionHelpers

develop_origen = "develop_origen"
def develop_origen_cmd():
Expand Down Expand Up @@ -103,6 +103,10 @@ class CLIShared(cli.CLI, AssertionHelpers):
error_messages = ErrorCases()
na = "no_action"

def get_action_results(self, *args):
from .ext_helpers import get_action_results as get_action_results_wrap
return get_action_results_wrap(*args)

@pytest.fixture
def cmd(self):
return self._cmd
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,23 @@ def do_action(actions, phase):
# TEST_NEEDED CLI check for extension mods
for n, e in origen.current_command.exts.items():
print(f"{n}: {e.mod}")
elif action == "show_arg_indices":
print(origen.current_command.arg_indices)
elif action == "show_ext_arg_indices":
print({ n: v.arg_indices for n, v in origen.current_command.exts.items() })
elif action == "no_action":
pass
else:
raise RuntimeError(f"No action '{action}' is known!")
print(f"End Action {p_out} CMD: {action}")
print(f"End Action {p_out} CMD: {action}")

def get_action_results(output, actions):
retn = {}
for action in actions:
a = {}
r = output.split(f"Start Action Before CMD: {action}")[1].strip()
a["Before"], r = r.split(f"End Action Before CMD: {action}")
r = output.split(f"Start Action After CMD: {action}")[1].strip()
a["After"], r = r.split(f"End Action After CMD: {action}")
retn[action] = a
return retn

0 comments on commit 6784940

Please sign in to comment.