Skip to content

Commit

Permalink
tests: Extend test_extension_command_duplicate
Browse files Browse the repository at this point in the history
This test is meant to cover the handling of duplicate command names,
including the warnings to be emitted. Previously, it only tested the
case where two extension commands had the same name. The other case is
duplicating a built-in command name, which prompts a different warning
message, so update the test to include it.

Additionally, ensure that each duplicate command in the test comes from
a different project, so that each warning message is expected to contain
a different project name. This serves to verify the bug fix from commit
edd1cee.

Signed-off-by: Grzegorz Swiderski <[email protected]>
  • Loading branch information
57300 committed Jan 21, 2025
1 parent 950fc32 commit 497bf3f
Showing 1 changed file with 29 additions and 7 deletions.
36 changes: 29 additions & 7 deletions tests/test_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -1941,8 +1941,10 @@ def do_run(self, args, ignored):


def test_extension_command_duplicate(repos_tmpdir):
# Test to ensure that in case to subprojects introduces same command, it
# will print a warning.
# West should disregard an extension command if its name is already taken,
# either by a built-in command or another extension command added earlier.
# A warning should also appear for each such case.

rr = repos_tmpdir.join('repos')
remote_kconfiglib = str(rr.join('Kconfiglib'))
remote_zephyr = str(rr.join('zephyr'))
Expand Down Expand Up @@ -1972,17 +1974,32 @@ def test_extension_command_duplicate(repos_tmpdir):
path: zephyr
''')})

# Initialize the net-tools repository.
# Add extension commands to the Kconfiglib remote.
add_commit(remote_kconfiglib, 'add west commands',
files={'scripts/west-commands.yml': textwrap.dedent('''\
west-commands:
- file: scripts/test.py
commands:
- name: list
class: List
- name: test-extension
class: Test
'''),
'scripts/test.py': textwrap.dedent('''\
from argparse import REMAINDER
from west.commands import WestCommand
class List(WestCommand):
def __init__(self):
super(List, self).__init__(
'list',
'test list',
'')
def do_add_parser(self, parser_adder):
parser = parser_adder.add_parser(self.name)
parser.add_argument('any', nargs=REMAINDER)
return parser
def do_run(self, args, ignored):
print('This must never be printed')
class Test(WestCommand):
def __init__(self):
super(Test, self).__init__(
Expand All @@ -2002,13 +2019,18 @@ def do_run(self, args, ignored):
west_tmpdir.chdir()
cmd('update')

actual = cmd('test-extension', stderr=subprocess.STDOUT).splitlines()
expected = [
expected_warns = [
'WARNING: ignoring project Kconfiglib extension command "list"; this is a built in command', # noqa: E501
'WARNING: ignoring project net-tools extension command "test-extension"; command "test-extension" is already defined as extension command', # noqa: E501
'Testing kconfig test command',
]

assert actual == expected
# Expect output from the built-in command, not its Kconfiglib duplicate.
actual = cmd('list zephyr -f {name}', stderr=subprocess.STDOUT).splitlines()
assert actual == expected_warns + ['manifest']

# Expect output from the Kconfiglib command, not its net-tools duplicate.
actual = cmd('test-extension', stderr=subprocess.STDOUT).splitlines()
assert actual == expected_warns + ['Testing kconfig test command']

def test_topdir_none(tmpdir):
# Running west topdir outside of any workspace ought to fail.
Expand Down

0 comments on commit 497bf3f

Please sign in to comment.