-
Notifications
You must be signed in to change notification settings - Fork 14
Fix mixin arg merge order for lists and scalars (fixes #40) #59
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
Open
PiousCrossten
wants to merge
4
commits into
colcon:master
Choose a base branch
from
PiousCrossten:fix/reverse-list-concatenation-issue-40
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
c401071
Apply mixins in reverse order to preserve command line order (#40)
PiousCrossten 5847f20
Apply suggestion from @knmcguire
PiousCrossten eafe9a2
Remove unnecessary comment in mixin_argument.py
PiousCrossten 6dbbae0
Update test_mixin_argument.py
PiousCrossten 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 hidden or 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
This file contains hidden or 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
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| # Copyright 2025 Open Source Robotics Foundation, Inc. | ||
|
PiousCrossten marked this conversation as resolved.
Outdated
|
||
| # Licensed under the Apache License, Version 2.0 | ||
|
|
||
| import argparse | ||
| from unittest.mock import patch | ||
|
|
||
| from colcon_mixin.mixin.mixin_argument import MixinArgumentDecorator | ||
| import pytest | ||
|
|
||
| MIXINS = { | ||
| 'a': {'cmake-args': ['FOO=A']}, | ||
| 'b': {'cmake-args': ['FOO=B']}, | ||
| 'c': {'cmake-args': ['FOO=C']}, | ||
| } | ||
|
|
||
|
|
||
| SCALAR_MIXINS = { | ||
| 'a': {'build-base': 'BASE_A'}, | ||
| 'b': {'build-base': 'BASE_B'}, | ||
| } | ||
|
|
||
|
|
||
| def _parse(argv, mixins=MIXINS): | ||
| base = argparse.ArgumentParser(prog='colcon') | ||
| decorator = MixinArgumentDecorator(base) | ||
| subparsers = decorator.add_subparsers(dest='verb') | ||
| build = subparsers.add_parser('build') | ||
| build.add_argument('--cmake-args', nargs='*', default=[]) | ||
| build.add_argument('--build-base', default='build') | ||
| mixins_by_verb = {('build',): mixins} | ||
| with patch( | ||
| 'colcon_mixin.mixin.mixin_argument.get_mixins', | ||
| return_value=mixins_by_verb, | ||
| ): | ||
| return decorator.parse_args(argv) | ||
|
|
||
|
|
||
| def test_multiple_mixins_preserve_command_line_order(): | ||
| # regression test for issue #40: the resulting list must follow the | ||
|
PiousCrossten marked this conversation as resolved.
Outdated
|
||
| # order the mixins were given on the command line | ||
| args = _parse(['build', '--mixin', 'a', 'b']) | ||
| assert args.cmake_args == ['FOO=A', 'FOO=B'] | ||
|
|
||
|
|
||
| def test_multiple_mixins_follow_reversed_selection(): | ||
| args = _parse(['build', '--mixin', 'b', 'a']) | ||
| assert args.cmake_args == ['FOO=B', 'FOO=A'] | ||
|
|
||
|
|
||
| def test_three_mixins_preserve_order(): | ||
| args = _parse(['build', '--mixin', 'a', 'b', 'c']) | ||
| assert args.cmake_args == ['FOO=A', 'FOO=B', 'FOO=C'] | ||
|
|
||
|
|
||
| def test_command_line_arguments_take_precedence(): | ||
| # explicit command line arguments must come last so they win | ||
| args = _parse(['build', '--mixin', 'a', 'b', '--cmake-args=FOO=CLI']) | ||
| assert args.cmake_args == ['FOO=A', 'FOO=B', 'FOO=CLI'] | ||
|
|
||
|
|
||
| def test_single_mixin(): | ||
| args = _parse(['build', '--mixin', 'a']) | ||
| assert args.cmake_args == ['FOO=A'] | ||
|
|
||
|
|
||
| def test_no_mixin(): | ||
| args = _parse(['build']) | ||
| assert args.cmake_args == [] | ||
|
|
||
|
|
||
| def test_scalar_last_listed_mixin_wins(): | ||
| # a scalar value from a later mixin must override an earlier one | ||
| args = _parse(['build', '--mixin', 'a', 'b'], SCALAR_MIXINS) | ||
| assert args.build_base == 'BASE_B' | ||
|
|
||
|
|
||
| def test_scalar_reversed_selection(): | ||
| args = _parse(['build', '--mixin', 'b', 'a'], SCALAR_MIXINS) | ||
| assert args.build_base == 'BASE_A' | ||
|
|
||
|
|
||
| def test_scalar_command_line_argument_take_precedence(): | ||
| args = _parse( | ||
| ['build', '--mixin', 'a', 'b', '--build-base', 'CLI'], SCALAR_MIXINS) | ||
| assert args.build_base == 'CLI' | ||
|
|
||
|
|
||
| def test_unavailable_mixin_reports_first(capsys): | ||
| with pytest.raises(SystemExit): | ||
| _parse(['build', '--mixin', 'bad', 'a']) | ||
| assert "Mixin 'bad' is not available" in capsys.readouterr().err | ||
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.
Uh oh!
There was an error while loading. Please reload this page.