update testcase for testsuite python3-pydocstyle
This commit is contained in:
@@ -6,145 +6,17 @@
|
||||
"name": "test_python3-pydocstyle_function_doc_check",
|
||||
"desc": "Check docstring compliance"
|
||||
},
|
||||
{
|
||||
"name": "test_python3-pydocstyle_function_style_validate",
|
||||
"desc": "Validate docstring style"
|
||||
},
|
||||
{
|
||||
"name": "test_python3-pydocstyle_function_error_report",
|
||||
"desc": "Report docstring errors"
|
||||
},
|
||||
{
|
||||
"name": "test_python3-pydocstyle_pydocstyle__h",
|
||||
"desc": "测试显示帮助信息"
|
||||
},
|
||||
{
|
||||
"name": "test_python3-pydocstyle_pydocstyle__help",
|
||||
"desc": "测试显示帮助信息"
|
||||
},
|
||||
{
|
||||
"name": "test_python3-pydocstyle_pydocstyle__version",
|
||||
"desc": "测试显示程序版本号"
|
||||
},
|
||||
{
|
||||
"name": "test_python3-pydocstyle_pydocstyle__e",
|
||||
"desc": "测试显示每个错误的解释"
|
||||
},
|
||||
{
|
||||
"name": "test_python3-pydocstyle_pydocstyle__explain",
|
||||
"desc": "测试显示每个错误的解释"
|
||||
},
|
||||
{
|
||||
"name": "test_python3-pydocstyle_pydocstyle__s",
|
||||
"desc": "测试显示每个错误的源代码"
|
||||
},
|
||||
{
|
||||
"name": "test_python3-pydocstyle_pydocstyle__source",
|
||||
"desc": "测试显示每个错误的源代码"
|
||||
},
|
||||
{
|
||||
"name": "test_python3-pydocstyle_pydocstyle__d",
|
||||
"desc": "测试打印调试信息"
|
||||
},
|
||||
{
|
||||
"name": "test_python3-pydocstyle_pydocstyle__debug",
|
||||
"desc": "测试打印调试信息"
|
||||
},
|
||||
{
|
||||
"name": "test_python3-pydocstyle_pydocstyle__v",
|
||||
"desc": "测试打印状态信息"
|
||||
},
|
||||
{
|
||||
"name": "test_python3-pydocstyle_pydocstyle__verbose",
|
||||
"desc": "测试打印状态信息"
|
||||
},
|
||||
{
|
||||
"name": "test_python3-pydocstyle_pydocstyle__count",
|
||||
"desc": "测试打印错误总数到标准输出"
|
||||
},
|
||||
{
|
||||
"name": "test_python3-pydocstyle_pydocstyle__config_eq_path",
|
||||
"desc": "测试使用指定配置文件并禁用配置发现"
|
||||
},
|
||||
{
|
||||
"name": "test_python3-pydocstyle_pydocstyle__match_eq_pattern",
|
||||
"desc": "测试仅检查完全匹配指定正则表达式的文件"
|
||||
},
|
||||
{
|
||||
"name": "test_python3-pydocstyle_pydocstyle__match_dir_eq_pattern",
|
||||
"desc": "测试仅搜索完全匹配指定正则表达式的目录"
|
||||
},
|
||||
{
|
||||
"name": "test_python3-pydocstyle_pydocstyle__ignore_decorators_eq_decorators",
|
||||
"desc": "测试忽略被指定正则表达式匹配的装饰器装饰的函数或方法"
|
||||
},
|
||||
{
|
||||
"name": "test_python3-pydocstyle_pydocstyle__property_decorators_eq_property_decorators",
|
||||
"desc": "测试将使用指定装饰器装饰的方法视为属性"
|
||||
},
|
||||
{
|
||||
"name": "test_python3-pydocstyle_pydocstyle__select_eq_codes",
|
||||
"desc": "测试通过指定错误代码来选择要检查的基本错误列表"
|
||||
},
|
||||
{
|
||||
"name": "test_python3-pydocstyle_pydocstyle__ignore_eq_codes",
|
||||
"desc": "测试通过指定要忽略的错误代码来选择基本错误列表"
|
||||
},
|
||||
{
|
||||
"name": "test_python3-pydocstyle_pydocstyle__convention_eq_name",
|
||||
"desc": "测试通过指定现有约定来选择基本错误列表"
|
||||
},
|
||||
{
|
||||
"name": "test_python3-pydocstyle_pydocstyle__add_select_eq_codes",
|
||||
"desc": "测试向先前设置的基本错误列表中添加额外的错误代码"
|
||||
},
|
||||
{
|
||||
"name": "test_python3-pydocstyle_pydocstyle__add_ignore_eq_codes",
|
||||
"desc": "测试通过从先前设置的基本错误列表中移除来忽略额外的错误代码"
|
||||
},
|
||||
{
|
||||
"name": "test_python3-pydocstyle_pydocstyle__ignore_self_only_init",
|
||||
"desc": "测试忽略仅包含self参数的__init__方法"
|
||||
},
|
||||
{
|
||||
"name": "test_python3-pydocstyle_function_install",
|
||||
"desc": "Test package installation"
|
||||
},
|
||||
{
|
||||
"name": "test_python3-pydocstyle_function_uninstall",
|
||||
"desc": "Test package removal"
|
||||
},
|
||||
{
|
||||
"name": "test_python3-pydocstyle_function_check_installed",
|
||||
"desc": "Verify package is installed"
|
||||
},
|
||||
{
|
||||
"name": "test_python3-pydocstyle_function_basic_usage",
|
||||
"desc": "Basic command line usage"
|
||||
},
|
||||
{
|
||||
"name": "test_python3-pydocstyle_function_check_file",
|
||||
"desc": "Check docstring of file"
|
||||
},
|
||||
{
|
||||
"name": "test_python3-pydocstyle_function_check_dir",
|
||||
"desc": "Check docstring in directory"
|
||||
},
|
||||
{
|
||||
"name": "test_python3-pydocstyle_function_select_codes",
|
||||
"desc": "Select specific error codes"
|
||||
},
|
||||
{
|
||||
"name": "test_python3-pydocstyle_function_ignore_codes",
|
||||
"desc": "Ignore specific error codes"
|
||||
},
|
||||
{
|
||||
"name": "test_python3-pydocstyle_function_use_convention",
|
||||
"desc": "Use predefined convention"
|
||||
},
|
||||
{
|
||||
"name": "test_python3-pydocstyle_function_explain_error",
|
||||
"desc": "Explain specific error"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -1,107 +0,0 @@
|
||||
#!/usr/bin/bash
|
||||
|
||||
# Copyright (c) 2024 ISCAS .ALL rights reserved.
|
||||
# This program is licensed under Mulan PSL v2.
|
||||
# You can use it according to the terms and conditions of the Mulan PSL v2.
|
||||
# http://license.coscl.org.cn/MulanPSL2
|
||||
# THIS PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
# EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
# MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
# See the Mulan PSL v2 for more details.
|
||||
|
||||
# #############################################
|
||||
# @Author : honghua
|
||||
# @Contact : honghua@iscas.ac.cn
|
||||
# @Date : 2026-03-03
|
||||
# @License : Mulan PSL v2
|
||||
# @Desc : Basic command line usage
|
||||
# ############################################
|
||||
|
||||
source "$OET_PATH/libs/locallibs/common_lib.sh"
|
||||
|
||||
function run_test() {
|
||||
# 定义变量
|
||||
PYTHON_PACKAGE="python3-pydocstyle"
|
||||
TEST_FILE="/tmp/test_python_script.py"
|
||||
EXPECTED_OUTPUT="test_python_script.py:1 at module level"
|
||||
|
||||
# 步骤1:检查软件包是否在yum源中
|
||||
LOG_INFO "步骤1:检查软件包是否在yum源中"
|
||||
if ! dnf list available ${PYTHON_PACKAGE} &>/dev/null; then
|
||||
LOG_ERROR "软件包 ${PYTHON_PACKAGE} 不在yum源中"
|
||||
exit 255
|
||||
fi
|
||||
|
||||
# 步骤2:检查是否已安装软件包
|
||||
LOG_INFO "步骤2:检查是否已安装软件包"
|
||||
if rpm -q ${PYTHON_PACKAGE} &>/dev/null; then
|
||||
LOG_INFO "软件包 ${PYTHON_PACKAGE} 已安装,测试结束后将保持安装状态"
|
||||
INSTALLED_BEFORE_TEST=true
|
||||
else
|
||||
LOG_INFO "软件包 ${PYTHON_PACKAGE} 未安装,测试结束后将卸载"
|
||||
INSTALLED_BEFORE_TEST=false
|
||||
fi
|
||||
|
||||
# 步骤3:如果未安装,则安装软件包
|
||||
if [ "${INSTALLED_BEFORE_TEST}" = "false" ]; then
|
||||
LOG_INFO "步骤3:安装软件包 ${PYTHON_PACKAGE}"
|
||||
dnf install -y ${PYTHON_PACKAGE}
|
||||
CHECK_RESULT $? 0 0 "安装软件包失败"
|
||||
fi
|
||||
|
||||
# 步骤4:验证pydocstyle命令是否可用
|
||||
LOG_INFO "步骤4:验证pydocstyle命令是否可用"
|
||||
if ! command -v pydocstyle &>/dev/null; then
|
||||
LOG_ERROR "pydocstyle命令不存在"
|
||||
exit 255
|
||||
fi
|
||||
|
||||
# 步骤5:检查pydocstyle命令支持的参数
|
||||
LOG_INFO "步骤5:检查pydocstyle命令支持的参数"
|
||||
if ! pydocstyle --help | grep -q "\-\-help"; then
|
||||
LOG_ERROR "pydocstyle命令不支持--help参数"
|
||||
exit 255
|
||||
fi
|
||||
|
||||
# 步骤6:创建一个测试Python文件用于pydocstyle检查
|
||||
LOG_INFO "步骤6:创建一个测试Python文件用于pydocstyle检查"
|
||||
cat > ${TEST_FILE} << "EOF"
|
||||
"""This is a test module."""
|
||||
def test_function():
|
||||
"""This is a test function."""
|
||||
pass
|
||||
EOF
|
||||
CHECK_RESULT $? 0 0 "创建测试文件失败"
|
||||
|
||||
# 步骤7:运行pydocstyle检查测试文件
|
||||
LOG_INFO "步骤7:运行pydocstyle检查测试文件"
|
||||
pydocstyle ${TEST_FILE} 2>&1 | tee /tmp/pydocstyle_output.txt
|
||||
CHECK_RESULT $? 1 0 "pydocstyle命令执行失败" # pydocstyle在发现问题时返回非零,这里预期有错误
|
||||
|
||||
# 步骤8:验证pydocstyle输出是否符合预期
|
||||
LOG_INFO "步骤8:验证pydocstyle输出是否符合预期"
|
||||
if grep -q "${EXPECTED_OUTPUT}" /tmp/pydocstyle_output.txt; then
|
||||
LOG_INFO "pydocstyle输出符合预期"
|
||||
else
|
||||
LOG_ERROR "pydocstyle输出不符合预期"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# 步骤9:清理测试文件
|
||||
LOG_INFO "步骤9:清理测试文件"
|
||||
rm -f ${TEST_FILE} /tmp/pydocstyle_output.txt
|
||||
CHECK_RESULT $? 0 0 "清理测试文件失败"
|
||||
|
||||
# 步骤10:如果测试前未安装,则卸载软件包
|
||||
if [ "${INSTALLED_BEFORE_TEST}" = "false" ]; then
|
||||
LOG_INFO "步骤10:卸载软件包 ${PYTHON_PACKAGE}"
|
||||
dnf remove -y ${PYTHON_PACKAGE}
|
||||
CHECK_RESULT $? 0 0 "卸载软件包失败"
|
||||
else
|
||||
LOG_INFO "步骤10:测试前已安装软件包,保持安装状态"
|
||||
fi
|
||||
|
||||
LOG_INFO "测试完成"
|
||||
}
|
||||
|
||||
main "$@"
|
||||
@@ -1,88 +0,0 @@
|
||||
#!/usr/bin/bash
|
||||
|
||||
# Copyright (c) 2024 ISCAS .ALL rights reserved.
|
||||
# This program is licensed under Mulan PSL v2.
|
||||
# You can use it according to the terms and conditions of the Mulan PSL v2.
|
||||
# http://license.coscl.org.cn/MulanPSL2
|
||||
# THIS PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
# EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
# MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
# See the Mulan PSL v2 for more details.
|
||||
|
||||
# #############################################
|
||||
# @Author : honghua
|
||||
# @Contact : honghua@iscas.ac.cn
|
||||
# @Date : 2026-03-03
|
||||
# @License : Mulan PSL v2
|
||||
# @Desc : Check docstring in directory
|
||||
# ############################################
|
||||
|
||||
source "$OET_PATH/libs/locallibs/common_lib.sh"
|
||||
|
||||
function run_test() {
|
||||
LOG_INFO "开始测试:检查目录中的文档字符串"
|
||||
|
||||
LOG_INFO "步骤1:检查是否已安装pydocstyle"
|
||||
if command -v pydocstyle &> /dev/null; then
|
||||
LOG_INFO "pydocstyle已安装,跳过安装步骤"
|
||||
INSTALLED=true
|
||||
else
|
||||
LOG_INFO "pydocstyle未安装,将进行安装"
|
||||
INSTALLED=false
|
||||
fi
|
||||
|
||||
LOG_INFO "步骤2:检查yum源中是否有python3-pydocstyle包"
|
||||
if ! dnf list available python3-pydocstyle &> /dev/null; then
|
||||
LOG_ERROR "yum源中未找到python3-pydocstyle包"
|
||||
exit 255
|
||||
fi
|
||||
|
||||
if [ "$INSTALLED" = false ]; then
|
||||
LOG_INFO "步骤3:安装python3-pydocstyle"
|
||||
dnf install -y python3-pydocstyle
|
||||
CHECK_RESULT $? 0 0 "安装python3-pydocstyle失败"
|
||||
fi
|
||||
|
||||
LOG_INFO "步骤4:验证pydocstyle命令是否可用"
|
||||
pydocstyle --version
|
||||
CHECK_RESULT $? 0 0 "pydocstyle命令不可用"
|
||||
|
||||
LOG_INFO "步骤5:检查pydocstyle是否支持目录参数"
|
||||
if ! pydocstyle --help | grep -q "directory"; then
|
||||
LOG_ERROR "pydocstyle不支持目录参数"
|
||||
exit 255
|
||||
fi
|
||||
|
||||
LOG_INFO "步骤6:创建测试目录和Python文件"
|
||||
TEST_DIR="/tmp/test_pydocstyle_dir"
|
||||
mkdir -p "$TEST_DIR"
|
||||
cat > "$TEST_DIR/test_file1.py" << EOF
|
||||
def func1():
|
||||
"""This is a docstring."""
|
||||
pass
|
||||
EOF
|
||||
|
||||
cat > "$TEST_DIR/test_file2.py" << EOF
|
||||
def func2():
|
||||
pass
|
||||
EOF
|
||||
|
||||
LOG_INFO "步骤7:运行pydocstyle检查目录中的文档字符串"
|
||||
pydocstyle "$TEST_DIR"
|
||||
CHECK_RESULT $? 0 0 "pydocstyle检查目录失败"
|
||||
|
||||
LOG_INFO "步骤8:清理测试目录"
|
||||
rm -rf "$TEST_DIR"
|
||||
|
||||
if [ "$INSTALLED" = false ]; then
|
||||
LOG_INFO "步骤9:卸载python3-pydocstyle"
|
||||
dnf remove -y python3-pydocstyle
|
||||
CHECK_RESULT $? 0 0 "卸载python3-pydocstyle失败"
|
||||
else
|
||||
LOG_INFO "步骤9:保持pydocstyle安装状态"
|
||||
fi
|
||||
|
||||
LOG_INFO "测试完成:检查目录中的文档字符串"
|
||||
}
|
||||
|
||||
main "$@"
|
||||
@@ -1,79 +0,0 @@
|
||||
#!/usr/bin/bash
|
||||
|
||||
# Copyright (c) 2024 ISCAS .ALL rights reserved.
|
||||
# This program is licensed under Mulan PSL v2.
|
||||
# You can use it according to the terms and conditions of the Mulan PSL v2.
|
||||
# http://license.coscl.org.cn/MulanPSL2
|
||||
# THIS PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
# EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
# MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
# See the Mulan PSL v2 for more details.
|
||||
|
||||
# #############################################
|
||||
# @Author : honghua
|
||||
# @Contact : honghua@iscas.ac.cn
|
||||
# @Date : 2026-03-03
|
||||
# @License : Mulan PSL v2
|
||||
# @Desc : Check docstring of file
|
||||
# ############################################
|
||||
|
||||
source "$OET_PATH/libs/locallibs/common_lib.sh"
|
||||
|
||||
function run_test() {
|
||||
LOG_INFO "开始测试:检查文件的docstring"
|
||||
LOG_INFO "步骤1:检查环境中是否已安装python3-pydocstyle软件包"
|
||||
if dnf list installed python3-pydocstyle &>/dev/null; then
|
||||
LOG_INFO "python3-pydocstyle已安装,测试后保持安装状态"
|
||||
INSTALLED=1
|
||||
else
|
||||
LOG_INFO "python3-pydocstyle未安装,将在测试步骤中安装"
|
||||
INSTALLED=0
|
||||
fi
|
||||
|
||||
LOG_INFO "步骤2:检查yum源中是否有python3-pydocstyle软件包"
|
||||
if ! dnf list available python3-pydocstyle &>/dev/null; then
|
||||
LOG_ERROR "yum源中未找到python3-pydocstyle软件包"
|
||||
exit 255
|
||||
fi
|
||||
|
||||
if [ $INSTALLED -eq 0 ]; then
|
||||
LOG_INFO "步骤3:安装python3-pydocstyle软件包"
|
||||
dnf install -y python3-pydocstyle
|
||||
CHECK_RESULT $? 0 0 "安装python3-pydocstyle失败"
|
||||
fi
|
||||
|
||||
LOG_INFO "步骤4:检查pydocstyle命令是否支持文件参数"
|
||||
if ! pydocstyle --help | grep -q "file"; then
|
||||
LOG_ERROR "pydocstyle命令不支持文件参数"
|
||||
if [ $INSTALLED -eq 0 ]; then
|
||||
dnf remove -y python3-pydocstyle
|
||||
fi
|
||||
exit 255
|
||||
fi
|
||||
|
||||
LOG_INFO "步骤5:创建一个测试Python文件用于检查docstring"
|
||||
cat > test_docstring.py << "EOF"
|
||||
def example_function():
|
||||
"""这是一个示例函数的docstring。"""
|
||||
return "Hello, World!"
|
||||
EOF
|
||||
|
||||
LOG_INFO "步骤6:使用pydocstyle检查测试文件的docstring"
|
||||
pydocstyle test_docstring.py
|
||||
CHECK_RESULT $? 0 0 "检查文件docstring失败"
|
||||
|
||||
LOG_INFO "步骤7:清理测试文件"
|
||||
rm -f test_docstring.py
|
||||
|
||||
if [ $INSTALLED -eq 0 ]; then
|
||||
LOG_INFO "步骤8:卸载python3-pydocstyle软件包"
|
||||
dnf remove -y python3-pydocstyle
|
||||
CHECK_RESULT $? 0 0 "卸载python3-pydocstyle失败"
|
||||
else
|
||||
LOG_INFO "步骤8:保持python3-pydocstyle安装状态"
|
||||
fi
|
||||
|
||||
LOG_INFO "测试完成:检查文件的docstring"
|
||||
}
|
||||
|
||||
main "$@"
|
||||
@@ -1,70 +0,0 @@
|
||||
#!/usr/bin/bash
|
||||
|
||||
# Copyright (c) 2024 ISCAS .ALL rights reserved.
|
||||
# This program is licensed under Mulan PSL v2.
|
||||
# You can use it according to the terms and conditions of the Mulan PSL v2.
|
||||
# http://license.coscl.org.cn/MulanPSL2
|
||||
# THIS PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
# EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
# MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
# See the Mulan PSL v2 for more details.
|
||||
|
||||
# #############################################
|
||||
# @Author : honghua
|
||||
# @Contact : honghua@iscas.ac.cn
|
||||
# @Date : 2026-03-03
|
||||
# @License : Mulan PSL v2
|
||||
# @Desc : Verify package is installed
|
||||
# ############################################
|
||||
|
||||
source "$OET_PATH/libs/locallibs/common_lib.sh"
|
||||
|
||||
function run_test() {
|
||||
LOG_INFO "开始测试:验证python3-pydocstyle包是否已安装"
|
||||
LOG_INFO "步骤1:检查yum源中是否存在python3-pydocstyle包"
|
||||
dnf list available python3-pydocstyle > /dev/null 2>&1
|
||||
if [ $? -ne 0 ]; then
|
||||
LOG_ERROR "yum源中未找到python3-pydocstyle包"
|
||||
exit 255
|
||||
fi
|
||||
LOG_INFO "yum源中存在python3-pydocstyle包"
|
||||
|
||||
LOG_INFO "步骤2:检查系统是否已安装python3-pydocstyle包"
|
||||
rpm -q python3-pydocstyle > /dev/null 2>&1
|
||||
if [ $? -eq 0 ]; then
|
||||
LOG_INFO "python3-pydocstyle包已安装,标记为已安装状态"
|
||||
INSTALLED=1
|
||||
else
|
||||
LOG_INFO "python3-pydocstyle包未安装,标记为未安装状态"
|
||||
INSTALLED=0
|
||||
fi
|
||||
|
||||
LOG_INFO "步骤3:如果未安装,则安装python3-pydocstyle包"
|
||||
if [ $INSTALLED -eq 0 ]; then
|
||||
dnf install -y python3-pydocstyle
|
||||
CHECK_RESULT $? 0 0 "安装python3-pydocstyle包失败"
|
||||
LOG_INFO "python3-pydocstyle包安装成功"
|
||||
fi
|
||||
|
||||
LOG_INFO "步骤4:验证python3-pydocstyle包是否已正确安装"
|
||||
rpm -q python3-pydocstyle > /dev/null 2>&1
|
||||
CHECK_RESULT $? 0 0 "python3-pydocstyle包未正确安装"
|
||||
|
||||
LOG_INFO "步骤5:验证pydocstyle命令是否可用"
|
||||
pydocstyle --help > /dev/null 2>&1
|
||||
CHECK_RESULT $? 0 0 "pydocstyle命令不可用或参数不支持"
|
||||
|
||||
LOG_INFO "步骤6:清理环境,恢复原始状态"
|
||||
if [ $INSTALLED -eq 0 ]; then
|
||||
LOG_INFO "卸载测试期间安装的python3-pydocstyle包"
|
||||
dnf remove -y python3-pydocstyle
|
||||
CHECK_RESULT $? 0 0 "卸载python3-pydocstyle包失败"
|
||||
LOG_INFO "python3-pydocstyle包卸载成功"
|
||||
else
|
||||
LOG_INFO "系统原本已安装python3-pydocstyle包,保持安装状态"
|
||||
fi
|
||||
|
||||
LOG_INFO "测试完成:验证python3-pydocstyle包是否已安装"
|
||||
}
|
||||
|
||||
main "$@"
|
||||
@@ -1,83 +0,0 @@
|
||||
#!/usr/bin/bash
|
||||
|
||||
# Copyright (c) 2024 ISCAS .ALL rights reserved.
|
||||
# This program is licensed under Mulan PSL v2.
|
||||
# You can use it according to the terms and conditions of the Mulan PSL v2.
|
||||
# http://license.coscl.org.cn/MulanPSL2
|
||||
# THIS PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
# EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
# MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
# See the Mulan PSL v2 for more details.
|
||||
|
||||
# #############################################
|
||||
# @Author : honghua
|
||||
# @Contact : honghua@iscas.ac.cn
|
||||
# @Date : 2025-12-09
|
||||
# @License : Mulan PSL v2
|
||||
# @Desc : Report docstring errors
|
||||
# ############################################
|
||||
|
||||
source "$OET_PATH/libs/locallibs/common_lib.sh"
|
||||
|
||||
function run_test() {
|
||||
|
||||
# 检查是否已安装pydocstyle
|
||||
LOG_INFO "检查是否已安装pydocstyle"
|
||||
if ! dnf list installed python3-pydocstyle &>/dev/null; then
|
||||
LOG_INFO "未安装pydocstyle,准备安装"
|
||||
# 检查yum源中是否有该软件包
|
||||
if ! dnf list available python3-pydocstyle &>/dev/null; then
|
||||
LOG_ERROR "yum源中未找到python3-pydocstyle软件包"
|
||||
exit 255
|
||||
fi
|
||||
# 安装软件包
|
||||
dnf install -y python3-pydocstyle
|
||||
CHECK_RESULT $? 0 0 "安装python3-pydocstyle失败"
|
||||
INSTALLED=true
|
||||
else
|
||||
LOG_INFO "pydocstyle已安装"
|
||||
INSTALLED=false
|
||||
fi
|
||||
|
||||
# 测试pydocstyle功能:报告文档字符串错误
|
||||
LOG_INFO "测试pydocstyle功能:报告文档字符串错误"
|
||||
TEST_FILE="test_docstring.py"
|
||||
cat > $TEST_FILE <<EOF
|
||||
def example_function():
|
||||
\"\"\"
|
||||
This is a function without proper docstring.
|
||||
\"\"\"
|
||||
pass
|
||||
|
||||
def another_function():
|
||||
\"\"\"
|
||||
This function has a proper docstring.
|
||||
|
||||
Args:
|
||||
None
|
||||
Returns:
|
||||
None
|
||||
\"\"\"
|
||||
pass
|
||||
EOF
|
||||
|
||||
# 运行pydocstyle检查文档字符串
|
||||
LOG_INFO "运行pydocstyle检查文档字符串错误"
|
||||
pydocstyle $TEST_FILE > /dev/null 2>&1
|
||||
CHECK_RESULT $? 1 0 "pydocstyle未正确报告文档字符串错误"
|
||||
|
||||
# 清理测试文件
|
||||
rm -f $TEST_FILE
|
||||
|
||||
# 恢复环境
|
||||
if [ "$INSTALLED" = true ]; then
|
||||
LOG_INFO "卸载python3-pydocstage"
|
||||
dnf remove -y python3-pydocstyle
|
||||
CHECK_RESULT $? 0 0 "卸载python3-pydocstage失败"
|
||||
fi
|
||||
|
||||
LOG_INFO "测试完成"
|
||||
|
||||
}
|
||||
|
||||
main "$@"
|
||||
@@ -1,83 +0,0 @@
|
||||
#!/usr/bin/bash
|
||||
|
||||
# Copyright (c) 2024 ISCAS .ALL rights reserved.
|
||||
# This program is licensed under Mulan PSL v2.
|
||||
# You can use it according to the terms and conditions of the Mulan PSL v2.
|
||||
# http://license.coscl.org.cn/MulanPSL2
|
||||
# THIS PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
# EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
# MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
# See the Mulan PSL v2 for more details.
|
||||
|
||||
# #############################################
|
||||
# @Author : honghua
|
||||
# @Contact : honghua@iscas.ac.cn
|
||||
# @Date : 2026-03-03
|
||||
# @License : Mulan PSL v2
|
||||
# @Desc : Explain specific error
|
||||
# ############################################
|
||||
|
||||
source "$OET_PATH/libs/locallibs/common_lib.sh"
|
||||
|
||||
function run_test() {
|
||||
LOG_INFO "开始测试:Explain specific error"
|
||||
LOG_INFO "步骤1:检查python3-pydocstyle软件包是否在yum源中"
|
||||
if ! dnf list available python3-pydocstyle &>/dev/null; then
|
||||
LOG_ERROR "python3-pydocstyle软件包不在yum源中"
|
||||
exit 255
|
||||
fi
|
||||
LOG_INFO "python3-pydocstyle软件包在yum源中"
|
||||
|
||||
LOG_INFO "步骤2:检查系统是否已安装python3-pydocstyle"
|
||||
if rpm -q python3-pydocstyle &>/dev/null; then
|
||||
LOG_INFO "python3-pydocstyle已安装,测试结束后保持安装状态"
|
||||
INSTALLED=true
|
||||
else
|
||||
LOG_INFO "python3-pydocstyle未安装,将在测试前安装"
|
||||
INSTALLED=false
|
||||
fi
|
||||
|
||||
if [ "$INSTALLED" = false ]; then
|
||||
LOG_INFO "步骤3:安装python3-pydocstyle软件包"
|
||||
dnf install -y python3-pydocstyle
|
||||
CHECK_RESULT $? 0 0 "安装python3-pydocstyle失败"
|
||||
fi
|
||||
|
||||
LOG_INFO "步骤4:验证pydocstyle命令是否支持--explain参数"
|
||||
if ! pydocstyle --help | grep -q -- --explain; then
|
||||
LOG_ERROR "pydocstyle命令不支持--explain参数"
|
||||
if [ "$INSTALLED" = false ]; then
|
||||
LOG_INFO "清理环境:卸载python3-pydocstyle"
|
||||
dnf remove -y python3-pydocstyle
|
||||
fi
|
||||
exit 255
|
||||
fi
|
||||
LOG_INFO "pydocstyle命令支持--explain参数"
|
||||
|
||||
LOG_INFO "步骤5:创建一个测试Python文件用于检查特定错误"
|
||||
cat > test_explain.py << "EOF"
|
||||
def bad_function():
|
||||
"""This is a bad function.
|
||||
"""
|
||||
pass
|
||||
EOF
|
||||
|
||||
LOG_INFO "步骤6:使用pydocstyle检查测试文件,并使用--explain参数解释特定错误"
|
||||
pydocstyle --explain D401 test_explain.py
|
||||
CHECK_RESULT $? 0 0 "pydocstyle --explain命令执行失败"
|
||||
|
||||
LOG_INFO "步骤7:清理测试文件"
|
||||
rm -f test_explain.py
|
||||
|
||||
if [ "$INSTALLED" = false ]; then
|
||||
LOG_INFO "步骤8:卸载python3-pydocstyle软件包"
|
||||
dnf remove -y python3-pydocstyle
|
||||
CHECK_RESULT $? 0 0 "卸载python3-pydocstyle失败"
|
||||
else
|
||||
LOG_INFO "步骤8:保持python3-pydocstyle安装状态"
|
||||
fi
|
||||
|
||||
LOG_INFO "测试完成:Explain specific error"
|
||||
}
|
||||
|
||||
main "$@"
|
||||
@@ -1,113 +0,0 @@
|
||||
#!/usr/bin/bash
|
||||
|
||||
# Copyright (c) 2024 ISCAS .ALL rights reserved.
|
||||
# This program is licensed under Mulan PSL v2.
|
||||
# You can use it according to the terms and conditions of the Mulan PSL v2.
|
||||
# http://license.coscl.org.cn/MulanPSL2
|
||||
# THIS PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
# EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
# MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
# See the Mulan PSL v2 for more details.
|
||||
|
||||
# #############################################
|
||||
# @Author : honghua
|
||||
# @Contact : honghua@iscas.ac.cn
|
||||
# @Date : 2026-03-03
|
||||
# @License : Mulan PSL v2
|
||||
# @Desc : Ignore specific error codes
|
||||
# ############################################
|
||||
|
||||
source "$OET_PATH/libs/locallibs/common_lib.sh"
|
||||
|
||||
function run_test() {
|
||||
LOG_INFO "开始测试:Ignore specific error codes"
|
||||
|
||||
LOG_INFO "1. 检查yum源中是否存在python3-pydocstyle软件包"
|
||||
if ! dnf list available python3-pydocstyle &>/dev/null; then
|
||||
LOG_ERROR "yum源中未找到python3-pydocstyle软件包"
|
||||
exit 255
|
||||
fi
|
||||
|
||||
LOG_INFO "2. 检查当前是否已安装python3-pydocstyle"
|
||||
if rpm -q python3-pydocstyle &>/dev/null; then
|
||||
LOG_INFO "检测到python3-pydocstyle已安装,测试结束后将保持安装状态"
|
||||
INSTALLED_BEFORE_TEST=true
|
||||
else
|
||||
LOG_INFO "python3-pydocstyle未安装,将在测试中安装"
|
||||
INSTALLED_BEFORE_TEST=false
|
||||
fi
|
||||
|
||||
if [ "$INSTALLED_BEFORE_TEST" = false ]; then
|
||||
LOG_INFO "3. 安装python3-pydocstyle软件包"
|
||||
dnf install -y python3-pydocstyle
|
||||
CHECK_RESULT $? 0 0 "安装python3-pydocstyle失败"
|
||||
fi
|
||||
|
||||
LOG_INFO "4. 验证pydocstyle命令是否支持--ignore参数"
|
||||
if ! pydocstyle --help 2>&1 | grep -q -- "--ignore"; then
|
||||
LOG_ERROR "pydocstyle命令不支持--ignore参数"
|
||||
if [ "$INSTALLED_BEFORE_TEST" = false ]; then
|
||||
LOG_INFO "清理环境:卸载python3-pydocstyle"
|
||||
dnf remove -y python3-pydocstyle
|
||||
fi
|
||||
exit 255
|
||||
fi
|
||||
|
||||
LOG_INFO "5. 创建测试用Python文件"
|
||||
TEST_FILE="/tmp/test_ignore_codes.py"
|
||||
cat > "$TEST_FILE" << "EOF"
|
||||
def func_without_docstring():
|
||||
pass
|
||||
|
||||
def func_with_bad_whitespace():
|
||||
"""Bad whitespace."""
|
||||
pass
|
||||
|
||||
def func_with_missing_blank_line():
|
||||
"""Missing blank line."""
|
||||
pass
|
||||
EOF
|
||||
CHECK_RESULT $? 0 0 "创建测试文件失败"
|
||||
|
||||
LOG_INFO "6. 运行pydocstyle,忽略D100错误码(缺失文档字符串)"
|
||||
pydocstyle --ignore=D100 "$TEST_FILE" 2>&1 | tee /tmp/pydocstyle_output.txt
|
||||
CHECK_RESULT $? 1 0 "pydocstyle执行失败或返回码不符合预期"
|
||||
|
||||
LOG_INFO "7. 检查输出中是否不包含D100错误"
|
||||
if grep -q "D100" /tmp/pydocstyle_output.txt; then
|
||||
LOG_ERROR "输出中包含应被忽略的D100错误"
|
||||
CHECK_RESULT 1 0 0 "忽略D100错误码失败"
|
||||
else
|
||||
LOG_INFO "成功:输出中未发现D100错误"
|
||||
CHECK_RESULT 0 0 0 "忽略D100错误码验证成功"
|
||||
fi
|
||||
|
||||
LOG_INFO "8. 运行pydocstyle,同时忽略D100和D203错误码"
|
||||
pydocstyle --ignore=D100,D203 "$TEST_FILE" 2>&1 | tee /tmp/pydocstyle_output_multi.txt
|
||||
CHECK_RESULT $? 1 0 "pydocstyle执行失败或返回码不符合预期"
|
||||
|
||||
LOG_INFO "9. 检查输出中是否不包含D100和D203错误"
|
||||
if grep -q "D100\|D203" /tmp/pydocstyle_output_multi.txt; then
|
||||
LOG_ERROR "输出中包含应被忽略的D100或D203错误"
|
||||
CHECK_RESULT 1 0 0 "同时忽略多个错误码失败"
|
||||
else
|
||||
LOG_INFO "成功:输出中未发现D100和D203错误"
|
||||
CHECK_RESULT 0 0 0 "同时忽略多个错误码验证成功"
|
||||
fi
|
||||
|
||||
LOG_INFO "10. 清理测试文件"
|
||||
rm -f "$TEST_FILE" /tmp/pydocstyle_output*.txt
|
||||
CHECK_RESULT $? 0 0 "清理测试文件失败"
|
||||
|
||||
if [ "$INSTALLED_BEFORE_TEST" = false ]; then
|
||||
LOG_INFO "11. 清理环境:卸载python3-pydocstyle"
|
||||
dnf remove -y python3-pydocstyle
|
||||
CHECK_RESULT $? 0 0 "卸载python3-pydocstyle失败"
|
||||
else
|
||||
LOG_INFO "11. 保持python3-pydocstyle安装状态"
|
||||
fi
|
||||
|
||||
LOG_INFO "测试完成:Ignore specific error codes"
|
||||
}
|
||||
|
||||
main "$@"
|
||||
@@ -1,91 +0,0 @@
|
||||
#!/usr/bin/bash
|
||||
|
||||
# Copyright (c) 2024 ISCAS .ALL rights reserved.
|
||||
# This program is licensed under Mulan PSL v2.
|
||||
# You can use it according to the terms and conditions of the Mulan PSL v2.
|
||||
# http://license.coscl.org.cn/MulanPSL2
|
||||
# THIS PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
# EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
# MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
# See the Mulan PSL v2 for more details.
|
||||
|
||||
# #############################################
|
||||
# @Author : honghua
|
||||
# @Contact : honghua@iscas.ac.cn
|
||||
# @Date : 2026-03-03
|
||||
# @License : Mulan PSL v2
|
||||
# @Desc : Test package installation
|
||||
# ############################################
|
||||
|
||||
source "$OET_PATH/libs/locallibs/common_lib.sh"
|
||||
|
||||
function run_test() {
|
||||
# 定义软件包名称
|
||||
PACKAGE_NAME="python3-pydocstyle"
|
||||
|
||||
# 步骤1: 检查软件包是否已在yum源中
|
||||
LOG_INFO "检查软件包 ${PACKAGE_NAME} 是否在yum源中"
|
||||
dnf list available ${PACKAGE_NAME} &>/dev/null
|
||||
if [ $? -ne 0 ]; then
|
||||
LOG_ERROR "软件包 ${PACKAGE_NAME} 不在yum源中"
|
||||
exit 255
|
||||
fi
|
||||
|
||||
# 步骤2: 检查当前是否已安装软件包
|
||||
LOG_INFO "检查当前是否已安装软件包 ${PACKAGE_NAME}"
|
||||
rpm -q ${PACKAGE_NAME} &>/dev/null
|
||||
if [ $? -eq 0 ]; then
|
||||
INSTALLED=true
|
||||
LOG_INFO "软件包 ${PACKAGE_NAME} 已安装,测试后保持安装状态"
|
||||
else
|
||||
INSTALLED=false
|
||||
LOG_INFO "软件包 ${PACKAGE_NAME} 未安装,将在测试后卸载"
|
||||
fi
|
||||
|
||||
# 步骤3: 如果未安装,则安装软件包
|
||||
if [ "${INSTALLED}" = "false" ]; then
|
||||
LOG_INFO "安装软件包 ${PACKAGE_NAME}"
|
||||
dnf install -y ${PACKAGE_NAME}
|
||||
CHECK_RESULT $? 0 0 "安装软件包 ${PACKAGE_NAME} 失败"
|
||||
fi
|
||||
|
||||
# 步骤4: 验证软件包安装成功
|
||||
LOG_INFO "验证软件包 ${PACKAGE_NAME} 是否安装成功"
|
||||
rpm -q ${PACKAGE_NAME} &>/dev/null
|
||||
CHECK_RESULT $? 0 0 "验证软件包 ${PACKAGE_NAME} 安装失败"
|
||||
|
||||
# 步骤5: 测试软件包的基本功能
|
||||
LOG_INFO "测试软件包 ${PACKAGE_NAME} 的基本功能"
|
||||
pydocstyle --version &>/dev/null
|
||||
CHECK_RESULT $? 0 0 "测试软件包 ${PACKAGE_NAME} 基本功能失败"
|
||||
|
||||
# 步骤6: 测试不支持的参数
|
||||
LOG_INFO "测试软件包 ${PACKAGE_NAME} 不支持参数的情况"
|
||||
pydocstyle --nonexistent-option &>/dev/null
|
||||
if [ $? -ne 255 ] && [ $? -ne 2 ]; then
|
||||
LOG_ERROR "软件包 ${PACKAGE_NAME} 参数检查失败"
|
||||
exit 255
|
||||
fi
|
||||
|
||||
# 步骤7: 清理环境,如果测试前未安装则卸载软件包
|
||||
if [ "${INSTALLED}" = "false" ]; then
|
||||
LOG_INFO "卸载软件包 ${PACKAGE_NAME}"
|
||||
dnf remove -y ${PACKAGE_NAME}
|
||||
CHECK_RESULT $? 0 0 "卸载软件包 ${PACKAGE_NAME} 失败"
|
||||
|
||||
LOG_INFO "验证软件包 ${PACKAGE_NAME} 是否已卸载"
|
||||
rpm -q ${PACKAGE_NAME} &>/dev/null
|
||||
if [ $? -eq 0 ]; then
|
||||
LOG_ERROR "软件包 ${PACKAGE_NAME} 卸载失败"
|
||||
exit 1
|
||||
else
|
||||
LOG_INFO "软件包 ${PACKAGE_NAME} 已成功卸载"
|
||||
fi
|
||||
else
|
||||
LOG_INFO "测试前软件包已安装,保持安装状态"
|
||||
fi
|
||||
|
||||
LOG_INFO "测试完成,环境已恢复"
|
||||
}
|
||||
|
||||
main "$@"
|
||||
@@ -1,83 +0,0 @@
|
||||
#!/usr/bin/bash
|
||||
|
||||
# Copyright (c) 2024 ISCAS .ALL rights reserved.
|
||||
# This program is licensed under Mulan PSL v2.
|
||||
# You can use it according to the terms and conditions of the Mulan PSL v2.
|
||||
# http://license.coscl.org.cn/MulanPSL2
|
||||
# THIS PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
# EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
# MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
# See the Mulan PSL v2 for more details.
|
||||
|
||||
# #############################################
|
||||
# @Author : honghua
|
||||
# @Contact : honghua@iscas.ac.cn
|
||||
# @Date : 2026-03-03
|
||||
# @License : Mulan PSL v2
|
||||
# @Desc : Select specific error codes
|
||||
# ############################################
|
||||
|
||||
source "$OET_PATH/libs/locallibs/common_lib.sh"
|
||||
|
||||
function run_test() {
|
||||
LOG_INFO "开始测试:Select specific error codes"
|
||||
|
||||
# 检查是否已安装python3-pydocstyle
|
||||
if rpm -q python3-pydocstyle &> /dev/null; then
|
||||
LOG_INFO "python3-pydocstyle已安装,测试结束后将保持安装状态"
|
||||
already_installed=1
|
||||
else
|
||||
LOG_INFO "python3-pydocstyle未安装,将在测试中安装并最终卸载"
|
||||
already_installed=0
|
||||
fi
|
||||
|
||||
# 检查yum源中是否有python3-pydocstyle软件包
|
||||
LOG_INFO "检查yum源中是否有python3-pydocstyle软件包"
|
||||
if ! dnf list available python3-pydocstyle &> /dev/null; then
|
||||
LOG_ERROR "yum源中未找到python3-pydocstyle软件包"
|
||||
exit 255
|
||||
fi
|
||||
|
||||
# 如果未安装,则安装软件包
|
||||
if [ $already_installed -eq 0 ]; then
|
||||
LOG_INFO "安装python3-pydocstyle软件包"
|
||||
dnf install -y python3-pydocstyle
|
||||
CHECK_RESULT $? 0 0 "安装python3-pydocstyle失败"
|
||||
fi
|
||||
|
||||
# 测试pydocstyle的--select参数
|
||||
LOG_INFO "测试pydocstyle的--select参数,选择特定错误码D203"
|
||||
pydocstyle --select D203 /usr/lib64/python3.9/argparse.py
|
||||
CHECK_RESULT $? 0 0 "执行pydocstyle --select D203失败"
|
||||
|
||||
# 测试不存在的参数
|
||||
LOG_INFO "测试pydocstyle的不存在的参数--nonexistent"
|
||||
pydocstyle --nonexistent 2>&1 | grep -q "error:"
|
||||
if [ $? -eq 0 ]; then
|
||||
LOG_INFO "参数--nonexistent不存在,符合预期"
|
||||
else
|
||||
LOG_ERROR "参数--nonexistent未被正确识别为无效参数"
|
||||
exit 255
|
||||
fi
|
||||
|
||||
# 测试不支持的参数值
|
||||
LOG_INFO "测试pydocstyle的不支持的参数值--select=INVALID"
|
||||
pydocstyle --select=INVALID 2>&1 | grep -q "error:"
|
||||
if [ $? -eq 0 ]; then
|
||||
LOG_INFO "参数值INVALID不被支持,符合预期"
|
||||
else
|
||||
LOG_ERROR "参数值INVALID未被正确识别为无效"
|
||||
exit 255
|
||||
fi
|
||||
|
||||
# 清理环境:如果测试前未安装,则卸载软件包
|
||||
if [ $already_installed -eq 0 ]; then
|
||||
LOG_INFO "卸载python3-pydocstyle软件包"
|
||||
dnf remove -y python3-pydocstyle
|
||||
CHECK_RESULT $? 0 0 "卸载python3-pydocstyle失败"
|
||||
fi
|
||||
|
||||
LOG_INFO "测试完成:Select specific error codes"
|
||||
}
|
||||
|
||||
main "$@"
|
||||
@@ -1,71 +0,0 @@
|
||||
#!/usr/bin/bash
|
||||
|
||||
# Copyright (c) 2024 ISCAS .ALL rights reserved.
|
||||
# This program is licensed under Mulan PSL v2.
|
||||
# You can use it according to the terms and conditions of the Mulan PSL v2.
|
||||
# http://license.coscl.org.cn/MulanPSL2
|
||||
# THIS PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
# EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
# MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
# See the Mulan PSL v2 for more details.
|
||||
|
||||
# #############################################
|
||||
# @Author : honghua
|
||||
# @Contact : honghua@iscas.ac.cn
|
||||
# @Date : 2025-12-09
|
||||
# @License : Mulan PSL v2
|
||||
# @Desc : Validate docstring style
|
||||
# ############################################
|
||||
|
||||
source "$OET_PATH/libs/locallibs/common_lib.sh"
|
||||
|
||||
function run_test() {
|
||||
|
||||
# 测试脚本:test_python3-pydocstyle_function_style_validate
|
||||
|
||||
# 步骤1:检查是否已安装python3-pydocstyle
|
||||
LOG_INFO "检查是否已安装python3-pydocstyle"
|
||||
if dnf list installed python3-pydocstyle &>/dev/null; then
|
||||
LOG_INFO "python3-pydocstyle已安装,脚本结束时将保持安装状态"
|
||||
INSTALLED=true
|
||||
else
|
||||
LOG_INFO "python3-pydocstyle未安装,将在测试完成后卸载"
|
||||
INSTALLED=false
|
||||
fi
|
||||
|
||||
# 步骤2:检查yum源中是否存在python3-pydocstyle
|
||||
LOG_INFO "检查yum源中是否存在python3-pydocstyle"
|
||||
if ! dnf list available python3-pydocstyle &>/dev/null; then
|
||||
LOG_ERROR "yum源中未找到python3-pydocstyle"
|
||||
exit 255
|
||||
fi
|
||||
|
||||
# 步骤3:安装python3-pydocstyle(如果未安装)
|
||||
if [ "$INSTALLED" = false ]; then
|
||||
LOG_INFO "开始安装python3-pydocstyle"
|
||||
dnf install -y python3-pydocstyle
|
||||
CHECK_RESULT $? 0 0 "安装python3-pydocstyle失败"
|
||||
fi
|
||||
|
||||
# 步骤4:验证pydocstyle命令是否支持--help参数
|
||||
LOG_INFO "验证pydocstyle命令是否支持--help参数"
|
||||
pydocstyle --help &>/dev/null
|
||||
CHECK_RESULT $? 0 0 "pydocstyle不支持--help参数"
|
||||
|
||||
# 步骤5:执行docstring风格验证
|
||||
LOG_INFO "执行docstring风格验证"
|
||||
pydocstyle /path/to/python/file.py # 替换为实际文件路径
|
||||
CHECK_RESULT $? 0 0 "docstring风格验证失败"
|
||||
|
||||
# 步骤6:清理环境(如果脚本开始时未安装)
|
||||
if [ "$INSTALLED" = false ]; then
|
||||
LOG_INFO "卸载python3-pydocstyle"
|
||||
dnf remove -y python3-pydocstyle
|
||||
CHECK_RESULT $? 0 0 "卸载python3-pydocstyle失败"
|
||||
fi
|
||||
|
||||
LOG_INFO "测试脚本执行完毕,环境已恢复"
|
||||
|
||||
}
|
||||
|
||||
main "$@"
|
||||
@@ -1,78 +0,0 @@
|
||||
#!/usr/bin/bash
|
||||
|
||||
# Copyright (c) 2024 ISCAS .ALL rights reserved.
|
||||
# This program is licensed under Mulan PSL v2.
|
||||
# You can use it according to the terms and conditions of the Mulan PSL v2.
|
||||
# http://license.coscl.org.cn/MulanPSL2
|
||||
# THIS PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
# EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
# MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
# See the Mulan PSL v2 for more details.
|
||||
|
||||
# #############################################
|
||||
# @Author : honghua
|
||||
# @Contact : honghua@iscas.ac.cn
|
||||
# @Date : 2026-03-03
|
||||
# @License : Mulan PSL v2
|
||||
# @Desc : Test package removal
|
||||
# ############################################
|
||||
|
||||
source "$OET_PATH/libs/locallibs/common_lib.sh"
|
||||
|
||||
function run_test() {
|
||||
LOG_INFO "开始测试:Test package removal"
|
||||
LOG_INFO "步骤1:检查yum源中是否存在python3-pydocstyle软件包"
|
||||
dnf list available python3-pydocstyle > /dev/null 2>&1
|
||||
if [ $? -ne 0 ]; then
|
||||
LOG_ERROR "yum源中未找到python3-pydocstyle软件包"
|
||||
exit 255
|
||||
fi
|
||||
LOG_INFO "yum源中存在python3-pydocstyle软件包"
|
||||
|
||||
LOG_INFO "步骤2:检查当前环境是否已安装python3-pydocstyle软件包"
|
||||
rpm -q python3-pydocstyle > /dev/null 2>&1
|
||||
if [ $? -eq 0 ]; then
|
||||
LOG_INFO "当前环境已安装python3-pydocstyle软件包,测试完成后将保持安装状态"
|
||||
INSTALLED_BEFORE=1
|
||||
else
|
||||
LOG_INFO "当前环境未安装python3-pydocstyle软件包,将进行安装测试"
|
||||
INSTALLED_BEFORE=0
|
||||
fi
|
||||
|
||||
if [ $INSTALLED_BEFORE -eq 0 ]; then
|
||||
LOG_INFO "步骤3:安装python3-pydocstyle软件包"
|
||||
dnf install -y python3-pydocstyle
|
||||
CHECK_RESULT $? 0 0 "安装python3-pydocstyle软件包失败"
|
||||
LOG_INFO "安装python3-pydocstyle软件包成功"
|
||||
fi
|
||||
|
||||
LOG_INFO "步骤4:验证python3-pydocstyle软件包是否成功安装"
|
||||
rpm -q python3-pydocstyle > /dev/null 2>&1
|
||||
CHECK_RESULT $? 0 0 "验证python3-pydocstyle软件包安装状态失败"
|
||||
|
||||
LOG_INFO "步骤5:执行python3-pydocstyle命令验证功能"
|
||||
python3-pydocstyle --help > /dev/null 2>&1
|
||||
CHECK_RESULT $? 0 0 "python3-pydocstyle命令执行失败或参数不支持"
|
||||
LOG_INFO "python3-pydocstyle命令功能正常"
|
||||
|
||||
if [ $INSTALLED_BEFORE -eq 0 ]; then
|
||||
LOG_INFO "步骤6:卸载python3-pydocstyle软件包"
|
||||
dnf remove -y python3-pydocstyle
|
||||
CHECK_RESULT $? 0 0 "卸载python3-pydocstyle软件包失败"
|
||||
LOG_INFO "卸载python3-pydocstyle软件包成功"
|
||||
|
||||
LOG_INFO "步骤7:验证python3-pydocstyle软件包是否成功卸载"
|
||||
rpm -q python3-pydocstyle > /dev/null 2>&1
|
||||
if [ $? -eq 0 ]; then
|
||||
LOG_ERROR "python3-pydocstyle软件包卸载失败"
|
||||
exit 1
|
||||
fi
|
||||
LOG_INFO "python3-pydocstyle软件包已成功卸载"
|
||||
else
|
||||
LOG_INFO "步骤6:环境恢复:保持python3-pydocstyle软件包的安装状态"
|
||||
fi
|
||||
|
||||
LOG_INFO "测试完成:Test package removal"
|
||||
}
|
||||
|
||||
main "$@"
|
||||
@@ -1,91 +0,0 @@
|
||||
#!/usr/bin/bash
|
||||
|
||||
# Copyright (c) 2024 ISCAS .ALL rights reserved.
|
||||
# This program is licensed under Mulan PSL v2.
|
||||
# You can use it according to the terms and conditions of the Mulan PSL v2.
|
||||
# http://license.coscl.org.cn/MulanPSL2
|
||||
# THIS PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
# EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
# MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
# See the Mulan PSL v2 for more details.
|
||||
|
||||
# #############################################
|
||||
# @Author : honghua
|
||||
# @Contact : honghua@iscas.ac.cn
|
||||
# @Date : 2026-03-03
|
||||
# @License : Mulan PSL v2
|
||||
# @Desc : Use predefined convention
|
||||
# ############################################
|
||||
|
||||
source "$OET_PATH/libs/locallibs/common_lib.sh"
|
||||
|
||||
function run_test() {
|
||||
# 测试脚本开始
|
||||
LOG_INFO "开始测试:Use predefined convention"
|
||||
|
||||
# 检查是否已安装python3-pydocstyle
|
||||
LOG_INFO "步骤1:检查python3-pydocstyle是否已安装"
|
||||
if dnf list installed python3-pydocstyle &>/dev/null; then
|
||||
LOG_INFO "python3-pydocstyle已安装"
|
||||
installed_before=true
|
||||
else
|
||||
LOG_INFO "python3-pydocstyle未安装"
|
||||
installed_before=false
|
||||
fi
|
||||
|
||||
# 检查yum源中是否有python3-pydocstyle软件包
|
||||
LOG_INFO "步骤2:检查yum源中是否有python3-pydocstyle软件包"
|
||||
if ! dnf list available python3-pydocstyle &>/dev/null; then
|
||||
LOG_ERROR "yum源中未找到python3-pydocstyle软件包"
|
||||
exit 255
|
||||
fi
|
||||
|
||||
# 如果未安装,则安装软件包
|
||||
if [ "$installed_before" = false ]; then
|
||||
LOG_INFO "步骤3:安装python3-pydocstyle软件包"
|
||||
dnf install -y python3-pydocstyle
|
||||
CHECK_RESULT $? 0 0 "安装python3-pydocstyle失败"
|
||||
LOG_INFO "python3-pydocstyle安装成功"
|
||||
fi
|
||||
|
||||
# 测试pydocstyle命令的基本功能
|
||||
LOG_INFO "步骤4:测试pydocstyle命令的基本功能"
|
||||
pydocstyle --version
|
||||
CHECK_RESULT $? 0 0 "pydocstyle命令执行失败"
|
||||
|
||||
# 测试pydocstyle命令的参数是否支持
|
||||
LOG_INFO "步骤5:测试pydocstyle命令的参数是否支持"
|
||||
pydocstyle --help | grep -q "convention"
|
||||
CHECK_RESULT $? 0 0 "pydocstyle命令不支持convention参数"
|
||||
|
||||
# 创建一个测试Python文件
|
||||
LOG_INFO "步骤6:创建一个测试Python文件"
|
||||
cat > test_example.py << EOF
|
||||
def example_function():
|
||||
"""This is an example function."""
|
||||
pass
|
||||
EOF
|
||||
|
||||
# 使用pydocstyle检查测试文件
|
||||
LOG_INFO "步骤7:使用pydocstyle检查测试文件"
|
||||
pydocstyle test_example.py
|
||||
CHECK_RESULT $? 0 0 "pydocstyle检查测试文件失败"
|
||||
|
||||
# 清理测试文件
|
||||
LOG_INFO "步骤8:清理测试文件"
|
||||
rm -f test_example.py
|
||||
|
||||
# 如果之前未安装,则卸载软件包
|
||||
if [ "$installed_before" = false ]; then
|
||||
LOG_INFO "步骤9:卸载python3-pydocstyle软件包"
|
||||
dnf remove -y python3-pydocstyle
|
||||
CHECK_RESULT $? 0 0 "卸载python3-pydocstyle失败"
|
||||
LOG_INFO "python3-pydocstyle卸载成功"
|
||||
else
|
||||
LOG_INFO "步骤9:保持python3-pydocstyle安装状态"
|
||||
fi
|
||||
|
||||
LOG_INFO "测试完成:Use predefined convention"
|
||||
}
|
||||
|
||||
main "$@"
|
||||
@@ -1,87 +0,0 @@
|
||||
#!/usr/bin/bash
|
||||
|
||||
# Copyright (c) 2024 ISCAS .ALL rights reserved.
|
||||
# This program is licensed under Mulan PSL v2.
|
||||
# You can use it according to the terms and conditions of the Mulan PSL v2.
|
||||
# http://license.coscl.org.cn/MulanPSL2
|
||||
# THIS PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
# EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
# MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
# See the Mulan PSL v2 for more details.
|
||||
|
||||
# #############################################
|
||||
# @Author : honghua
|
||||
# @Contact : honghua@iscas.ac.cn
|
||||
# @Date : 2026-03-03
|
||||
# @License : Mulan PSL v2
|
||||
# @Desc : 测试使用指定配置文件并禁用配置发现
|
||||
# ############################################
|
||||
|
||||
source "$OET_PATH/libs/locallibs/common_lib.sh"
|
||||
|
||||
function run_test() {
|
||||
LOG_INFO "开始测试:测试使用指定配置文件并禁用配置发现"
|
||||
|
||||
# 检查是否已安装python3-pydocstyle
|
||||
LOG_INFO "检查是否已安装python3-pydocstyle"
|
||||
if dnf list installed python3-pydocstyle &> /dev/null; then
|
||||
LOG_INFO "python3-pydocstyle已安装,测试结束后将保持安装状态"
|
||||
already_installed=1
|
||||
else
|
||||
LOG_INFO "python3-pydocstyle未安装,将在测试步骤中安装"
|
||||
already_installed=0
|
||||
fi
|
||||
|
||||
# 检查yum源中是否有python3-pydocstyle软件包
|
||||
LOG_INFO "检查yum源中是否有python3-pydocstyle软件包"
|
||||
if ! dnf list available python3-pydocstyle &> /dev/null; then
|
||||
LOG_ERROR "yum源中没有python3-pydocstyle软件包"
|
||||
exit 255
|
||||
fi
|
||||
|
||||
# 如果未安装,则安装软件包
|
||||
if [ $already_installed -eq 0 ]; then
|
||||
LOG_INFO "安装python3-pydocstyle软件包"
|
||||
dnf install -y python3-pydocstyle
|
||||
CHECK_RESULT $? 0 0 "安装python3-pydocstyle失败"
|
||||
fi
|
||||
|
||||
# 创建测试用的配置文件
|
||||
LOG_INFO "创建测试用的配置文件"
|
||||
cat > /tmp/test_pydocstyle_config.ini << EOF
|
||||
[pydocstyle]
|
||||
ignore = D100,D101
|
||||
EOF
|
||||
CHECK_RESULT $? 0 0 "创建配置文件失败"
|
||||
|
||||
# 创建测试用的Python文件
|
||||
LOG_INFO "创建测试用的Python文件"
|
||||
cat > /tmp/test_python_file.py << EOF
|
||||
"""Test module docstring."""
|
||||
def test_function():
|
||||
"""Test function docstring."""
|
||||
pass
|
||||
EOF
|
||||
CHECK_RESULT $? 0 0 "创建Python文件失败"
|
||||
|
||||
# 测试使用指定配置文件并禁用配置发现
|
||||
LOG_INFO "测试使用指定配置文件并禁用配置发现"
|
||||
pydocstyle --config=/tmp/test_pydocstyle_config.ini --disable-config-discovery /tmp/test_python_file.py
|
||||
CHECK_RESULT $? 0 0 "pydocstyle命令执行失败"
|
||||
|
||||
# 清理临时文件
|
||||
LOG_INFO "清理临时文件"
|
||||
rm -f /tmp/test_pydocstyle_config.ini /tmp/test_python_file.py
|
||||
CHECK_RESULT $? 0 0 "清理临时文件失败"
|
||||
|
||||
# 如果测试前未安装,则卸载软件包
|
||||
if [ $already_installed -eq 0 ]; then
|
||||
LOG_INFO "卸载python3-pydocstyle软件包"
|
||||
dnf remove -y python3-pydocstyle
|
||||
CHECK_RESULT $? 0 0 "卸载python3-pydocstyle失败"
|
||||
fi
|
||||
|
||||
LOG_INFO "测试完成:测试使用指定配置文件并禁用配置发现"
|
||||
}
|
||||
|
||||
main "$@"
|
||||
@@ -1,72 +0,0 @@
|
||||
#!/usr/bin/bash
|
||||
|
||||
# Copyright (c) 2024 ISCAS .ALL rights reserved.
|
||||
# This program is licensed under Mulan PSL v2.
|
||||
# You can use it according to the terms and conditions of the Mulan PSL v2.
|
||||
# http://license.coscl.org.cn/MulanPSL2
|
||||
# THIS PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
# EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
# MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
# See the Mulan PSL v2 for more details.
|
||||
|
||||
# #############################################
|
||||
# @Author : honghua
|
||||
# @Contact : honghua@iscas.ac.cn
|
||||
# @Date : 2026-03-03
|
||||
# @License : Mulan PSL v2
|
||||
# @Desc : 测试打印调试信息
|
||||
# ############################################
|
||||
|
||||
source "$OET_PATH/libs/locallibs/common_lib.sh"
|
||||
|
||||
function run_test() {
|
||||
LOG_INFO "开始测试:测试打印调试信息"
|
||||
LOG_INFO "步骤1:检查yum源中是否存在python3-pydocstyle和pydocstyle软件包"
|
||||
dnf list available python3-pydocstyle pydocstyle &> /dev/null
|
||||
if [ $? -ne 0 ]; then
|
||||
LOG_ERROR "yum源中不存在python3-pydocstyle或pydocstyle软件包"
|
||||
exit 255
|
||||
fi
|
||||
LOG_INFO "yum源中存在python3-pydocstyle和pydocstyle软件包"
|
||||
|
||||
LOG_INFO "步骤2:检查环境是否已安装python3-pydocstyle和pydocstyle"
|
||||
rpm -q python3-pydocstyle pydocstyle &> /dev/null
|
||||
if [ $? -eq 0 ]; then
|
||||
LOG_INFO "环境已安装python3-pydocstyle和pydocstyle,脚本结束后将保持安装状态"
|
||||
INSTALLED=true
|
||||
else
|
||||
LOG_INFO "环境未安装python3-pydocstyle和pydocstyle,将进行安装"
|
||||
INSTALLED=false
|
||||
fi
|
||||
|
||||
if [ "$INSTALLED" = false ]; then
|
||||
LOG_INFO "步骤3:安装python3-pydocstyle和pydocstyle软件包"
|
||||
dnf install -y python3-pydocstyle pydocstyle
|
||||
CHECK_RESULT $? 0 0 "安装python3-pydocstyle和pydocstyle失败"
|
||||
fi
|
||||
|
||||
LOG_INFO "步骤4:检查pydocstyle命令是否支持--debug参数"
|
||||
pydocstyle --help | grep -q -- --debug
|
||||
if [ $? -ne 0 ]; then
|
||||
LOG_ERROR "pydocstyle命令不支持--debug参数"
|
||||
exit 255
|
||||
fi
|
||||
LOG_INFO "pydocstyle命令支持--debug参数"
|
||||
|
||||
LOG_INFO "步骤5:使用pydocstyle命令打印调试信息"
|
||||
pydocstyle --debug /usr/lib/python3.9/site-packages/pydocstyle/ 2>&1 | head -20
|
||||
CHECK_RESULT $? 0 0 "执行pydocstyle --debug命令失败"
|
||||
|
||||
LOG_INFO "步骤6:清理环境"
|
||||
if [ "$INSTALLED" = false ]; then
|
||||
LOG_INFO "卸载python3-pydocstyle和pydocstyle软件包"
|
||||
dnf remove -y python3-pydocstyle pydocstyle
|
||||
CHECK_RESULT $? 0 0 "卸载python3-pydocstyle和pydocstyle失败"
|
||||
else
|
||||
LOG_INFO "环境已安装python3-pydocstyle和pydocstyle,保持安装状态"
|
||||
fi
|
||||
|
||||
LOG_INFO "测试完成"
|
||||
}
|
||||
|
||||
main "$@"
|
||||
@@ -1,94 +0,0 @@
|
||||
#!/usr/bin/bash
|
||||
|
||||
# Copyright (c) 2024 ISCAS .ALL rights reserved.
|
||||
# This program is licensed under Mulan PSL v2.
|
||||
# You can use it according to the terms and conditions of the Mulan PSL v2.
|
||||
# http://license.coscl.org.cn/MulanPSL2
|
||||
# THIS PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
# EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
# MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
# See the Mulan PSL v2 for more details.
|
||||
|
||||
# #############################################
|
||||
# @Author : honghua
|
||||
# @Contact : honghua@iscas.ac.cn
|
||||
# @Date : 2026-03-03
|
||||
# @License : Mulan PSL v2
|
||||
# @Desc : 测试显示每个错误的解释
|
||||
# ############################################
|
||||
|
||||
source "$OET_PATH/libs/locallibs/common_lib.sh"
|
||||
|
||||
function run_test() {
|
||||
LOG_INFO "开始测试:测试显示每个错误的解释"
|
||||
|
||||
# 检查yum源中是否存在python3-pydocstyle软件包
|
||||
LOG_INFO "检查yum源中是否存在python3-pydocstyle软件包"
|
||||
if ! dnf list available python3-pydocstyle &>/dev/null; then
|
||||
LOG_ERROR "yum源中不存在python3-pydocstyle软件包"
|
||||
exit 255
|
||||
fi
|
||||
|
||||
# 检查pydocstyle命令是否已安装
|
||||
LOG_INFO "检查pydocstyle命令是否已安装"
|
||||
if command -v pydocstyle &>/dev/null; then
|
||||
LOG_INFO "pydocstyle命令已安装,脚本结束后保持安装状态"
|
||||
ALREADY_INSTALLED=true
|
||||
else
|
||||
LOG_INFO "pydocstyle命令未安装,将在测试过程中安装"
|
||||
ALREADY_INSTALLED=false
|
||||
fi
|
||||
|
||||
# 如果未安装,则安装软件包
|
||||
if [ "$ALREADY_INSTALLED" = false ]; then
|
||||
LOG_INFO "安装python3-pydocstyle软件包"
|
||||
dnf install -y python3-pydocstyle
|
||||
CHECK_RESULT $? 0 0 "安装python3-pydocstyle软件包失败"
|
||||
fi
|
||||
|
||||
# 检查pydocstyle命令是否支持--explain参数
|
||||
LOG_INFO "检查pydocstyle命令是否支持--explain参数"
|
||||
if ! pydocstyle --help | grep -q -- "--explain"; then
|
||||
LOG_ERROR "pydocstyle命令不支持--explain参数"
|
||||
if [ "$ALREADY_INSTALLED" = false ]; then
|
||||
LOG_INFO "卸载python3-pydocstyle软件包"
|
||||
dnf remove -y python3-pydocstyle
|
||||
fi
|
||||
exit 255
|
||||
fi
|
||||
|
||||
# 创建一个临时Python文件用于测试
|
||||
LOG_INFO "创建一个临时Python文件用于测试"
|
||||
TEMP_PY_FILE=$(mktemp /tmp/test_python_XXXXXX.py)
|
||||
cat > "$TEMP_PY_FILE" << "EOF"
|
||||
def bad_function():
|
||||
"""缺少参数说明"""
|
||||
pass
|
||||
|
||||
class BadClass:
|
||||
"""类文档字符串不完整"""
|
||||
def method(self):
|
||||
"""方法文档字符串缺少返回值和异常说明"""
|
||||
pass
|
||||
EOF
|
||||
|
||||
# 使用pydocstyle检查临时文件并显示每个错误的解释
|
||||
LOG_INFO "使用pydocstyle检查临时文件并显示每个错误的解释"
|
||||
pydocstyle --explain "$TEMP_PY_FILE"
|
||||
CHECK_RESULT $? 0 0 "pydocstyle命令执行失败"
|
||||
|
||||
# 清理临时文件
|
||||
LOG_INFO "清理临时文件"
|
||||
rm -f "$TEMP_PY_FILE"
|
||||
|
||||
# 如果测试开始时未安装,则卸载软件包
|
||||
if [ "$ALREADY_INSTALLED" = false ]; then
|
||||
LOG_INFO "卸载python3-pydocstyle软件包"
|
||||
dnf remove -y python3-pydocstyle
|
||||
CHECK_RESULT $? 0 0 "卸载python3-pydocstyle软件包失败"
|
||||
fi
|
||||
|
||||
LOG_INFO "测试完成:测试显示每个错误的解释"
|
||||
}
|
||||
|
||||
main "$@"
|
||||
@@ -1,76 +0,0 @@
|
||||
#!/usr/bin/bash
|
||||
|
||||
# Copyright (c) 2024 ISCAS .ALL rights reserved.
|
||||
# This program is licensed under Mulan PSL v2.
|
||||
# You can use it according to the terms and conditions of the Mulan PSL v2.
|
||||
# http://license.coscl.org.cn/MulanPSL2
|
||||
# THIS PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
# EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
# MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
# See the Mulan PSL v2 for more details.
|
||||
|
||||
# #############################################
|
||||
# @Author : honghua
|
||||
# @Contact : honghua@iscas.ac.cn
|
||||
# @Date : 2026-03-03
|
||||
# @License : Mulan PSL v2
|
||||
# @Desc : 测试显示每个错误的解释
|
||||
# ############################################
|
||||
|
||||
source "$OET_PATH/libs/locallibs/common_lib.sh"
|
||||
|
||||
function run_test() {
|
||||
LOG_INFO "1. 检查yum源中是否存在python3-pydocstyle和pydocstyle软件包"
|
||||
dnf list available python3-pydocstyle pydocstyle 2>/dev/null | grep -E "^python3-pydocstyle|^pydocstyle" >/dev/null
|
||||
CHECK_RESULT $? 0 0 "yum源中未找到python3-pydocstyle或pydocstyle软件包"
|
||||
|
||||
LOG_INFO "2. 检查当前环境是否已安装python3-pydocstyle和pydocstyle"
|
||||
rpm -q python3-pydocstyle pydocstyle >/dev/null 2>&1
|
||||
if [ $? -eq 0 ]; then
|
||||
LOG_INFO "软件包已安装,标记为已安装状态"
|
||||
INSTALLED=1
|
||||
else
|
||||
LOG_INFO "软件包未安装,标记为未安装状态"
|
||||
INSTALLED=0
|
||||
fi
|
||||
|
||||
if [ $INSTALLED -eq 0 ]; then
|
||||
LOG_INFO "3. 安装python3-pydocstyle和pydocstyle软件包"
|
||||
dnf install -y python3-pydocstyle pydocstyle
|
||||
CHECK_RESULT $? 0 0 "安装python3-pydocstyle和pydocstyle失败"
|
||||
fi
|
||||
|
||||
LOG_INFO "4. 检查pydocstyle命令是否支持--explain参数"
|
||||
pydocstyle --help 2>&1 | grep -q -- "--explain"
|
||||
CHECK_RESULT $? 0 0 "pydocstyle命令不支持--explain参数"
|
||||
|
||||
LOG_INFO "5. 创建一个存在文档风格问题的Python测试文件"
|
||||
cat > test_docstring.py << "EOF"
|
||||
def bad_function():
|
||||
"""没有空行的文档字符串"""
|
||||
pass
|
||||
|
||||
class BadClass:
|
||||
"""类文档字符串缺少空行"""
|
||||
def method(self):
|
||||
"""方法文档字符串缺少空行"""
|
||||
pass
|
||||
EOF
|
||||
|
||||
LOG_INFO "6. 使用pydocstyle --explain测试显示每个错误的解释"
|
||||
pydocstyle --explain test_docstring.py
|
||||
CHECK_RESULT $? 0 0 "pydocstyle --explain执行失败"
|
||||
|
||||
LOG_INFO "7. 清理测试文件"
|
||||
rm -f test_docstring.py
|
||||
|
||||
if [ $INSTALLED -eq 0 ]; then
|
||||
LOG_INFO "8. 卸载测试安装的软件包"
|
||||
dnf remove -y python3-pydocstyle pydocstyle
|
||||
CHECK_RESULT $? 0 0 "卸载python3-pydocstyle和pydocstyle失败"
|
||||
fi
|
||||
|
||||
LOG_INFO "测试完成"
|
||||
}
|
||||
|
||||
main "$@"
|
||||
@@ -1,74 +0,0 @@
|
||||
#!/usr/bin/bash
|
||||
|
||||
# Copyright (c) 2024 ISCAS .ALL rights reserved.
|
||||
# This program is licensed under Mulan PSL v2.
|
||||
# You can use it according to the terms and conditions of the Mulan PSL v2.
|
||||
# http://license.coscl.org.cn/MulanPSL2
|
||||
# THIS PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
# EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
# MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
# See the Mulan PSL v2 for more details.
|
||||
|
||||
# #############################################
|
||||
# @Author : honghua
|
||||
# @Contact : honghua@iscas.ac.cn
|
||||
# @Date : 2026-03-03
|
||||
# @License : Mulan PSL v2
|
||||
# @Desc : 测试显示帮助信息
|
||||
# ############################################
|
||||
|
||||
source "$OET_PATH/libs/locallibs/common_lib.sh"
|
||||
|
||||
function run_test() {
|
||||
LOG_INFO "开始测试:测试显示帮助信息"
|
||||
LOG_INFO "检查环境是否已安装python3-pydocstyle和pydocstyle软件包"
|
||||
|
||||
# 检查是否已安装python3-pydocstyle和pydocstyle
|
||||
if dnf list installed python3-pydocstyle &> /dev/null && dnf list installed pydocstyle &> /dev/null; then
|
||||
LOG_INFO "环境已安装python3-pydocstyle和pydocstyle软件包"
|
||||
INSTALLED=true
|
||||
else
|
||||
LOG_INFO "环境未安装python3-pydocstyle和pydocstyle软件包"
|
||||
INSTALLED=false
|
||||
fi
|
||||
|
||||
# 检查yum源中是否有python3-pydocstyle和pydocstyle软件包
|
||||
LOG_INFO "检查yum源中是否有python3-pydocstyle和pydocstyle软件包"
|
||||
if ! dnf list available python3-pydocstyle &> /dev/null; then
|
||||
LOG_ERROR "yum源中未找到python3-pydocstyle软件包"
|
||||
exit 255
|
||||
fi
|
||||
if ! dnf list available pydocstyle &> /dev/null; then
|
||||
LOG_ERROR "yum源中未找到pydocstyle软件包"
|
||||
exit 255
|
||||
fi
|
||||
|
||||
# 如果未安装,则安装软件包
|
||||
if [ "$INSTALLED" = false ]; then
|
||||
LOG_INFO "安装python3-pydocstyle和pydocstyle软件包"
|
||||
dnf install -y python3-pydocstyle pydocstyle
|
||||
CHECK_RESULT $? 0 0 "安装python3-pydocstyle和pydocstyle软件包失败"
|
||||
fi
|
||||
|
||||
# 测试显示帮助信息
|
||||
LOG_INFO "测试pydocstyle命令的-h参数显示帮助信息"
|
||||
pydocstyle -h
|
||||
CHECK_RESULT $? 0 0 "pydocstyle -h命令执行失败"
|
||||
|
||||
LOG_INFO "测试pydocstyle命令的--help参数显示帮助信息"
|
||||
pydocstyle --help
|
||||
CHECK_RESULT $? 0 0 "pydocstyle --help命令执行失败"
|
||||
|
||||
# 清理环境:如果之前未安装,则卸载软件包
|
||||
if [ "$INSTALLED" = false ]; then
|
||||
LOG_INFO "卸载python3-pydocstyle和pydocstyle软件包"
|
||||
dnf remove -y python3-pydocstyle pydocstyle
|
||||
CHECK_RESULT $? 0 0 "卸载python3-pydocstyle和pydocstyle软件包失败"
|
||||
else
|
||||
LOG_INFO "保持环境安装状态,不卸载软件包"
|
||||
fi
|
||||
|
||||
LOG_INFO "测试完成:测试显示帮助信息"
|
||||
}
|
||||
|
||||
main "$@"
|
||||
@@ -1,85 +0,0 @@
|
||||
#!/usr/bin/bash
|
||||
|
||||
# Copyright (c) 2024 ISCAS .ALL rights reserved.
|
||||
# This program is licensed under Mulan PSL v2.
|
||||
# You can use it according to the terms and conditions of the Mulan PSL v2.
|
||||
# http://license.coscl.org.cn/MulanPSL2
|
||||
# THIS PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
# EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
# MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
# See the Mulan PSL v2 for more details.
|
||||
|
||||
# #############################################
|
||||
# @Author : honghua
|
||||
# @Contact : honghua@iscas.ac.cn
|
||||
# @Date : 2026-03-03
|
||||
# @License : Mulan PSL v2
|
||||
# @Desc : 测试显示帮助信息
|
||||
# ############################################
|
||||
|
||||
source "$OET_PATH/libs/locallibs/common_lib.sh"
|
||||
|
||||
function run_test() {
|
||||
# 定义测试函数
|
||||
test_python3-pydocstyle_pydocstyle__help() {
|
||||
# 步骤1:检查测试环境是否已安装python3-pydocstyle
|
||||
LOG_INFO "步骤1:检查测试环境是否已安装python3-pydocstyle"
|
||||
rpm -q python3-pydocstyle > /dev/null 2>&1
|
||||
local installed=$?
|
||||
local need_cleanup=0
|
||||
|
||||
# 步骤2:检查yum源中是否有python3-pydocstyle软件包
|
||||
LOG_INFO "步骤2:检查yum源中是否有python3-pydocstyle软件包"
|
||||
dnf list available python3-pydocstyle > /dev/null 2>&1
|
||||
if [ $? -ne 0 ]; then
|
||||
LOG_ERROR "yum源中没有python3-pydocstyle软件包"
|
||||
exit 255
|
||||
fi
|
||||
|
||||
# 步骤3:如果未安装则安装软件包
|
||||
if [ $installed -ne 0 ]; then
|
||||
LOG_INFO "步骤3:安装python3-pydocstyle软件包"
|
||||
dnf install -y python3-pydocstyle
|
||||
CHECK_RESULT $? 0 0 "安装python3-pydocstyle失败"
|
||||
need_cleanup=1
|
||||
else
|
||||
LOG_INFO "步骤3:python3-pydocstyle已安装,跳过安装步骤"
|
||||
fi
|
||||
|
||||
# 步骤4:测试pydocstyle --help命令
|
||||
LOG_INFO "步骤4:测试pydocstyle --help命令"
|
||||
pydocstyle --help > /dev/null 2>&1
|
||||
if [ $? -eq 255 ]; then
|
||||
LOG_ERROR "pydocstyle不支持--help参数"
|
||||
# 清理环境
|
||||
if [ $need_cleanup -eq 1 ]; then
|
||||
LOG_INFO "清理环境:卸载python3-pydocstyle"
|
||||
dnf remove -y python3-pydocstyle
|
||||
fi
|
||||
exit 255
|
||||
fi
|
||||
CHECK_RESULT $? 0 0 "执行pydocstyle --help失败"
|
||||
|
||||
# 步骤5:验证帮助信息包含关键内容
|
||||
LOG_INFO "步骤5:验证帮助信息包含关键内容"
|
||||
pydocstyle --help 2>&1 | grep -q "usage:"
|
||||
CHECK_RESULT $? 0 0 "帮助信息不包含"usage:"关键字"
|
||||
|
||||
# 步骤6:清理环境
|
||||
LOG_INFO "步骤6:清理环境"
|
||||
if [ $need_cleanup -eq 1 ]; then
|
||||
LOG_INFO "卸载python3-pydocstyle软件包"
|
||||
dnf remove -y python3-pydocstyle
|
||||
CHECK_RESULT $? 0 0 "卸载python3-pydocstyle失败"
|
||||
else
|
||||
LOG_INFO "保持python3-pydocstyle安装状态"
|
||||
fi
|
||||
|
||||
LOG_INFO "测试完成:成功测试pydocstyle --help命令"
|
||||
}
|
||||
|
||||
# 执行测试
|
||||
test_python3-pydocstyle_pydocstyle__help
|
||||
}
|
||||
|
||||
main "$@"
|
||||
@@ -1,96 +0,0 @@
|
||||
#!/usr/bin/bash
|
||||
|
||||
# Copyright (c) 2024 ISCAS .ALL rights reserved.
|
||||
# This program is licensed under Mulan PSL v2.
|
||||
# You can use it according to the terms and conditions of the Mulan PSL v2.
|
||||
# http://license.coscl.org.cn/MulanPSL2
|
||||
# THIS PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
# EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
# MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
# See the Mulan PSL v2 for more details.
|
||||
|
||||
# #############################################
|
||||
# @Author : honghua
|
||||
# @Contact : honghua@iscas.ac.cn
|
||||
# @Date : 2026-03-03
|
||||
# @License : Mulan PSL v2
|
||||
# @Desc : 测试显示每个错误的源代码
|
||||
# ############################################
|
||||
|
||||
source "$OET_PATH/libs/locallibs/common_lib.sh"
|
||||
|
||||
function run_test() {
|
||||
LOG_INFO "开始测试:测试显示每个错误的源代码"
|
||||
|
||||
# 检查是否已安装pydocstyle软件包
|
||||
LOG_INFO "步骤1:检查pydocstyle软件包是否已安装"
|
||||
if dnf list installed python3-pydocstyle &>/dev/null; then
|
||||
LOG_INFO "pydocstyle软件包已安装,测试后保持安装状态"
|
||||
already_installed=true
|
||||
else
|
||||
LOG_INFO "pydocstyle软件包未安装,将在测试过程中安装"
|
||||
already_installed=false
|
||||
fi
|
||||
|
||||
# 检查yum源中是否有pydocstyle软件包
|
||||
LOG_INFO "步骤2:检查yum源中是否有pydocstyle软件包"
|
||||
if ! dnf list available python3-pydocstyle &>/dev/null; then
|
||||
LOG_ERROR "yum源中未找到pydocstyle软件包"
|
||||
exit 255
|
||||
fi
|
||||
|
||||
# 安装pydocstyle软件包(如果未安装)
|
||||
if [ "$already_installed" = false ]; then
|
||||
LOG_INFO "步骤3:安装pydocstyle软件包"
|
||||
dnf install -y python3-pydocstyle
|
||||
CHECK_RESULT $? 0 0 "安装pydocstyle软件包失败"
|
||||
fi
|
||||
|
||||
# 检查pydocstyle命令是否支持--show-source参数
|
||||
LOG_INFO "步骤4:检查pydocstyle命令是否支持--show-source参数"
|
||||
if ! pydocstyle --help | grep -q -- "--show-source"; then
|
||||
LOG_ERROR "pydocstyle命令不支持--show-source参数"
|
||||
if [ "$already_installed" = false ]; then
|
||||
LOG_INFO "清理环境:卸载pydocstyle软件包"
|
||||
dnf remove -y python3-pydocstyle
|
||||
fi
|
||||
exit 255
|
||||
fi
|
||||
|
||||
# 创建测试用的Python文件,包含文档字符串错误
|
||||
LOG_INFO "步骤5:创建测试用的Python文件"
|
||||
cat > /tmp/test_file.py << "EOF"
|
||||
"""测试文件,包含文档字符串错误"""
|
||||
|
||||
def bad_function():
|
||||
"""这个函数缺少参数和返回值的文档字符串"""
|
||||
pass
|
||||
|
||||
def another_bad_function(param):
|
||||
"""这个函数的文档字符串格式不正确
|
||||
"""
|
||||
return param
|
||||
EOF
|
||||
|
||||
# 使用pydocstyle检查Python文件,并显示每个错误的源代码
|
||||
LOG_INFO "步骤6:使用pydocstyle检查Python文件,并显示每个错误的源代码"
|
||||
pydocstyle --show-source /tmp/test_file.py
|
||||
CHECK_RESULT $? 0 1 "pydocstyle检查失败或未发现错误" # pydocstyle发现错误时返回非零值,这里期望发现错误
|
||||
|
||||
# 清理测试文件
|
||||
LOG_INFO "步骤7:清理测试文件"
|
||||
rm -f /tmp/test_file.py
|
||||
|
||||
# 如果测试前未安装pydocstyle,则在测试后卸载
|
||||
if [ "$already_installed" = false ]; then
|
||||
LOG_INFO "步骤8:卸载pydocstyle软件包"
|
||||
dnf remove -y python3-pydocstyle
|
||||
CHECK_RESULT $? 0 0 "卸载pydocstyle软件包失败"
|
||||
else
|
||||
LOG_INFO "pydocstyle软件包在测试前已安装,保持安装状态"
|
||||
fi
|
||||
|
||||
LOG_INFO "测试完成:测试显示每个错误的源代码"
|
||||
}
|
||||
|
||||
main "$@"
|
||||
@@ -1,108 +0,0 @@
|
||||
#!/usr/bin/bash
|
||||
|
||||
# Copyright (c) 2024 ISCAS .ALL rights reserved.
|
||||
# This program is licensed under Mulan PSL v2.
|
||||
# You can use it according to the terms and conditions of the Mulan PSL v2.
|
||||
# http://license.coscl.org.cn/MulanPSL2
|
||||
# THIS PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
# EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
# MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
# See the Mulan PSL v2 for more details.
|
||||
|
||||
# #############################################
|
||||
# @Author : honghua
|
||||
# @Contact : honghua@iscas.ac.cn
|
||||
# @Date : 2026-03-03
|
||||
# @License : Mulan PSL v2
|
||||
# @Desc : 测试显示每个错误的源代码
|
||||
# ############################################
|
||||
|
||||
source "$OET_PATH/libs/locallibs/common_lib.sh"
|
||||
|
||||
function run_test() {
|
||||
LOG_INFO "开始测试:测试显示每个错误的源代码"
|
||||
|
||||
# 检查软件包是否在yum源中
|
||||
LOG_INFO "检查python3-pydocstyle软件包是否在yum源中"
|
||||
dnf list python3-pydocstyle 2>/dev/null | grep -q python3-pydocstyle
|
||||
if [ $? -ne 0 ]; then
|
||||
LOG_ERROR "yum源中未找到python3-pydocstyle软件包"
|
||||
exit 255
|
||||
fi
|
||||
|
||||
# 检查是否已安装软件包
|
||||
LOG_INFO "检查python3-pydocstyle是否已安装"
|
||||
rpm -q python3-pydocstyle >/dev/null 2>&1
|
||||
INSTALLED=$?
|
||||
|
||||
if [ $INSTALLED -eq 0 ]; then
|
||||
LOG_INFO "python3-pydocstyle已安装,测试结束后将保持安装状态"
|
||||
NEED_UNINSTALL=0
|
||||
else
|
||||
LOG_INFO "python3-pydocstyle未安装,将进行安装"
|
||||
NEED_UNINSTALL=1
|
||||
|
||||
# 安装软件包
|
||||
LOG_INFO "安装python3-pydocstyle软件包"
|
||||
dnf install -y python3-pydocstyle
|
||||
CHECK_RESULT $? 0 0 "安装python3-pydocstyle失败"
|
||||
fi
|
||||
|
||||
# 检查pydocstyle命令是否可用
|
||||
LOG_INFO "检查pydocstyle命令是否可用"
|
||||
which pydocstyle >/dev/null 2>&1
|
||||
CHECK_RESULT $? 0 0 "pydocstyle命令不可用"
|
||||
|
||||
# 测试pydocstyle的--source参数
|
||||
LOG_INFO "测试pydocstyle的--source参数"
|
||||
pydocstyle --help | grep -q -- "--source"
|
||||
if [ $? -ne 0 ]; then
|
||||
LOG_ERROR "pydocstyle不支持--source参数"
|
||||
# 清理环境
|
||||
if [ $NEED_UNINSTALL -eq 1 ]; then
|
||||
LOG_INFO "卸载python3-pydocstyle软件包"
|
||||
dnf remove -y python3-pydocstyle
|
||||
fi
|
||||
exit 255
|
||||
fi
|
||||
|
||||
# 创建测试Python文件
|
||||
LOG_INFO "创建测试Python文件"
|
||||
TEST_DIR=$(mktemp -d)
|
||||
TEST_FILE="${TEST_DIR}/test_module.py"
|
||||
cat > "${TEST_FILE}" << "EOF"
|
||||
"""测试模块的文档字符串"""
|
||||
|
||||
def test_function():
|
||||
"""测试函数的文档字符串"""
|
||||
print("Hello, World!")
|
||||
|
||||
class TestClass:
|
||||
"""测试类的文档字符串"""
|
||||
def test_method(self):
|
||||
"""测试方法的文档字符串"""
|
||||
pass
|
||||
EOF
|
||||
|
||||
# 测试显示每个错误的源代码
|
||||
LOG_INFO "执行pydocstyle --source命令测试"
|
||||
pydocstyle --source "${TEST_FILE}"
|
||||
CHECK_RESULT $? 0 0 "pydocstyle --source命令执行失败"
|
||||
|
||||
# 清理测试文件
|
||||
LOG_INFO "清理测试文件"
|
||||
rm -rf "${TEST_DIR}"
|
||||
|
||||
# 恢复环境
|
||||
if [ $NEED_UNINSTALL -eq 1 ]; then
|
||||
LOG_INFO "卸载python3-pydocstyle软件包"
|
||||
dnf remove -y python3-pydocstyle
|
||||
CHECK_RESULT $? 0 0 "卸载python3-pydocstyle失败"
|
||||
else
|
||||
LOG_INFO "保持python3-pydocstyle安装状态"
|
||||
fi
|
||||
|
||||
LOG_INFO "测试完成:测试显示每个错误的源代码"
|
||||
}
|
||||
|
||||
main "$@"
|
||||
@@ -1,102 +0,0 @@
|
||||
#!/usr/bin/bash
|
||||
|
||||
# Copyright (c) 2024 ISCAS .ALL rights reserved.
|
||||
# This program is licensed under Mulan PSL v2.
|
||||
# You can use it according to the terms and conditions of the Mulan PSL v2.
|
||||
# http://license.coscl.org.cn/MulanPSL2
|
||||
# THIS PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
# EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
# MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
# See the Mulan PSL v2 for more details.
|
||||
|
||||
# #############################################
|
||||
# @Author : honghua
|
||||
# @Contact : honghua@iscas.ac.cn
|
||||
# @Date : 2026-03-03
|
||||
# @License : Mulan PSL v2
|
||||
# @Desc : 测试打印状态信息
|
||||
# ############################################
|
||||
|
||||
source "$OET_PATH/libs/locallibs/common_lib.sh"
|
||||
|
||||
function run_test() {
|
||||
# 测试打印状态信息
|
||||
LOG_INFO "开始测试 pydocstyle 命令的打印状态信息功能"
|
||||
|
||||
# 检查是否已安装 pydocstyle
|
||||
LOG_INFO "检查 pydocstyle 是否已安装"
|
||||
if rpm -q python3-pydocstyle &> /dev/null; then
|
||||
LOG_INFO "pydocstyle 已安装,测试后将保持安装状态"
|
||||
already_installed=1
|
||||
else
|
||||
LOG_INFO "pydocstyle 未安装,将在测试中安装并在测试后卸载"
|
||||
already_installed=0
|
||||
fi
|
||||
|
||||
# 检查 yum 源中是否有该软件包
|
||||
LOG_INFO "检查 yum 源中是否有 python3-pydocstyle 软件包"
|
||||
if ! dnf list available python3-pydocstyle &> /dev/null; then
|
||||
LOG_ERROR "yum 源中未找到 python3-pydocstyle 软件包"
|
||||
exit 255
|
||||
fi
|
||||
|
||||
# 如果未安装,则安装软件包
|
||||
if [ ${already_installed} -eq 0 ]; then
|
||||
LOG_INFO "安装 python3-pydocstyle 软件包"
|
||||
dnf install -y python3-pydocstyle
|
||||
CHECK_RESULT $? 0 0 "安装 python3-pydocstyle 失败"
|
||||
fi
|
||||
|
||||
# 检查 pydocstyle 命令是否可用
|
||||
LOG_INFO "检查 pydocstyle 命令是否可用"
|
||||
if ! command -v pydocstyle &> /dev/null; then
|
||||
LOG_ERROR "pydocstyle 命令未找到"
|
||||
exit 255
|
||||
fi
|
||||
|
||||
# 测试 pydocstyle 的 --help 参数
|
||||
LOG_INFO "测试 pydocstyle --help 参数"
|
||||
pydocstyle --help
|
||||
CHECK_RESULT $? 0 0 "pydocstyle --help 执行失败"
|
||||
|
||||
# 测试 pydocstyle 的 --version 参数
|
||||
LOG_INFO "测试 pydocstyle --version 参数"
|
||||
pydocstyle --version
|
||||
CHECK_RESULT $? 0 0 "pydocstyle --version 执行失败"
|
||||
|
||||
# 测试不支持的参数
|
||||
LOG_INFO "测试 pydocstyle 不支持参数的情况"
|
||||
pydocstyle --invalid-param 2>&1 | grep -q "unrecognized arguments"
|
||||
CHECK_RESULT $? 0 0 "pydocstyle 不支持参数检查失败"
|
||||
|
||||
# 创建一个简单的 Python 文件用于测试
|
||||
LOG_INFO "创建测试用的 Python 文件"
|
||||
cat > /tmp/test_docstring.py << "EOF"
|
||||
"""This is a module docstring."""
|
||||
def example_function():
|
||||
"""This is a function docstring."""
|
||||
pass
|
||||
EOF
|
||||
|
||||
# 测试 pydocstyle 检查文档字符串
|
||||
LOG_INFO "测试 pydocstyle 检查文档字符串"
|
||||
pydocstyle /tmp/test_docstring.py
|
||||
CHECK_RESULT $? 0 0 "pydocstyle 检查文档字符串失败"
|
||||
|
||||
# 清理测试文件
|
||||
LOG_INFO "清理测试文件"
|
||||
rm -f /tmp/test_docstring.py
|
||||
|
||||
# 如果测试前未安装,则卸载软件包
|
||||
if [ ${already_installed} -eq 0 ]; then
|
||||
LOG_INFO "卸载 python3-pydocstyle 软件包"
|
||||
dnf remove -y python3-pydocstyle
|
||||
CHECK_RESULT $? 0 0 "卸载 python3-pydocstyle 失败"
|
||||
else
|
||||
LOG_INFO "保持 python3-pydocstyle 安装状态"
|
||||
fi
|
||||
|
||||
LOG_INFO "测试 pydocstyle 打印状态信息功能完成"
|
||||
}
|
||||
|
||||
main "$@"
|
||||
@@ -1,124 +0,0 @@
|
||||
#!/usr/bin/bash
|
||||
|
||||
# Copyright (c) 2024 ISCAS .ALL rights reserved.
|
||||
# This program is licensed under Mulan PSL v2.
|
||||
# You can use it according to the terms and conditions of the Mulan PSL v2.
|
||||
# http://license.coscl.org.cn/MulanPSL2
|
||||
# THIS PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
# EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
# MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
# See the Mulan PSL v2 for more details.
|
||||
|
||||
# #############################################
|
||||
# @Author : honghua
|
||||
# @Contact : honghua@iscas.ac.cn
|
||||
# @Date : 2026-03-03
|
||||
# @License : Mulan PSL v2
|
||||
# @Desc : 测试打印状态信息
|
||||
# ############################################
|
||||
|
||||
source "$OET_PATH/libs/locallibs/common_lib.sh"
|
||||
|
||||
function run_test() {
|
||||
# 测试脚本:测试打印状态信息
|
||||
|
||||
LOG_INFO "开始测试pydocstyle --verbose命令"
|
||||
|
||||
# 检查是否已安装python3-pydocstyle
|
||||
LOG_INFO "步骤1: 检查python3-pydocstyle是否已安装"
|
||||
if dnf list installed python3-pydocstyle &>/dev/null; then
|
||||
LOG_INFO "python3-pydocstyle已安装"
|
||||
INSTALLED_BEFORE_TEST=1
|
||||
else
|
||||
LOG_INFO "python3-pydocstyle未安装"
|
||||
INSTALLED_BEFORE_TEST=0
|
||||
fi
|
||||
|
||||
# 检查yum源中是否有python3-pydocstyle软件包
|
||||
LOG_INFO "步骤2: 检查yum源中是否有python3-pydocstyle软件包"
|
||||
if ! dnf list available python3-pydocstyle &>/dev/null; then
|
||||
LOG_ERROR "yum源中未找到python3-pydocstyle软件包"
|
||||
exit 255
|
||||
fi
|
||||
|
||||
# 如果未安装则安装软件包
|
||||
if [ ${INSTALLED_BEFORE_TEST} -eq 0 ]; then
|
||||
LOG_INFO "步骤3: 安装python3-pydocstyle软件包"
|
||||
dnf install -y python3-pydocstyle
|
||||
CHECK_RESULT $? 0 0 "安装python3-pydocstyle失败"
|
||||
fi
|
||||
|
||||
# 检查pydocstyle命令是否存在
|
||||
LOG_INFO "步骤4: 检查pydocstyle命令是否存在"
|
||||
if ! command -v pydocstyle &>/dev/null; then
|
||||
LOG_ERROR "pydocstyle命令不存在"
|
||||
if [ ${INSTALLED_BEFORE_TEST} -eq 0 ]; then
|
||||
LOG_INFO "清理环境:卸载python3-pydocstyle"
|
||||
dnf remove -y python3-pydocstyle
|
||||
fi
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# 检查--verbose参数是否支持
|
||||
LOG_INFO "步骤5: 检查--verbose参数是否支持"
|
||||
pydocstyle --help 2>&1 | grep -q "\-\-verbose"
|
||||
CHECK_RESULT $? 0 0 "--verbose参数不支持"
|
||||
if [ $? -ne 0 ]; then
|
||||
LOG_ERROR "--verbose参数不存在或不支持"
|
||||
if [ ${INSTALLED_BEFORE_TEST} -eq 0 ]; then
|
||||
LOG_INFO "清理环境:卸载python3-pydocstyle"
|
||||
dnf remove -y python3-pydocstyle
|
||||
fi
|
||||
exit 255
|
||||
fi
|
||||
|
||||
# 测试pydocstyle --verbose命令
|
||||
LOG_INFO "步骤6: 执行pydocstyle --verbose命令测试"
|
||||
pydocstyle --verbose --version
|
||||
CHECK_RESULT $? 0 0 "执行pydocstyle --verbose失败"
|
||||
|
||||
# 测试pydocstyle --verbose检查当前目录
|
||||
LOG_INFO "步骤7: 测试pydocstyle --verbose检查当前目录"
|
||||
pydocstyle --verbose .
|
||||
CHECK_RESULT $? 0 0 "pydocstyle --verbose检查当前目录失败"
|
||||
|
||||
# 创建一个简单的Python文件用于测试
|
||||
LOG_INFO "步骤8: 创建测试Python文件"
|
||||
cat > test_pydocstyle.py << "EOF"
|
||||
"""测试模块的文档字符串"""
|
||||
|
||||
def test_function():
|
||||
"""测试函数的文档字符串"""
|
||||
return "Hello World"
|
||||
|
||||
class TestClass:
|
||||
"""测试类的文档字符串"""
|
||||
|
||||
def method(self):
|
||||
"""测试方法的文档字符串"""
|
||||
return "Test"
|
||||
EOF
|
||||
|
||||
# 测试pydocstyle --verbose检查测试文件
|
||||
LOG_INFO "步骤9: 测试pydocstyle --verbose检查测试文件"
|
||||
pydocstyle --verbose test_pydocstyle.py
|
||||
CHECK_RESULT $? 0 0 "pydocstyle --verbose检查测试文件失败"
|
||||
|
||||
# 清理测试文件
|
||||
LOG_INFO "步骤10: 清理测试文件"
|
||||
rm -f test_pydocstyle.py
|
||||
|
||||
# 环境恢复
|
||||
LOG_INFO "步骤11: 恢复测试环境"
|
||||
if [ ${INSTALLED_BEFORE_TEST} -eq 0 ]; then
|
||||
LOG_INFO "卸载python3-pydocstyle软件包"
|
||||
dnf remove -y python3-pydocstyle
|
||||
CHECK_RESULT $? 0 0 "卸载python3-pydocstyle失败"
|
||||
else
|
||||
LOG_INFO "保持python3-pydocstyle安装状态"
|
||||
fi
|
||||
|
||||
LOG_INFO "测试完成:pydocstyle --verbose命令测试成功"
|
||||
}
|
||||
|
||||
main "$@"
|
||||
Reference in New Issue
Block a user