Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
python-cliff
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
OpenStack
python
python-cliff
Commits
b1717618
Commit
b1717618
authored
3 years ago
by
Zuul
Committed by
Gerrit Code Review
3 years ago
Browse files
Options
Downloads
Plain Diff
Merge "Add conflict_handler parameter as attribut in Command class"
parents
392f3b2e
452fff3a
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
cliff/command.py
+2
-1
2 additions, 1 deletion
cliff/command.py
cliff/tests/test_command.py
+46
-0
46 additions, 0 deletions
cliff/tests/test_command.py
with
48 additions
and
1 deletion
cliff/command.py
+
2
−
1
View file @
b1717618
...
...
@@ -74,6 +74,7 @@ class Command(object, metaclass=abc.ABCMeta):
"""
deprecated
=
False
conflict_handler
=
'
ignore
'
_description
=
''
_epilog
=
None
...
...
@@ -156,7 +157,7 @@ class Command(object, metaclass=abc.ABCMeta):
epilog
=
self
.
get_epilog
(),
prog
=
prog_name
,
formatter_class
=
_argparse
.
SmartHelpFormatter
,
conflict_handler
=
'
ignore
'
,
conflict_handler
=
self
.
conflict_handler
,
)
for
hook
in
self
.
_hooks
:
hook
.
obj
.
get_parser
(
parser
)
...
...
This diff is collapsed.
Click to expand it.
cliff/tests/test_command.py
+
46
−
0
View file @
b1717618
...
...
@@ -172,3 +172,49 @@ class TestArgumentParser(base.TestBase):
args
=
parser
.
parse_args
([
'
-z
'
,
'
foo
'
,
'
a
'
,
'
b
'
])
self
.
assertEqual
(
args
.
zippy
,
'
foo
'
)
self
.
assertEqual
(
args
.
zero
,
'
zero-default
'
)
def
test_with_conflict_handler
(
self
):
cmd
=
TestCommand
(
None
,
None
)
cmd
.
conflict_handler
=
'
resolve
'
parser
=
cmd
.
get_parser
(
'
NAME
'
)
self
.
assertEqual
(
parser
.
conflict_handler
,
'
resolve
'
)
def
test_raise_conflict_argument_error
(
self
):
cmd
=
TestCommand
(
None
,
None
)
parser
=
cmd
.
get_parser
(
'
NAME
'
)
parser
.
add_argument
(
'
-f
'
,
'
--foo
'
,
dest
=
'
foo
'
,
default
=
'
foo
'
,
)
self
.
assertRaises
(
argparse
.
ArgumentError
,
parser
.
add_argument
,
'
-f
'
,
)
def
test_resolve_conflict_argument
(
self
):
cmd
=
TestCommand
(
None
,
None
)
cmd
.
conflict_handler
=
'
resolve
'
parser
=
cmd
.
get_parser
(
'
NAME
'
)
parser
.
add_argument
(
'
-f
'
,
'
--foo
'
,
dest
=
'
foo
'
,
default
=
'
foo
'
,
)
parser
.
add_argument
(
'
-f
'
,
'
--foo
'
,
dest
=
'
foo
'
,
default
=
'
bar
'
,
)
args
=
parser
.
parse_args
([
'
a
'
,
'
b
'
])
self
.
assertEqual
(
args
.
foo
,
'
bar
'
)
def
test_wrong_conflict_handler
(
self
):
cmd
=
TestCommand
(
None
,
None
)
cmd
.
conflict_handler
=
'
wrong
'
self
.
assertRaises
(
ValueError
,
cmd
.
get_parser
,
'
NAME
'
,
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment