Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openeuler
avocado
提交
479f99fb
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,发现更多精彩内容 >>
未验证
提交
479f99fb
编写于
3月 21, 2019
作者:
C
Cleber Rosa
浏览文件
操作
浏览文件
下载
差异文件
Merge remote-tracking branch 'clebergnu/python2_leftovers'
Signed-off-by:
N
Cleber Rosa
<
crosa@redhat.com
>
上级
453a613c
dfb6f577
变更
13
隐藏空白更改
内联
并排
Showing
13 changed file
with
30 addition
and
75 deletion
+30
-75
Makefile
Makefile
+1
-1
avocado/core/settings.py
avocado/core/settings.py
+6
-10
avocado/utils/astring.py
avocado/utils/astring.py
+1
-7
avocado/utils/process.py
avocado/utils/process.py
+2
-9
avocado/utils/software_manager.py
avocado/utils/software_manager.py
+2
-6
docs/Makefile
docs/Makefile
+4
-1
docs/source/Configuration.rst
docs/source/Configuration.rst
+1
-1
optional_plugins/varianter_cit/tests/test_functional.py
optional_plugins/varianter_cit/tests/test_functional.py
+2
-2
selftests/functional/test_basic.py
selftests/functional/test_basic.py
+5
-13
selftests/functional/test_loader.py
selftests/functional/test_loader.py
+0
-3
selftests/functional/test_standalone.py
selftests/functional/test_standalone.py
+2
-8
selftests/unit/test_astring.py
selftests/unit/test_astring.py
+1
-5
selftests/unit/test_utils_disk.py
selftests/unit/test_utils_disk.py
+3
-9
未找到文件。
Makefile
浏览文件 @
479f99fb
ifndef
PYTHON
PYTHON
=
$(
shell
which python3 2>/dev/null
||
which python
2 2>/dev/null
||
which python
2>/dev/null
)
PYTHON
=
$(
shell
which python3 2>/dev/null
||
which python 2>/dev/null
)
endif
VERSION
=
$(
shell
$(PYTHON)
setup.py
--version
2>/dev/null
)
PYTHON_DEVELOP_ARGS
=
$(
shell
if
(
$(PYTHON)
setup.py develop
--help
2>/dev/null |
grep
-q
'\-\-user'
)
;
then
echo
"--user"
;
else
echo
""
;
fi
)
...
...
avocado/core/settings.py
浏览文件 @
479f99fb
...
...
@@ -13,16 +13,12 @@
# Author: Travis Miller <raphtee@google.com>
"""
Reads the avocado settings from a .ini file (
from python ConfigP
arser).
Reads the avocado settings from a .ini file (
with Python's configp
arser).
"""
import
ast
import
os
import
glob
try
:
import
ConfigParser
except
ImportError
:
import
configparser
as
ConfigParser
import
configparser
from
pkg_resources
import
resource_filename
from
pkg_resources
import
resource_isdir
...
...
@@ -144,7 +140,7 @@ def convert_value_type(value, value_type):
class
Settings
(
object
):
"""
Simple wrapper around
ConfigP
arser, with a key type conversion available.
Simple wrapper around
configp
arser, with a key type conversion available.
"""
no_default
=
object
()
...
...
@@ -155,7 +151,7 @@ class Settings(object):
:param config_path: Path to a config file. Useful for unittesting.
"""
self
.
config
=
ConfigP
arser
.
ConfigParser
()
self
.
config
=
configp
arser
.
ConfigParser
()
self
.
config_paths
=
[]
self
.
all_config_paths
=
[]
_source_tree_root
=
os
.
path
.
dirname
(
os
.
path
.
dirname
(
os
.
path
.
dirname
(
...
...
@@ -295,9 +291,9 @@ class Settings(object):
"""
try
:
val
=
self
.
config
.
get
(
section
,
key
)
except
ConfigP
arser
.
NoSectionError
:
except
configp
arser
.
NoSectionError
:
return
self
.
_handle_no_section
(
section
,
default
)
except
ConfigP
arser
.
Error
:
except
configp
arser
.
Error
:
return
self
.
_handle_no_value
(
section
,
key
,
default
)
if
not
val
.
strip
()
and
not
allow_blank
:
...
...
avocado/utils/astring.py
浏览文件 @
479f99fb
...
...
@@ -28,7 +28,6 @@ And not notice until their code starts failing.
import
itertools
import
locale
import
re
import
sys
import
string
from
six
import
string_types
,
PY3
...
...
@@ -315,8 +314,6 @@ def is_text(data):
That is, if it can hold text that requires more than one byte for
each character.
"""
if
sys
.
version_info
[
0
]
<
3
:
return
isinstance
(
data
,
unicode
)
# pylint: disable=E0602
return
isinstance
(
data
,
str
)
...
...
@@ -341,8 +338,5 @@ def to_text(data, encoding=ENCODING, errors='strict'):
encoding
=
ENCODING
return
data
.
decode
(
encoding
,
errors
=
errors
)
elif
not
isinstance
(
data
,
string_types
):
if
sys
.
version_info
[
0
]
<
3
:
return
unicode
(
data
)
# pylint: disable=E0602
else
:
return
str
(
data
)
return
str
(
data
)
return
data
avocado/utils/process.py
浏览文件 @
479f99fb
...
...
@@ -28,7 +28,6 @@ import shutil
import
signal
import
stat
import
subprocess
import
sys
import
threading
import
time
...
...
@@ -312,14 +311,8 @@ def cmd_split(cmd):
:param cmd: text (a multi byte string) encoded as 'utf-8'
"""
if
sys
.
version_info
[
0
]
<
3
:
data
=
cmd
.
encode
(
'utf-8'
)
result
=
shlex
.
split
(
data
)
result
=
[
i
.
decode
(
'utf-8'
)
for
i
in
result
]
else
:
data
=
astring
.
to_text
(
cmd
,
'utf-8'
)
result
=
shlex
.
split
(
data
)
return
result
data
=
astring
.
to_text
(
cmd
,
'utf-8'
)
return
shlex
.
split
(
data
)
class
CmdResult
(
object
):
...
...
avocado/utils/software_manager.py
浏览文件 @
479f99fb
...
...
@@ -40,6 +40,7 @@ import shutil
import
logging
import
optparse
import
tempfile
import
configparser
try
:
import
yum
...
...
@@ -48,11 +49,6 @@ except ImportError:
else
:
HAS_YUM_MODULE
=
True
try
:
import
ConfigParser
except
ImportError
:
import
configparser
as
ConfigParser
from
.
import
process
from
.
import
data_factory
from
.
import
distro
...
...
@@ -403,7 +399,7 @@ class YumBackend(RpmBackend):
base_arguments
=
'-y'
self
.
base_command
=
executable
+
' '
+
base_arguments
self
.
repo_file_path
=
'/etc/yum.repos.d/avocado-managed.repo'
self
.
cfgparser
=
ConfigP
arser
.
ConfigParser
()
self
.
cfgparser
=
configp
arser
.
ConfigParser
()
self
.
cfgparser
.
read
(
self
.
repo_file_path
)
y_cmd
=
executable
+
' --version | head -1'
cmd_result
=
process
.
run
(
y_cmd
,
ignore_status
=
True
,
...
...
docs/Makefile
浏览文件 @
479f99fb
# Makefile for Sphinx documentation
#
ifndef
PYTHON
PYTHON
=
$(
shell
which python3 2>/dev/null
||
which python 2>/dev/null
)
endif
# You can set these variables from the command line.
SPHINXOPTS
=
SPHINXBUILD
=
sphinx-build
SPHINXBUILD
=
$(PYTHON)
-m
sphinx
PAPER
=
BUILDDIR
=
build
...
...
docs/source/Configuration.rst
浏览文件 @
479f99fb
...
...
@@ -8,7 +8,7 @@ and that's why a configuration system is in place to help with those cases
The Avocado config file format is based on the (informal)
`INI file 'specification' <http://en.wikipedia.org/wiki/INI_file>`__, that is implemented by
Python's :mod:`
ConfigP
arser`. The format is simple and straightforward, composed by `sections`,
Python's :mod:`
configp
arser`. The format is simple and straightforward, composed by `sections`,
that contain a number of `keys` and `values`. Take for example a basic Avocado config file:
.. code-block:: ini
...
...
optional_plugins/varianter_cit/tests/test_functional.py
浏览文件 @
479f99fb
...
...
@@ -3,12 +3,12 @@ import unittest
from
avocado.utils
import
process
from
selftests
import
AVOCADO
basedir
=
os
.
path
.
join
(
os
.
path
.
dirname
(
os
.
path
.
abspath
(
__file__
)),
'..'
,
'..'
,
'..'
)
basedir
=
os
.
path
.
abspath
(
basedir
)
AVOCADO
=
os
.
environ
.
get
(
"UNITTEST_AVOCADO_CMD"
,
"./scripts/avocado"
)
class
Variants
(
unittest
.
TestCase
):
...
...
selftests/functional/test_basic.py
浏览文件 @
479f99fb
...
...
@@ -156,13 +156,9 @@ class RunnerOperationTest(unittest.TestCase):
def
test_show_version
(
self
):
result
=
process
.
run
(
'%s -v'
%
AVOCADO
,
ignore_status
=
True
)
self
.
assertEqual
(
result
.
exit_status
,
0
)
if
sys
.
version_info
[
0
]
==
3
:
content
=
result
.
stdout_text
else
:
content
=
result
.
stderr_text
self
.
assertTrue
(
re
.
match
(
r
"^Avocado \d+\.\d+$"
,
content
),
self
.
assertTrue
(
re
.
match
(
r
"^Avocado \d+\.\d+$"
,
result
.
stdout_text
),
"Version string does not match 'Avocado
\\
d
\\
.
\\
d:'
\n
"
"%r"
%
(
conten
t
))
"%r"
%
(
result
.
stdout_tex
t
))
def
test_alternate_config_datadir
(
self
):
"""
...
...
@@ -438,11 +434,8 @@ class RunnerOperationTest(unittest.TestCase):
cmd_line
=
AVOCADO
result
=
process
.
run
(
cmd_line
,
ignore_status
=
True
)
self
.
assertEqual
(
result
.
exit_status
,
exit_codes
.
AVOCADO_FAIL
)
if
sys
.
version_info
[
0
]
==
3
:
exp
=
b
'avocado: error: the following arguments are required'
else
:
exp
=
b
'error: too few arguments'
self
.
assertIn
(
exp
,
result
.
stderr
)
self
.
assertIn
(
b
'avocado: error: the following arguments are required'
,
result
.
stderr
)
def
test_empty_test_list
(
self
):
cmd_line
=
'%s run --sysinfo=off --job-results-dir %s'
%
(
AVOCADO
,
...
...
@@ -1120,8 +1113,7 @@ class PluginsTest(AbsPluginsTest, unittest.TestCase):
self
.
assertEqual
(
result
.
exit_status
,
expected_rc
,
"Avocado did not return rc %d:
\n
%s"
%
(
expected_rc
,
result
))
if
sys
.
version_info
[:
2
]
>=
(
2
,
7
,
0
):
self
.
assertNotIn
(
b
'Disabled'
,
result
.
stdout
)
self
.
assertNotIn
(
b
'Disabled'
,
result
.
stdout
)
def
test_config_plugin
(
self
):
cmd_line
=
'%s config --paginator off'
%
AVOCADO
...
...
selftests/functional/test_loader.py
浏览文件 @
479f99fb
...
...
@@ -6,7 +6,6 @@ import stat
import
tempfile
import
shutil
import
signal
import
sys
import
unittest
from
avocado.core
import
exit_codes
...
...
@@ -265,8 +264,6 @@ class LoaderTestFunctional(unittest.TestCase):
%
(
AVOCADO
,
self
.
tmpdir
,
mytest
))
self
.
_run_with_timeout
(
cmd_line
,
5
)
@
unittest
.
skipIf
(
sys
.
version_info
[
0
]
==
3
,
"Test currently broken on Python 3"
)
@
unittest
.
skipUnless
(
os
.
path
.
exists
(
"/bin/true"
),
"/bin/true not "
"available"
)
@
unittest
.
skipUnless
(
os
.
path
.
exists
(
"/bin/echo"
),
"/bin/echo not "
...
...
selftests/functional/test_standalone.py
浏览文件 @
479f99fb
...
...
@@ -48,10 +48,7 @@ class StandaloneTests(unittest.TestCase):
cmd_line
=
'%s ./examples/tests/errortest_nasty.py -r'
%
PY_CMD
expected_rc
=
exit_codes
.
AVOCADO_TESTS_FAIL
result
=
self
.
run_and_check
(
cmd_line
,
expected_rc
,
'errortest_nasty'
)
if
sys
.
version_info
[
0
]
==
3
:
exc
=
u
"errortest_nasty.NastyException: Nasty-string-like-exception
\u017e
"
else
:
exc
=
u
"NastyException: Nasty-string-like-exception
\\
u017e"
exc
=
u
"errortest_nasty.NastyException: Nasty-string-like-exception
\u017e
"
count
=
result
.
stdout_text
.
count
(
u
"
\n
%s"
%
exc
)
self
.
assertEqual
(
count
,
2
,
"Exception
\\
n%s should be present twice in"
"the log (once from the log, second time when parsing"
...
...
@@ -68,10 +65,7 @@ class StandaloneTests(unittest.TestCase):
cmd_line
=
'%s ./examples/tests/errortest_nasty3.py -r'
%
PY_CMD
expected_rc
=
exit_codes
.
AVOCADO_TESTS_FAIL
result
=
self
.
run_and_check
(
cmd_line
,
expected_rc
,
'errortest_nasty3'
)
if
sys
.
version_info
[
0
]
==
3
:
exc
=
b
"TypeError: exceptions must derive from BaseException"
else
:
exc
=
b
"TestError: <errortest_nasty3.NastyException instance at "
exc
=
b
"TypeError: exceptions must derive from BaseException"
self
.
assertIn
(
exc
,
result
.
stdout
)
def
test_errortest
(
self
):
...
...
selftests/unit/test_astring.py
浏览文件 @
479f99fb
...
...
@@ -88,11 +88,7 @@ class AstringTest(unittest.TestCase):
self
.
assertFalse
(
astring
.
is_bytes
(
text
))
self
.
assertTrue
(
hasattr
(
binary
,
'decode'
))
self
.
assertTrue
(
astring
.
is_text
(
binary
.
decode
()))
# on Python 2, each str member is also a single byte char
if
sys
.
version_info
[
0
]
<
3
:
self
.
assertTrue
(
astring
.
is_bytes
(
str
(
''
)))
else
:
self
.
assertFalse
(
astring
.
is_bytes
(
str
(
''
)))
self
.
assertFalse
(
astring
.
is_bytes
(
str
(
''
)))
def
test_is_text
(
self
):
"""
...
...
selftests/unit/test_utils_disk.py
浏览文件 @
479f99fb
import
sys
import
unittest.mock
from
..
import
recent_mock
...
...
@@ -40,11 +39,6 @@ PROC_MOUNTS = (
class
Disk
(
unittest
.
TestCase
):
@
property
def
builtin_open
(
self
):
py_version
=
sys
.
version_info
[
0
]
return
'builtins.open'
if
py_version
==
3
else
'__builtin__.open'
def
test_empty
(
self
):
mock_result
=
process
.
CmdResult
(
command
=
'lsblk --json'
,
...
...
@@ -66,7 +60,7 @@ class Disk(unittest.TestCase):
def
test_get_filesystems
(
self
):
expected_fs
=
[
'dax'
,
'bpf'
,
'pipefs'
,
'hugetlbfs'
,
'devpts'
,
'ext3'
]
open_mocked
=
unittest
.
mock
.
mock_open
(
read_data
=
PROC_FILESYSTEMS
)
with
unittest
.
mock
.
patch
(
self
.
builtin_open
,
open_mocked
):
with
unittest
.
mock
.
patch
(
'builtins.open'
,
open_mocked
):
self
.
assertEqual
(
sorted
(
expected_fs
),
sorted
(
disk
.
get_available_filesystems
()))
...
...
@@ -74,14 +68,14 @@ class Disk(unittest.TestCase):
"mock library version cannot (easily) patch open()"
)
def
test_get_filesystem_type_default_root
(
self
):
open_mocked
=
unittest
.
mock
.
mock_open
(
read_data
=
PROC_MOUNTS
)
with
unittest
.
mock
.
patch
(
self
.
builtin_open
,
open_mocked
):
with
unittest
.
mock
.
patch
(
'builtins.open'
,
open_mocked
):
self
.
assertEqual
(
'ext4'
,
disk
.
get_filesystem_type
())
@
unittest
.
skipUnless
(
recent_mock
(),
"mock library version cannot (easily) patch open()"
)
def
test_get_filesystem_type
(
self
):
open_mocked
=
unittest
.
mock
.
mock_open
(
read_data
=
PROC_MOUNTS
)
with
unittest
.
mock
.
patch
(
self
.
builtin_open
,
open_mocked
):
with
unittest
.
mock
.
patch
(
'builtins.open'
,
open_mocked
):
self
.
assertEqual
(
'ext2'
,
disk
.
get_filesystem_type
(
mount_point
=
'/home'
))
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录