-
Notifications
You must be signed in to change notification settings - Fork 126
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
pdgendt
merged 1 commit into
zephyrproject-rtos:main
from
57300:test-extension-command-duplicate
Jan 31, 2025
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 GitHub Actions / Check file tests/test_project.pyUnformatted file
|
||
|
||
import collections | ||
import os | ||
|
@@ -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. | ||
|
||
rr = repos_tmpdir.join('repos') | ||
remote_kconfiglib = str(rr.join('Kconfiglib')) | ||
remote_zephyr = str(rr.join('zephyr')) | ||
|
@@ -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__( | ||
|
@@ -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. | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pydoc syntax instead?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried to write pydoc for APIs and comments for things that weren't API, as a pattern.
There was a problem hiding this comment.
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?
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.