Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openeuler
avocado
提交
23a50ec9
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,发现更多精彩内容 >>
未验证
提交
23a50ec9
编写于
7月 13, 2018
作者:
C
Cleber Rosa
浏览文件
操作
浏览文件
下载
差异文件
Merge remote-tracking branch 'ldoktor/stdout_stderr_encoding'
Signed-off-by:
N
Cleber Rosa
<
crosa@redhat.com
>
上级
d4c4c69f
89c4a27c
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
28 addition
and
23 deletion
+28
-23
avocado/core/test.py
avocado/core/test.py
+4
-5
avocado/utils/script.py
avocado/utils/script.py
+6
-7
selftests/functional/test_output_check.py
selftests/functional/test_output_check.py
+18
-11
未找到文件。
avocado/core/test.py
浏览文件 @
23a50ec9
...
...
@@ -72,9 +72,6 @@ class RawFileHandler(logging.FileHandler):
logged stream but still respects the formatter.
"""
def
__init__
(
self
,
*
args
,
**
kwargs
):
logging
.
FileHandler
.
__init__
(
self
,
*
args
,
**
kwargs
)
def
emit
(
self
,
record
):
"""
Modifying the original emit() to avoid including a new line
...
...
@@ -86,7 +83,8 @@ class RawFileHandler(logging.FileHandler):
try
:
msg
=
self
.
format
(
record
)
stream
=
self
.
stream
stream
.
write
(
'%s'
%
msg
)
stream
.
write
(
astring
.
to_text
(
msg
,
self
.
encoding
,
'xmlcharrefreplace'
))
self
.
flush
()
except
Exception
:
self
.
handleError
(
record
)
...
...
@@ -639,7 +637,8 @@ class Test(unittest.TestCase, TestData):
def
_register_log_file_handler
(
self
,
logger
,
formatter
,
filename
,
log_level
=
logging
.
DEBUG
,
raw
=
False
):
if
raw
:
file_handler
=
RawFileHandler
(
filename
=
filename
)
file_handler
=
RawFileHandler
(
filename
=
filename
,
encoding
=
astring
.
ENCODING
)
else
:
file_handler
=
logging
.
FileHandler
(
filename
=
filename
)
file_handler
.
setLevel
(
log_level
)
...
...
avocado/utils/script.py
浏览文件 @
23a50ec9
...
...
@@ -39,7 +39,7 @@ class Script(object):
Class that represents a script.
"""
def
__init__
(
self
,
path
,
content
,
mode
=
DEFAULT_MODE
):
def
__init__
(
self
,
path
,
content
,
mode
=
DEFAULT_MODE
,
open_mode
=
'w'
):
"""
Creates an instance of :class:`Script`.
...
...
@@ -54,6 +54,7 @@ class Script(object):
self
.
content
=
content
self
.
mode
=
mode
self
.
stored
=
False
self
.
open_mode
=
open_mode
def
__repr__
(
self
):
return
'%s(path="%s", stored=%s)'
%
(
self
.
__class__
.
__name__
,
...
...
@@ -78,7 +79,7 @@ class Script(object):
"""
dirname
=
os
.
path
.
dirname
(
self
.
path
)
utils_path
.
init_dir
(
dirname
)
with
open
(
self
.
path
,
'w'
)
as
fd
:
with
open
(
self
.
path
,
self
.
open_mode
)
as
fd
:
fd
.
write
(
self
.
content
)
os
.
chmod
(
self
.
path
,
self
.
mode
)
self
.
stored
=
True
...
...
@@ -104,7 +105,7 @@ class TemporaryScript(Script):
Class that represents a temporary script.
"""
def
__init__
(
self
,
name
,
content
,
prefix
=
'avocado_script'
,
mode
=
DEFAULT_MODE
):
def
__init__
(
self
,
name
,
content
,
prefix
=
'avocado_script'
,
mode
=
DEFAULT_MODE
,
open_mode
=
'w'
):
"""
Creates an instance of :class:`TemporaryScript`.
...
...
@@ -120,10 +121,8 @@ class TemporaryScript(Script):
:param mode: set file mode, default to 0775.
"""
tmpdir
=
tempfile
.
mkdtemp
(
prefix
=
prefix
)
self
.
path
=
os
.
path
.
join
(
tmpdir
,
name
)
self
.
content
=
content
self
.
mode
=
mode
self
.
stored
=
False
super
(
TemporaryScript
,
self
).
__init__
(
os
.
path
.
join
(
tmpdir
,
name
),
content
,
mode
,
open_mode
)
def
__del__
(
self
):
self
.
remove
()
...
...
selftests/functional/test_output_check.py
浏览文件 @
23a50ec9
...
...
@@ -14,10 +14,12 @@ basedir = os.path.abspath(basedir)
AVOCADO
=
os
.
environ
.
get
(
"UNITTEST_AVOCADO_CMD"
,
"./scripts/avocado"
)
OUTPUT_SCRIPT_CONTENTS
=
"""#!/bin/sh
echo "Hello, avocado!"
echo "Hello, stderr!" >&2
"""
STDOUT
=
b
"Hello,
\xc4\x9b\xc5\xa1\xc4\x8d\xc5\x99\xc5\xbe\xc3\xbd\xc3\xa1\xc3\xad\xc3\xa9
!"
STDERR
=
b
"Hello, stderr!"
OUTPUT_SCRIPT_CONTENTS
=
b
"""#!/bin/sh
echo "%s"
echo "%s" >&2
"""
%
(
STDOUT
,
STDERR
)
class
RunnerSimpleTest
(
unittest
.
TestCase
):
...
...
@@ -27,7 +29,8 @@ class RunnerSimpleTest(unittest.TestCase):
self
.
output_script
=
script
.
TemporaryScript
(
'output_check.sh'
,
OUTPUT_SCRIPT_CONTENTS
,
'avocado_output_check_functional'
)
'avocado_output_check_functional'
,
open_mode
=
'wb'
)
self
.
output_script
.
save
()
def
_check_output_record_all
(
self
):
...
...
@@ -42,8 +45,10 @@ class RunnerSimpleTest(unittest.TestCase):
(
expected_rc
,
result
))
stdout_file
=
os
.
path
.
join
(
"%s.data/stdout.expected"
%
self
.
output_script
)
stderr_file
=
os
.
path
.
join
(
"%s.data/stderr.expected"
%
self
.
output_script
)
self
.
assertTrue
(
os
.
path
.
isfile
(
stdout_file
))
self
.
assertTrue
(
os
.
path
.
isfile
(
stderr_file
))
with
open
(
stdout_file
,
'rb'
)
as
fd_stdout
:
self
.
assertEqual
(
fd_stdout
.
read
(),
STDOUT
)
with
open
(
stderr_file
,
'rb'
)
as
fd_stderr
:
self
.
assertEqual
(
fd_stderr
.
read
(),
STDERR
)
def
_check_output_record_combined
(
self
):
os
.
chdir
(
basedir
)
...
...
@@ -56,7 +61,8 @@ class RunnerSimpleTest(unittest.TestCase):
"Avocado did not return rc %d:
\n
%s"
%
(
expected_rc
,
result
))
output_file
=
os
.
path
.
join
(
"%s.data/output.expected"
%
self
.
output_script
)
self
.
assertTrue
(
os
.
path
.
isfile
(
output_file
))
with
open
(
output_file
,
'rb'
)
as
fd_output
:
self
.
assertEqual
(
fd_output
.
read
(),
STDOUT
+
STDERR
)
def
test_output_record_none
(
self
):
os
.
chdir
(
basedir
)
...
...
@@ -85,7 +91,8 @@ class RunnerSimpleTest(unittest.TestCase):
(
expected_rc
,
result
))
stdout_file
=
os
.
path
.
join
(
"%s.data/stdout.expected"
%
self
.
output_script
)
stderr_file
=
os
.
path
.
join
(
"%s.data/stderr.expected"
%
self
.
output_script
)
self
.
assertTrue
(
os
.
path
.
isfile
(
stdout_file
))
with
open
(
stdout_file
,
'rb'
)
as
fd_stdout
:
self
.
assertEqual
(
fd_stdout
.
read
(),
STDOUT
)
self
.
assertFalse
(
os
.
path
.
isfile
(
stderr_file
))
def
test_output_record_and_check
(
self
):
...
...
@@ -170,7 +177,7 @@ class RunnerSimpleTest(unittest.TestCase):
stdout_diff_content
=
stdout_diff_obj
.
read
()
self
.
assertIn
(
b
'-I PITY THE FOOL THAT STANDS ON STDOUT!'
,
stdout_diff_content
)
self
.
assertIn
(
b
'+
Hello, avocado!'
,
stdout_diff_content
)
self
.
assertIn
(
b
'+
%s'
%
STDOUT
,
stdout_diff_content
)
with
open
(
stderr_diff
,
'rb'
)
as
stderr_diff_obj
:
stderr_diff_content
=
stderr_diff_obj
.
read
()
...
...
@@ -182,7 +189,7 @@ class RunnerSimpleTest(unittest.TestCase):
job_log_content
=
job_log_obj
.
read
()
self
.
assertIn
(
b
'Stdout Diff:'
,
job_log_content
)
self
.
assertIn
(
b
'-I PITY THE FOOL THAT STANDS ON STDOUT!'
,
job_log_content
)
self
.
assertIn
(
b
'+
Hello, avocado!'
,
job_log_content
)
self
.
assertIn
(
b
'+
%s'
%
STDOUT
,
job_log_content
)
self
.
assertIn
(
b
'Stdout Diff:'
,
job_log_content
)
self
.
assertIn
(
b
'-I PITY THE FOOL THAT STANDS ON STDERR!'
,
job_log_content
)
self
.
assertIn
(
b
'+Hello, stderr!'
,
job_log_content
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录