Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openeuler
avocado
提交
44a6efeb
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,发现更多精彩内容 >>
未验证
提交
44a6efeb
编写于
1月 04, 2017
作者:
A
Amador Pahim
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'ldoktor-testtmpdir'
上级
6eccf580
2e164bc4
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
40 addition
and
10 deletion
+40
-10
avocado/core/test.py
avocado/core/test.py
+6
-1
avocado/plugins/teststmpdir.py
avocado/plugins/teststmpdir.py
+2
-1
selftests/functional/test_teststmpdir.py
selftests/functional/test_teststmpdir.py
+32
-8
未找到文件。
avocado/core/test.py
浏览文件 @
44a6efeb
...
@@ -47,6 +47,11 @@ else:
...
@@ -47,6 +47,11 @@ else:
import
unittest
import
unittest
#: Environment variable used to store the location of a tmpfile which is
#: preserved across all tests execution (usually in one job)
COMMON_TMPDIR_NAME
=
'AVOCADO_TESTS_COMMON_TMPDIR'
class
NameNotTestNameError
(
Exception
):
class
NameNotTestNameError
(
Exception
):
"""
"""
...
@@ -286,7 +291,7 @@ class Test(unittest.TestCase):
...
@@ -286,7 +291,7 @@ class Test(unittest.TestCase):
Returns the path of the temporary directory that will stay the
Returns the path of the temporary directory that will stay the
same for all tests in a given Job.
same for all tests in a given Job.
"""
"""
env_var
=
'AVOCADO_TESTS_COMMON_TMPDIR'
env_var
=
COMMON_TMPDIR_NAME
path
=
os
.
environ
.
get
(
env_var
)
path
=
os
.
environ
.
get
(
env_var
)
if
path
is
None
:
if
path
is
None
:
msg
=
'Environment Variable %s is not set.'
%
env_var
msg
=
'Environment Variable %s is not set.'
%
env_var
...
...
avocado/plugins/teststmpdir.py
浏览文件 @
44a6efeb
...
@@ -20,6 +20,7 @@ import shutil
...
@@ -20,6 +20,7 @@ import shutil
import
tempfile
import
tempfile
from
avocado.core.plugin_interfaces
import
JobPre
,
JobPost
from
avocado.core.plugin_interfaces
import
JobPre
,
JobPost
from
avocado.core
import
test
class
TestsTmpDir
(
JobPre
,
JobPost
):
class
TestsTmpDir
(
JobPre
,
JobPost
):
...
@@ -28,7 +29,7 @@ class TestsTmpDir(JobPre, JobPost):
...
@@ -28,7 +29,7 @@ class TestsTmpDir(JobPre, JobPost):
description
=
'Creates a temporary directory for tests consumption'
description
=
'Creates a temporary directory for tests consumption'
def
__init__
(
self
):
def
__init__
(
self
):
self
.
_varname
=
'AVOCADO_TESTS_COMMON_TMPDIR'
self
.
_varname
=
test
.
COMMON_TMPDIR_NAME
self
.
_dirname
=
None
self
.
_dirname
=
None
def
pre
(
self
,
job
):
def
pre
(
self
,
job
):
...
...
selftests/functional/test_teststmpdir.py
浏览文件 @
44a6efeb
...
@@ -11,6 +11,7 @@ else:
...
@@ -11,6 +11,7 @@ else:
import
unittest
import
unittest
from
avocado.core
import
exit_codes
from
avocado.core
import
exit_codes
from
avocado.core
import
test
from
avocado.utils
import
process
from
avocado.utils
import
process
from
avocado.utils
import
script
from
avocado.utils
import
script
...
@@ -23,23 +24,21 @@ import tempfile
...
@@ -23,23 +24,21 @@ import tempfile
from avocado import Test
from avocado import Test
class MyTest(Test):
class MyTest(Test):
def test1(self):
def test1(self):
file = os.path.join(self.teststmpdir,
tempfile.mkstemp(dir=self.teststmpdir)
next(tempfile._get_candidate_names()))
open(file, "w+").close()
if len(os.listdir(self.teststmpdir)) != 2:
if len(os.listdir(self.teststmpdir)) != 2:
self.fail()
self.fail()
"""
"""
SIMPLE_SCRIPT
=
"""#!/bin/bash
SIMPLE_SCRIPT
=
"""#!/bin/bash
mktemp ${
AVOCADO_TESTS_COMMON_TMPDIR
}/XXXXXX
mktemp ${
{{0}}
}/XXXXXX
if [ $(ls ${
AVOCADO_TESTS_COMMON_TMPDIR
} | wc -l) == 1 ]
if [ $(ls ${
{{0}}
} | wc -l) == 1 ]
then
then
exit 0
exit 0
else
else
exit 1
exit 1
fi
fi
"""
"""
.
format
(
test
.
COMMON_TMPDIR_NAME
)
class
TestsTmpDirTests
(
unittest
.
TestCase
):
class
TestsTmpDirTests
(
unittest
.
TestCase
):
...
@@ -55,20 +54,45 @@ class TestsTmpDirTests(unittest.TestCase):
...
@@ -55,20 +54,45 @@ class TestsTmpDirTests(unittest.TestCase):
INSTRUMENTED_SCRIPT
)
INSTRUMENTED_SCRIPT
)
self
.
instrumented_test
.
save
()
self
.
instrumented_test
.
save
()
def
run_and_check
(
self
,
cmd_line
,
expected_rc
):
def
run_and_check
(
self
,
cmd_line
,
expected_rc
,
env
=
None
):
os
.
chdir
(
basedir
)
os
.
chdir
(
basedir
)
result
=
process
.
run
(
cmd_line
,
ignore_status
=
True
)
result
=
process
.
run
(
cmd_line
,
ignore_status
=
True
,
env
=
env
)
self
.
assertEqual
(
result
.
exit_status
,
expected_rc
,
self
.
assertEqual
(
result
.
exit_status
,
expected_rc
,
"Command %s did not return rc "
"Command %s did not return rc "
"%d:
\n
%s"
%
(
cmd_line
,
expected_rc
,
result
))
"%d:
\n
%s"
%
(
cmd_line
,
expected_rc
,
result
))
return
result
return
result
@
unittest
.
skipIf
(
test
.
COMMON_TMPDIR_NAME
in
os
.
environ
,
"%s already set in os.environ"
%
test
.
COMMON_TMPDIR_NAME
)
def
test_tests_tmp_dir
(
self
):
def
test_tests_tmp_dir
(
self
):
"""
Tests whether automatically created teststmpdir is shared across
all tests.
"""
cmd_line
=
(
"./scripts/avocado run --sysinfo=off "
cmd_line
=
(
"./scripts/avocado run --sysinfo=off "
"--job-results-dir %s %s %s"
%
"--job-results-dir %s %s %s"
%
(
self
.
tmpdir
,
self
.
simple_test
,
self
.
instrumented_test
))
(
self
.
tmpdir
,
self
.
simple_test
,
self
.
instrumented_test
))
self
.
run_and_check
(
cmd_line
,
exit_codes
.
AVOCADO_ALL_OK
)
self
.
run_and_check
(
cmd_line
,
exit_codes
.
AVOCADO_ALL_OK
)
def
test_manualy_created
(
self
):
"""
Tests whether manually set teststmpdir is used and not deleted by
avocado
"""
shared_tmp
=
tempfile
.
mkdtemp
(
dir
=
self
.
tmpdir
)
cmd
=
(
"./scripts/avocado run --sysinfo=off "
"--job-results-dir %s %%s"
%
self
.
tmpdir
)
self
.
run_and_check
(
cmd
%
self
.
simple_test
,
exit_codes
.
AVOCADO_ALL_OK
,
{
test
.
COMMON_TMPDIR_NAME
:
shared_tmp
})
self
.
run_and_check
(
cmd
%
self
.
instrumented_test
,
exit_codes
.
AVOCADO_ALL_OK
,
{
test
.
COMMON_TMPDIR_NAME
:
shared_tmp
})
content
=
os
.
listdir
(
shared_tmp
)
self
.
assertEqual
(
len
(
content
),
2
,
"The number of tests in manually "
"set teststmpdir is not 2 (%s):
\n
%s"
%
(
len
(
content
),
content
))
def
tearDown
(
self
):
def
tearDown
(
self
):
shutil
.
rmtree
(
self
.
tmpdir
)
shutil
.
rmtree
(
self
.
tmpdir
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录