Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: Extend test_extension_command_duplicate #780

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 32 additions & 8 deletions tests/test_project.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2020, Nordic Semiconductor ASA

Check notice on line 1 in tests/test_project.py

View workflow job for this annotation

GitHub Actions / Check file tests/test_project.py

Unformatted file

Consider running 'ruff format tests/test_project.py' See https://github.com/zephyrproject-rtos/west/actions/runs/13072843278 for more details

import collections
import os
Expand Down Expand Up @@ -1941,8 +1941,10 @@


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.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pydoc syntax instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean: move this comment above the function, or make it a docstring?
So far, I just kept it consistent with other comments in this particular file.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant pydoc. It's placed exactly like a pydoc but just missing the syntax.

I didn't see that all other tests are like this, sorry. I can't see a good reason why. I think starting to use the pydoc syntax would look consistent enough while making progress at the same time.

pydocs are automatically extracted by very many tools including python itself.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't see a good reason why.

I tried to write pydoc for APIs and comments for things that weren't API, as a pattern.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @mbolivar , now I see https://docs.zephyrproject.org/latest/develop/west/west-apis.html is extracted from the source. Is that automated somewhere or manual?

I tried to write pydoc for APIs and comments for things that weren't API, as a pattern.

Makes sense but the tests/ are located in an entirely different, top-level directory so they should not interfere.

Either way this should really be written down somewhere.

Apologies @57300 for the off-topic discussion, feel free to ignore.


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 @@
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,20 @@
west_tmpdir.chdir()
cmd('update')

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