Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openeuler
avocado
提交
b9b0be86
A
avocado
项目概览
openeuler
/
avocado
通知
0
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
A
avocado
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
b9b0be86
编写于
1月 27, 2016
作者:
C
Cleber Rosa
浏览文件
操作
浏览文件
下载
差异文件
Merge remote-tracking branch 'apahim/fix_subcommand_usage'
上级
4ae3bab5
6cd03d6f
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
42 addition
and
18 deletion
+42
-18
avocado/core/parser.py
avocado/core/parser.py
+28
-8
selftests/functional/test_argument_parsing.py
selftests/functional/test_argument_parsing.py
+11
-7
selftests/functional/test_basic.py
selftests/functional/test_basic.py
+1
-1
selftests/functional/test_replay.py
selftests/functional/test_replay.py
+2
-2
未找到文件。
avocado/core/parser.py
浏览文件 @
b9b0be86
...
...
@@ -18,7 +18,9 @@ Avocado application command line parsing.
"""
import
argparse
import
sys
from
.
import
exit_codes
from
.
import
tree
from
.
import
settings
from
.version
import
VERSION
...
...
@@ -27,6 +29,18 @@ PROG = 'avocado'
DESCRIPTION
=
'Avocado Test Runner'
class
ArgumentParser
(
argparse
.
ArgumentParser
):
"""
Class to override argparse functions
"""
def
error
(
self
,
message
):
msg
=
'%s: error: %s
\n
'
%
(
self
.
prog
,
message
)
self
.
print_help
(
sys
.
stderr
)
self
.
exit
(
exit_codes
.
AVOCADO_FAIL
,
msg
)
class
Parser
(
object
):
"""
...
...
@@ -36,10 +50,9 @@ class Parser(object):
def
__init__
(
self
):
self
.
args
=
None
self
.
subcommands
=
None
self
.
application
=
argparse
.
ArgumentParser
(
prog
=
PROG
,
add_help
=
False
,
# see parent parsing
description
=
DESCRIPTION
)
self
.
application
=
ArgumentParser
(
prog
=
PROG
,
add_help
=
False
,
# see parent parsing
description
=
DESCRIPTION
)
self
.
application
.
add_argument
(
'-v'
,
'--version'
,
action
=
'version'
,
version
=
'Avocado %s'
%
VERSION
)
self
.
application
.
add_argument
(
'--config'
,
metavar
=
'CONFIG_FILE'
,
...
...
@@ -59,9 +72,9 @@ class Parser(object):
settings
.
settings
.
process_config_path
(
self
.
args
.
config
)
# Use parent parsing to avoid breaking the output of --help option
self
.
application
=
argparse
.
ArgumentParser
(
prog
=
PROG
,
description
=
DESCRIPTION
,
parents
=
[
self
.
application
])
self
.
application
=
ArgumentParser
(
prog
=
PROG
,
description
=
DESCRIPTION
,
parents
=
[
self
.
application
])
# Subparsers where Avocado subcommands are plugged
self
.
subcommands
=
self
.
application
.
add_subparsers
(
...
...
@@ -80,4 +93,11 @@ class Parser(object):
Side effect: set the final value for attribute `args`.
"""
self
.
args
=
self
.
application
.
parse_args
(
namespace
=
self
.
args
)
self
.
args
,
extra
=
self
.
application
.
parse_known_args
(
namespace
=
self
.
args
)
if
extra
:
msg
=
'unrecognized arguments: %s'
%
' '
.
join
(
extra
)
for
sub
in
self
.
application
.
_subparsers
.
_actions
:
if
sub
.
dest
==
'subcommand'
:
sub
.
choices
[
self
.
args
.
subcommand
].
error
(
msg
)
self
.
application
.
error
(
msg
)
selftests/functional/test_argument_parsing.py
浏览文件 @
b9b0be86
...
...
@@ -23,7 +23,7 @@ class ArgumentParsingTest(unittest.TestCase):
os
.
chdir
(
basedir
)
cmd_line
=
'./scripts/avocado whacky-command-that-doesnt-exist'
result
=
process
.
run
(
cmd_line
,
ignore_status
=
True
)
expected_rc
=
exit_codes
.
AVOCADO_
JOB_
FAIL
expected_rc
=
exit_codes
.
AVOCADO_FAIL
self
.
assertEqual
(
result
.
exit_status
,
expected_rc
,
'Avocado did not return rc %d:
\n
%s'
%
(
expected_rc
,
result
))
...
...
@@ -31,7 +31,7 @@ class ArgumentParsingTest(unittest.TestCase):
os
.
chdir
(
basedir
)
cmd_line
=
'./scripts/avocado run --sysinfo=foo passtest'
result
=
process
.
run
(
cmd_line
,
ignore_status
=
True
)
expected_rc
=
exit_codes
.
AVOCADO_
JOB_
FAIL
expected_rc
=
exit_codes
.
AVOCADO_FAIL
self
.
assertEqual
(
result
.
exit_status
,
expected_rc
,
'Avocado did not return rc %d:
\n
%s'
%
(
expected_rc
,
result
))
...
...
@@ -39,14 +39,17 @@ class ArgumentParsingTest(unittest.TestCase):
os
.
chdir
(
basedir
)
cmd_line
=
'./scripts/avocado run --sysinfo=off --whacky-argument passtest'
result
=
process
.
run
(
cmd_line
,
ignore_status
=
True
)
expected_rc
=
exit_codes
.
AVOCADO_
JOB_
FAIL
expected_rc
=
exit_codes
.
AVOCADO_FAIL
self
.
assertEqual
(
result
.
exit_status
,
expected_rc
,
'Avocado did not return rc %d:
\n
%s'
%
(
expected_rc
,
result
))
subcommand_error_msg
=
'avocado run: error: unrecognized arguments: '
\
'--whacky-argument'
self
.
assertIn
(
subcommand_error_msg
,
result
.
stderr
)
class
ArgumentParsingErrorEarlyTest
(
unittest
.
TestCase
):
def
run_but_fail_before_create_job_dir
(
self
,
complement_args
):
def
run_but_fail_before_create_job_dir
(
self
,
complement_args
,
expected_rc
):
"""
Runs avocado but checks that it fails before creating the job dir
...
...
@@ -60,17 +63,18 @@ class ArgumentParsingErrorEarlyTest(unittest.TestCase):
cmd_line
=
'./scripts/avocado run --sysinfo=off --force-job-id=%s %s'
cmd_line
%=
(
job
,
complement_args
)
result
=
process
.
run
(
cmd_line
,
ignore_status
=
True
)
expected_rc
=
exit_codes
.
AVOCADO_JOB_FAIL
self
.
assertEqual
(
result
.
exit_status
,
expected_rc
,
'Avocado did not return rc %d:
\n
%s'
%
(
expected_rc
,
result
))
path_job_glob
=
os
.
path
.
join
(
log_dir
,
"job-*-%s"
%
job
[
0
:
7
])
self
.
assertEquals
(
glob
.
glob
(
path_job_glob
),
[])
def
test_whacky_option
(
self
):
self
.
run_but_fail_before_create_job_dir
(
'--whacky-option passtest'
)
self
.
run_but_fail_before_create_job_dir
(
'--whacky-option passtest'
,
exit_codes
.
AVOCADO_FAIL
)
def
test_empty_option
(
self
):
self
.
run_but_fail_before_create_job_dir
(
''
)
self
.
run_but_fail_before_create_job_dir
(
''
,
exit_codes
.
AVOCADO_JOB_FAIL
)
if
__name__
==
'__main__'
:
unittest
.
main
()
selftests/functional/test_basic.py
浏览文件 @
b9b0be86
...
...
@@ -191,7 +191,7 @@ class RunnerOperationTest(unittest.TestCase):
os
.
chdir
(
basedir
)
cmd_line
=
'./scripts/avocado'
result
=
process
.
run
(
cmd_line
,
ignore_status
=
True
)
expected_rc
=
exit_codes
.
AVOCADO_
JOB_
FAIL
expected_rc
=
exit_codes
.
AVOCADO_FAIL
expected_output
=
'error: too few arguments'
self
.
assertEqual
(
result
.
exit_status
,
expected_rc
)
self
.
assertIn
(
expected_output
,
result
.
stderr
)
...
...
selftests/functional/test_replay.py
浏览文件 @
b9b0be86
...
...
@@ -75,7 +75,7 @@ class ReplayTests(unittest.TestCase):
cmd_line
=
(
'./scripts/avocado run --replay %s --replay-ignore foo'
'--job-results-dir %s --replay-data-dir %s --sysinfo=off'
%
(
self
.
jobid
,
self
.
tmpdir
,
self
.
jobdir
))
expected_rc
=
exit_codes
.
AVOCADO_
JOB_
FAIL
expected_rc
=
exit_codes
.
AVOCADO_FAIL
result
=
self
.
run_and_check
(
cmd_line
,
expected_rc
)
msg
=
'Invalid --replay-ignore option. Valid options are '
\
'(more than one allowed): mux,config'
...
...
@@ -94,7 +94,7 @@ class ReplayTests(unittest.TestCase):
cmd_line
=
(
'./scripts/avocado run --replay %s --replay-test-status E '
'--job-results-dir %s --replay-data-dir %s --sysinfo=off'
%
(
self
.
jobid
,
self
.
tmpdir
,
self
.
jobdir
))
expected_rc
=
exit_codes
.
AVOCADO_
JOB_
FAIL
expected_rc
=
exit_codes
.
AVOCADO_FAIL
result
=
self
.
run_and_check
(
cmd_line
,
expected_rc
)
msg
=
'Invalid --replay-test-status option. Valid options are (more '
\
'than one allowed): SKIP,ERROR,FAIL,WARN,PASS,INTERRUPTED'
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录