Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openeuler
avocado
提交
5d8543c9
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,发现更多精彩内容 >>
未验证
提交
5d8543c9
编写于
3月 29, 2019
作者:
C
Cleber Rosa
浏览文件
操作
浏览文件
下载
差异文件
Merge remote-tracking branch 'clebergnu/builtin_open'
Signed-off-by:
N
Cleber Rosa
<
crosa@redhat.com
>
上级
40a76d97
c96f3c46
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
19 addition
and
80 deletion
+19
-80
selftests/__init__.py
selftests/__init__.py
+0
-15
selftests/unit/test_utils_cpu.py
selftests/unit/test_utils_cpu.py
+17
-50
selftests/unit/test_utils_disk.py
selftests/unit/test_utils_disk.py
+0
-7
selftests/unit/test_utils_linux_modules.py
selftests/unit/test_utils_linux_modules.py
+1
-4
selftests/unit/test_utils_process.py
selftests/unit/test_utils_process.py
+1
-4
未找到文件。
selftests/__init__.py
浏览文件 @
5d8543c9
...
...
@@ -13,21 +13,6 @@ AVOCADO = os.environ.get("UNITTEST_AVOCADO_CMD",
"%s ./scripts/avocado"
%
sys
.
executable
)
def
recent_mock
():
'''
Checks if a recent and capable enough mock library is available
On Python 3, mock from the standard library is used, but Python
3.6 or later is required.
Also, it assumes that on a future Python major version, functionality
won't regress.
'''
if
sys
.
version_info
[
0
]
==
3
:
return
sys
.
version_info
[
1
]
>=
6
return
sys
.
version_info
[
0
]
>
3
def
python_module_available
(
module_name
):
'''
Checks if a given Python module is available
...
...
selftests/unit/test_utils_cpu.py
浏览文件 @
5d8543c9
import
io
import
unittest.mock
from
..
import
recent_mock
from
avocado.utils
import
cpu
...
...
@@ -14,8 +13,6 @@ class Cpu(unittest.TestCase):
file_mock
.
__exit__
=
unittest
.
mock
.
Mock
()
return
file_mock
@
unittest
.
skipUnless
(
recent_mock
(),
"mock library version cannot (easily) patch open()"
)
def
test_s390x_cpu_online
(
self
):
s390x
=
b
"""vendor_id : IBM/S390
# processors : 2
...
...
@@ -78,15 +75,13 @@ cpu MHz static : 5504
with
unittest
.
mock
.
patch
(
'avocado.utils.cpu.platform.machine'
,
return_value
=
's390x'
):
with
unittest
.
mock
.
patch
(
'
avocado.utils.cpu
.open'
,
with
unittest
.
mock
.
patch
(
'
builtins
.open'
,
return_value
=
self
.
_get_file_mock
(
s390x
)):
self
.
assertEqual
(
len
(
cpu
.
cpu_online_list
()),
2
)
with
unittest
.
mock
.
patch
(
'
avocado.utils.cpu
.open'
,
with
unittest
.
mock
.
patch
(
'
builtins
.open'
,
return_value
=
self
.
_get_file_mock
(
s390x_2
)):
self
.
assertEqual
(
len
(
cpu
.
cpu_online_list
()),
4
)
@
unittest
.
skipUnless
(
recent_mock
(),
"mock library version cannot (easily) patch open()"
)
def
test_x86_64_cpu_online
(
self
):
x86_64
=
b
"""processor : 0
vendor_id : GenuineIntel
...
...
@@ -307,12 +302,10 @@ power management:
"""
with
unittest
.
mock
.
patch
(
'avocado.utils.cpu.platform.machine'
,
return_value
=
'x86_64'
):
with
unittest
.
mock
.
patch
(
'
avocado.utils.cpu
.open'
,
with
unittest
.
mock
.
patch
(
'
builtins
.open'
,
return_value
=
self
.
_get_file_mock
(
x86_64
)):
self
.
assertEqual
(
len
(
cpu
.
cpu_online_list
()),
8
)
@
unittest
.
skipUnless
(
recent_mock
(),
"mock library version cannot (easily) patch open()"
)
def
test_cpu_arch_i386
(
self
):
cpu_output
=
b
"""processor : 0
vendor_id : GenuineIntel
...
...
@@ -344,12 +337,10 @@ cache_alignment : 64
address sizes : 32 bits physical, 32 bits virtual
power management:
"""
with
unittest
.
mock
.
patch
(
'
avocado.utils.cpu
.open'
,
with
unittest
.
mock
.
patch
(
'
builtins
.open'
,
return_value
=
self
.
_get_file_mock
(
cpu_output
)):
self
.
assertEqual
(
cpu
.
get_cpu_arch
(),
"i386"
)
@
unittest
.
skipUnless
(
recent_mock
(),
"mock library version cannot (easily) patch open()"
)
def
test_cpu_arch_x86_64
(
self
):
cpu_output
=
b
"""processor : 0
vendor_id : GenuineIntel
...
...
@@ -378,12 +369,10 @@ cache_alignment : 64
address sizes : 39 bits physical, 48 bits virtual
power management:
"""
with
unittest
.
mock
.
patch
(
'
avocado.utils.cpu
.open'
,
with
unittest
.
mock
.
patch
(
'
builtins
.open'
,
return_value
=
self
.
_get_file_mock
(
cpu_output
)):
self
.
assertEqual
(
cpu
.
get_cpu_arch
(),
"x86_64"
)
@
unittest
.
skipUnless
(
recent_mock
(),
"mock library version cannot (easily) patch open()"
)
def
test_cpu_arch_ppc64_power8
(
self
):
cpu_output
=
b
"""processor : 88
cpu : POWER8E (raw), altivec supported
...
...
@@ -396,12 +385,10 @@ model : 8247-21L
machine : PowerNV 8247-21L
firmware : OPAL v3
"""
with
unittest
.
mock
.
patch
(
'
avocado.utils.cpu
.open'
,
with
unittest
.
mock
.
patch
(
'
builtins
.open'
,
return_value
=
self
.
_get_file_mock
(
cpu_output
)):
self
.
assertEqual
(
cpu
.
get_cpu_arch
(),
"power8"
)
@
unittest
.
skipUnless
(
recent_mock
(),
"mock library version cannot (easily) patch open()"
)
def
test_cpu_arch_ppc64_le_power8
(
self
):
cpu_output
=
b
"""processor : 88
cpu : POWER8E (raw), altivec supported
...
...
@@ -414,12 +401,10 @@ model : 8247-21L
machine : PowerNV 8247-21L
firmware : OPAL v3
"""
with
unittest
.
mock
.
patch
(
'
avocado.utils.cpu
.open'
,
with
unittest
.
mock
.
patch
(
'
builtins
.open'
,
return_value
=
self
.
_get_file_mock
(
cpu_output
)):
self
.
assertEqual
(
cpu
.
get_cpu_arch
(),
"power8"
)
@
unittest
.
skipUnless
(
recent_mock
(),
"mock library version cannot (easily) patch open()"
)
def
test_cpu_arch_ppc64_le_power9
(
self
):
cpu_output
=
b
"""processor : 20
cpu : POWER9 (raw), altivec supported
...
...
@@ -432,12 +417,10 @@ model : 8375-42A
machine : PowerNV 8375-42A
firmware : OPAL
"""
with
unittest
.
mock
.
patch
(
'
avocado.utils.cpu
.open'
,
with
unittest
.
mock
.
patch
(
'
builtins
.open'
,
return_value
=
self
.
_get_file_mock
(
cpu_output
)):
self
.
assertEqual
(
cpu
.
get_cpu_arch
(),
"power9"
)
@
unittest
.
skipUnless
(
recent_mock
(),
"mock library version cannot (easily) patch open()"
)
def
test_cpu_arch_s390
(
self
):
cpu_output
=
b
"""vendor_id : IBM/S390
# processors : 2
...
...
@@ -462,12 +445,10 @@ cpu number : 1
cpu MHz dynamic : 5504
cpu MHz static : 5504
"""
with
unittest
.
mock
.
patch
(
'
avocado.utils.cpu
.open'
,
with
unittest
.
mock
.
patch
(
'
builtins
.open'
,
return_value
=
self
.
_get_file_mock
(
cpu_output
)):
self
.
assertEqual
(
cpu
.
get_cpu_arch
(),
"s390"
)
@
unittest
.
skipUnless
(
recent_mock
(),
"mock library version cannot (easily) patch open()"
)
def
test_cpu_arch_arm_v7
(
self
):
cpu_output
=
b
"""Processor : ARMv7 Processor rev 2 (v7l)
BogoMIPS : 994.65
...
...
@@ -482,12 +463,10 @@ Hardware : herring
Revision : 0034
Serial : 3534268a5e0700ec
"""
with
unittest
.
mock
.
patch
(
'
avocado.utils.cpu
.open'
,
with
unittest
.
mock
.
patch
(
'
builtins
.open'
,
return_value
=
self
.
_get_file_mock
(
cpu_output
)):
self
.
assertEqual
(
cpu
.
get_cpu_arch
(),
"arm"
)
@
unittest
.
skipUnless
(
recent_mock
(),
"mock library version cannot (easily) patch open()"
)
def
test_cpu_arch_arm_v8
(
self
):
cpu_output
=
b
"""processor : 0
BogoMIPS : 200.00
...
...
@@ -498,81 +477,69 @@ CPU variant : 0x1
CPU part : 0x0a1
CPU revision : 1
"""
with
unittest
.
mock
.
patch
(
'
avocado.utils.cpu
.open'
,
with
unittest
.
mock
.
patch
(
'
builtins
.open'
,
return_value
=
self
.
_get_file_mock
(
cpu_output
)):
self
.
assertEqual
(
cpu
.
get_cpu_arch
(),
"aarch64"
)
@
unittest
.
skipUnless
(
recent_mock
(),
"mock library version cannot (easily) patch open()"
)
def
test_cpu_arch_risc_v
(
self
):
cpu_output
=
b
"""hart : 1
isa : rv64imafdc
mmu : sv39
uarch : sifive,rocket0
"""
with
unittest
.
mock
.
patch
(
'
avocado.utils.cpu
.open'
,
with
unittest
.
mock
.
patch
(
'
builtins
.open'
,
return_value
=
self
.
_get_file_mock
(
cpu_output
)):
self
.
assertEqual
(
cpu
.
get_cpu_arch
(),
"riscv"
)
@
unittest
.
skipUnless
(
recent_mock
(),
"mock library version cannot (easily) patch open()"
)
def
test_get_cpuidle_state_off
(
self
):
retval
=
{
0
:
{
0
:
0
}}
with
unittest
.
mock
.
patch
(
'avocado.utils.cpu.cpu_online_list'
,
return_value
=
[
0
]):
with
unittest
.
mock
.
patch
(
'glob.glob'
,
return_value
=
[
'/sys/devices/system/cpu/cpu0/cpuidle/state1'
]):
with
unittest
.
mock
.
patch
(
'
avocado.utils.cpu
.open'
,
with
unittest
.
mock
.
patch
(
'
builtins
.open'
,
return_value
=
io
.
BytesIO
(
b
'0'
)):
self
.
assertEqual
(
cpu
.
get_cpuidle_state
(),
retval
)
@
unittest
.
skipUnless
(
recent_mock
(),
"mock library version cannot (easily) patch open()"
)
def
test_get_cpuidle_state_on
(
self
):
retval
=
{
0
:
{
0
:
1
}}
with
unittest
.
mock
.
patch
(
'avocado.utils.cpu.cpu_online_list'
,
return_value
=
[
0
]):
with
unittest
.
mock
.
patch
(
'glob.glob'
,
return_value
=
[
'/sys/devices/system/cpu/cpu0/cpuidle/state1'
]):
with
unittest
.
mock
.
patch
(
'
avocado.utils.cpu
.open'
,
with
unittest
.
mock
.
patch
(
'
builtins
.open'
,
return_value
=
io
.
BytesIO
(
b
'1'
)):
self
.
assertEqual
(
cpu
.
get_cpuidle_state
(),
retval
)
@
unittest
.
skipUnless
(
recent_mock
(),
"mock library version cannot (easily) patch open()"
)
def
test_set_cpuidle_state_default
(
self
):
output
=
io
.
BytesIO
()
with
unittest
.
mock
.
patch
(
'avocado.utils.cpu.cpu_online_list'
,
return_value
=
[
0
]):
with
unittest
.
mock
.
patch
(
'glob.glob'
,
return_value
=
[
'/sys/devices/system/cpu/cpu0/cpuidle/state1'
]):
with
unittest
.
mock
.
patch
(
'
avocado.utils.cpu
.open'
,
with
unittest
.
mock
.
patch
(
'
builtins
.open'
,
return_value
=
output
):
cpu
.
set_cpuidle_state
()
self
.
assertEqual
(
output
.
getvalue
(),
b
'1'
)
@
unittest
.
skipUnless
(
recent_mock
(),
"mock library version cannot (easily) patch open()"
)
def
test_set_cpuidle_state_withstateno
(
self
):
output
=
io
.
BytesIO
()
with
unittest
.
mock
.
patch
(
'avocado.utils.cpu.cpu_online_list'
,
return_value
=
[
0
]):
with
unittest
.
mock
.
patch
(
'glob.glob'
,
return_value
=
[
'/sys/devices/system/cpu/cpu0/cpuidle/state2'
]):
with
unittest
.
mock
.
patch
(
'
avocado.utils.cpu
.open'
,
with
unittest
.
mock
.
patch
(
'
builtins
.open'
,
return_value
=
output
):
cpu
.
set_cpuidle_state
(
disable
=
False
,
state_number
=
'2'
)
self
.
assertEqual
(
output
.
getvalue
(),
b
'0'
)
@
unittest
.
skipUnless
(
recent_mock
(),
"mock library version cannot (easily) patch open()"
)
def
test_set_cpuidle_state_withsetstate
(
self
):
output
=
io
.
BytesIO
()
with
unittest
.
mock
.
patch
(
'avocado.utils.cpu.cpu_online_list'
,
return_value
=
[
0
,
2
]):
with
unittest
.
mock
.
patch
(
'glob.glob'
,
return_value
=
[
'/sys/devices/system/cpu/cpu0/cpuidle/state1'
]):
with
unittest
.
mock
.
patch
(
'
avocado.utils.cpu
.open'
,
with
unittest
.
mock
.
patch
(
'
builtins
.open'
,
return_value
=
output
):
cpu
.
set_cpuidle_state
(
setstate
=
{
0
:
{
0
:
1
},
2
:
{
0
:
0
}})
self
.
assertEqual
(
output
.
getvalue
(),
b
'10'
)
...
...
selftests/unit/test_utils_disk.py
浏览文件 @
5d8543c9
import
unittest.mock
from
..
import
recent_mock
from
avocado.utils
import
disk
from
avocado.utils
import
process
...
...
@@ -55,8 +54,6 @@ class Disk(unittest.TestCase):
return_value
=
mock_result
):
self
.
assertEqual
(
disk
.
get_disks
(),
[
'/dev/vda'
])
@
unittest
.
skipUnless
(
recent_mock
(),
"mock library version cannot (easily) patch open()"
)
def
test_get_filesystems
(
self
):
expected_fs
=
[
'dax'
,
'bpf'
,
'pipefs'
,
'hugetlbfs'
,
'devpts'
,
'ext3'
]
open_mocked
=
unittest
.
mock
.
mock_open
(
read_data
=
PROC_FILESYSTEMS
)
...
...
@@ -64,15 +61,11 @@ class Disk(unittest.TestCase):
self
.
assertEqual
(
sorted
(
expected_fs
),
sorted
(
disk
.
get_available_filesystems
()))
@
unittest
.
skipUnless
(
recent_mock
(),
"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
(
'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
(
'builtins.open'
,
open_mocked
):
...
...
selftests/unit/test_utils_linux_modules.py
浏览文件 @
5d8543c9
import
io
import
unittest.mock
from
..
import
recent_mock
from
avocado.utils
import
linux_modules
...
...
@@ -195,10 +194,8 @@ video 45056 2 thinkpad_acpi,i915, Live 0x0000000000000000
'used'
:
1
,
'submodules'
:
[
'ebtable_broute'
]})
@
unittest
.
skipUnless
(
recent_mock
(),
"mock library version cannot (easily) patch open()"
)
def
test_is_module_loaded
(
self
):
with
unittest
.
mock
.
patch
(
'
avocado.utils.linux_module
s.open'
,
with
unittest
.
mock
.
patch
(
'
builtin
s.open'
,
return_value
=
self
.
_get_file_mock
(
self
.
PROC_MODULES_OUT
)):
self
.
assertTrue
(
linux_modules
.
module_is_loaded
(
"rfcomm"
))
self
.
assertFalse
(
linux_modules
.
module_is_loaded
(
"unknown_module"
))
...
...
selftests/unit/test_utils_process.py
浏览文件 @
5d8543c9
...
...
@@ -7,7 +7,6 @@ import sys
import
time
from
..
import
recent_mock
from
avocado.utils
import
astring
from
avocado.utils
import
script
from
avocado.utils
import
gdb
...
...
@@ -422,11 +421,9 @@ class MiscProcessTests(unittest.TestCase):
[
u
"avok
\xe1
do_test_runner"
,
u
"arguments"
])
@
unittest
.
skipUnless
(
recent_mock
(),
"mock library version cannot (easily) patch open()"
)
def
test_get_parent_pid
(
self
):
stat
=
b
'18405 (bash) S 24139 18405 18405 34818 8056 4210688 9792 170102 0 7 11 4 257 84 20 0 1 0 44336493 235409408 4281 18446744073709551615 94723230367744 94723231442728 140723100226000 0 0 0 65536 3670020 1266777851 0 0 0 17 1 0 0 0 0 0 94723233541456 94723233588580 94723248717824 140723100229613 140723100229623 140723100229623 140723100233710 0'
with
unittest
.
mock
.
patch
(
'
avocado.utils.proces
s.open'
,
with
unittest
.
mock
.
patch
(
'
builtin
s.open'
,
return_value
=
io
.
BytesIO
(
stat
)):
self
.
assertTrue
(
process
.
get_parent_pid
(
0
),
24139
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录