python包装器,用于在没有cmake构建系统的情况下生成ctest并提交给cdash
pyctest的Python项目详细描述
Pyctest
Travis | AppVeyor |
---|---|
PyCTest Documentation (readthedocs)
吉特枢纽
git clone https://github.com/jrmadsen/pyctest.git
PYPI
pip install pyctest
水蟒云
conda install -c jrmadsen pyctest
Name | Version | Platforms | Downloads |
---|---|---|---|
康达锻造厂
conda install -c conda-forge pyctest
Name | Version | Platforms | Downloads |
---|---|---|---|
优点
- 集成到持续集成系统(如Travis、Appveyor、Circleci等)并推送到CDash Dashboard将把所有结果合并到一个地方
- 警告和错误在cdash中枚举(不再为错误解析stdout日志)
- 轻松创建独立于平台的测试
- 无需将生成系统迁移到CMake——只需指定
pyctest.BUILD_COMMAND
一般设置
- 将PyCTest添加到conda环境:
conda install pyctest
- 在源代码树的顶部编写驱动程序python脚本,例如
pyctest-runner.py
python项目的示例
下面是使用nosetests
进行单元测试的具有已编译C扩展名的Python代码的示例:
#!/usr/bin/env pythonimportos,sys,platformimportpyctest.pyctestaspyctestimportpyctest.helpersashelpersparser=helpers.ArgumentParser("ProjectName",source_dir=os.getcwd(),binary_dir=os.getcwd(),vcs_type="git")args=parser.parse_args()pyctest.BUILD_NAME="{}".format(args.build)pyctest.BUILD_COMMAND="python setup.py build_ext --inplace"test=pyctest.test()test.SetName("unittest")# insert the command to run the tests for projecttest.SetCommand(["nosetests"])pyctest.run()
Autotools项目的示例
#!/usr/bin/env pythonimportos,sys,platformimportmultiprocessingasmpimportpyctest.pyctestaspyctestimportpyctest.helpersashelpersparser=helpers.ArgumentParser("ProjectName",source_dir=os.getcwd(),binary_dir=os.getcwd(),vcs_type="git")parser.add_argument("-n","--build",type=str,required=True,help="Build name for identification")args=parser.parse_args()# CONFIGURE_COMMAND can only run one command so if autogen is required, just execute it herecmd=pyctest.command(["./autogen.sh"])cmd.SetWorkingDirectory(pyctest.SOURCE_DIRECTORY)cmd.SetErrorQuiet(False)cmd.Execute()pyctest.BUILD_NAME="{}".format(args.build)pyctest.CONFIGURE_COMMAND="./configure"pyctest.BUILD_COMMAND="make -j{}".format(mp.cpu_count())test=pyctest.test()test.SetName("unittest")# insert the command to run the tests for projecttest.SetCommand(["./run-testing.sh"])pyctest.run()
CMake项目示例
#!/usr/bin/env pythonimportosimportsysimportplatformimportmultiprocessingasmpimportpyctest.pyctestaspyctestimportpyctest.helpersashelpersbinary_dir=os.path.join(os.getcwd(),"build-ProjectName")parser=helpers.ArgumentParser("ProjectName",os.getcwd(),binary_dir)parser.add_argument("-n","--build",type=str,required=True,help="Build name for identification")args=parser.parse_args()pyctest.BUILD_NAME="{}".format(args.build)pyctest.UPDATE_COMMAND="git"pyctest.CONFIGURE_COMMAND="cmake {}".format(pyctest.SOURCE_DIRECTORY)pyctest.BUILD_COMMAND="cmake --build {} --target all -- -j{}".format(pyctest.BINARY_DIRECTORY,mp.cpu_count())test=pyctest.test()test.SetName("unittest")# insert the command to run the tests for projecttest.SetCommand(["./run-testing.sh"])pyctest.run()
Python模块
import pyctest
——全局包import pyctest.pyctest
——ctest模块import pyctest.pycmake
——cmake模块import pyctest.helpers
——Helpers模块- 包括pyctest的命令行参数(
argparse
)
- 包括pyctest的命令行参数(
直接访问CMake/CTest/CPack可执行文件
python -m pyctest.cmake <ARGS>
==cmake <ARGS>
python -m pyctest.ctest <ARGS>
=ctest <ARGS>
python -m pyctest.cpack <ARGS>
==cpack <ARGS>
遵循python代码:
frompyctest.ctestimportCTestfrompyctest.cmakeimportCMakefrompyctest.cpackimportCPackCMake({"CMAKE_BUILD_TYPE":"Release"},os.getcwd(),"-G","Ninja")CTest("--build-and-test",os.getcwd(),"-VV")CPack("-G","TGZ")
相当于以下shell命令:
$ cmake -DCMAKE_BUILD_TYPE=Release ${PWD} -G Ninja $ ctest --build-and-test ${PWD} -VV $ cpack -G TGZ
标准配置变量
pyctest.PROJECT_NAME
pyctest.SOURCE_DIRECTORY
pyctest.BINARY_DIRECTORY
pyctest.SITE
pyctest.BUILD_NAME
pyctest.TRIGGER
pyctest.CHECKOUT_COMMAND
pyctest.BUILD_COMMAND
pyctest.MODEL
pyctest.CUSTOM_COVERAGE_EXCLUDE
pyctest.CUSTOM_MAXIMUM_NUMBER_OF_ERRORS
pyctest.CUSTOM_MAXIMUM_NUMBER_OF_WARNINGS
pyctest.CUSTOM_MAXIMUM_PASSED_TEST_OUTPUT_SIZE
设置任意变量
pyctest.set("CTEST_TOKEN_FILE","${CMAKE_CURRENT_LIST_DIR}/.ctest-token")
生成测试
test=pyctest.test()test.SetName("nosetests")test.SetCommand(["nosetests","test","--cover-xml","--cover-xml-file=coverage.xml"])# set directory to run testtest.SetProperty("WORKING_DIRECTORY",pyctest.BINARY_DIRECTORY)test.SetProperty("RUN_SERIAL","ON")test.SetProperty("ENVIRONMENT","OMP_NUM_THREADS=1")
示例
- Basic example
- Advanced example
- 包括提交到CDash仪表板
CDash集成示例
运行TomoPy示例的结果可以在TomoPy CDash Testing Dashboard @ NERSC
- 不带cmake构建系统的c扩展的python代码
- “python setup.py install”中的生成日志在“build”部分中注册
nosetests test
命令+其他命令被包装成ctest
测试示例
PyCTest可用于简单地执行测试并提交到仪表板,而无需任何配置、构建等步骤
#!/usr/bin/env pythonimportosimportsysimportshutilimportargparseimportplatformimporttracebackimportpyctest.pyctestaspyctestimportpyctest.pycmakeaspycmakeimportpyctest.helpersashelpersif__name__=="__main__":directory=os.path.join(os.getcwd(),"pycm-test")# these are requiredpyctest.PROJECT_NAME="PyCTest"pyctest.SOURCE_DIRECTORY=directorypyctest.BINARY_DIRECTORY=directoryargs=helpers.ArgumentParser(pyctest.PROJECT_NAME,pyctest.SOURCE_DIRECTORY,pyctest.BINARY_DIRECTORY).parse_args()# set explicitlypyctest.MODEL="Continuous"pyctest.SITE=platform.node()# create a Test objecttest=pyctest.test()test.SetName("list_directory")test.SetCommand(["ls",directory])test.SetProperty("WORKING_DIRECTORY",os.getcwd())# create a second test# previous test is already stored by PyCTesttest=pyctest.test()test.SetName("hostname")test.SetCommand(["hostname"])test.SetProperty("TIMEOUT","10")# generate the CTestConfig.cmake and CTestCustom.cmakepyctest.generate_config(directory)# generate the CTestTestfile.cmake filepyctest.generate_test_file(directory)# run CTest -- e.g. ctest -VV ${PWD}/pycm-testpyctest.run(pyctest.ARGUMENTS,directory)
CTest arguments (default): '-V -DSTAGES=Start;Update;Configure;Build;Test;Coverage;MemCheck -S Stages.cmake -j1' Writing CTest test file: "/Users/jrmadsen/devel/c++/pyctest-master/pycm-test/CTestTestfile.cmake"... Generating test"list_directory"... Generating test"hostname"... -- STAGES= Start;Update;Configure;Build;Test;Coverage;MemCheck -- [[Darwin macOS 10.13.6 x86_64][Python 3.6.7]] Running CTEST_START stage... Run dashboard with model Continuous Source directory: /Users/jrmadsen/devel/c++/pyctest-master/pycm-test Build directory: /Users/jrmadsen/devel/c++/pyctest-master/pycm-test Track: Continuous Reading ctest configuration file: /Users/jrmadsen/devel/c++/pyctest-master/pycm-test/CTestConfig.cmake Site: JRM-macOS-DOE.local Build name: [Darwin macOS 10.13.6 x86_64][Python 3.6.7] Use Continuous tag: 20181129-2118 -- [[Darwin macOS 10.13.6 x86_64][Python 3.6.7]] Skipping CTEST_UPDATE stage... -- [[Darwin macOS 10.13.6 x86_64][Python 3.6.7]] Skipping CTEST_CONFIGURE stage... -- [[Darwin macOS 10.13.6 x86_64][Python 3.6.7]] Skipping CTEST_BUILD stage... -- [[Darwin macOS 10.13.6 x86_64][Python 3.6.7]] Running CTEST_TEST stage... Test project /Users/jrmadsen/devel/c++/pyctest-master/pycm-test Start 1: list_directory 1/2 Test #1: list_directory ................... Passed 0.00 sec Start 2: hostname 2/2 Test #2: hostname ......................... Passed 0.00 sec100% tests passed, 0 tests failed out of 2 Total Test time(real)=0.01 sec -- [[Darwin macOS 10.13.6 x86_64][Python 3.6.7]] Skipping CTEST_COVERAGE stage... -- [[Darwin macOS 10.13.6 x86_64][Python 3.6.7]] Skipping CTEST_MEMCHECK stage... -- [[Darwin macOS 10.13.6 x86_64][Python 3.6.7]] Skipping CTEST_SUBMIT stage... -- [[Darwin macOS 10.13.6 x86_64][Python 3.6.7]] Finished Continuous Stages (Start;Update;Configure;Build;Test;Coverage;MemCheck)
命令行界面
PyCTest args: ['--help'] CTest args: [] CMake args: [] usage: pyctest-runner.py [-h][-F][-S][-A][-j <INT>][-m <TYPE>][-b <NAME>][-i <PATH>][-o <PATH>][-M <TYPE>][-H <SITE>][-P <EXE>][-N <NAME>][-C <PATH> [<PATH> ...]][-L <LABEL> [<LABEL> ...]][-T [<TYPE> [<TYPE> ...]]][-fc <EXE>][-cc <EXE>][-cxx <EXE>][--pyctest-token <TOKEN>][--pyctest-token-file <FILE>][--pyctest-vcs-type <TYPE>][--pyctest-build-type <TYPE>][--pyctest-trigger <TYPE>][--pyctest-use-launchers <BOOL>][--pyctest-ctest-args [<ARG> [<ARG> ...]]][--pyctest-cdash-version <STR>][--pyctest-submit-retry-count <INT>][--pyctest-submit-retry-delay <INT>][--pyctest-curl-options <LIST>][--pyctest-drop-location <STR>][--pyctest-drop-method <STR>][--pyctest-drop-site <STR>][--pyctest-drop-site-password <STR>][--pyctest-drop-site-user <STR>][--pyctest-nightly-start-time <STR>][--pyctest-update-version-only] PyCTest argparse. Arguments after first '--' are passed directly to CTest, arguments after second '--' are passed directly to CMake optional arguments: -h, --help show this help message and exit -F, --pyctest-clean-first Remove standard PyCTest files and binary directory (if not source directory) -S, --pyctest-submit Enable submission to dashboard -A, --pyctest-append Append to last invocation of CTest -j <INT>, --pyctest-jobs <INT> number of concurrent jobs -m <TYPE>, --pyctest-mode <TYPE> Run specific stage. Choices: [Start,Update,Configure,Build,Test,Coverage,MemCheck,Submit,Stages] -b <NAME>, --pyctest-build-name <NAME> Build name for identification -i <PATH>, --pyctest-source-dir <PATH> Source directory -o <PATH>, --pyctest-binary-dir <PATH> Binary/build/working directory -M <TYPE>, --pyctest-model <TYPE> CTest submission model (track). Choices: [Nightly,Continuous,Experimental] -H <SITE>, --pyctest-site <SITE> CTest submission site -P <EXE>, --pyctest-python-exe <EXE> Python executable to use. This can be absolue, relative, or CMake path -N <NAME>, --pyctest-project-name <NAME> Name of project using PyCTest -C <PATH> [<PATH> ...], --pyctest-cleanup <PATH> [<PATH> ...] Remove standard PyCTest files and binary directory (if not source directory) and exit -L <LABEL> [<LABEL> ...], --pyctest-subproject-labels <LABEL> [<LABEL> ...] Add labels for subproject -T [<TYPE> [<TYPE> ...]], --pyctest-stages [<TYPE> [<TYPE> ...]] Run multiple stages. Choices: [Start,Update,Configure,Build,Test,Coverage,MemCheck,Submit] -fc <EXE>, --pyctest-fortran-compiler <EXE> Specify Fortan compiler (if needed) -cc <EXE>, --pyctest-c-compiler <EXE> Specify the C compiler (if needed) -cxx <EXE>, --pyctest-cxx-compiler <EXE> Specify C++ compiler (if needed) --pyctest-token <TOKEN> CTest site token for submission --pyctest-token-file <FILE> Path to file for CTest site token for submission --pyctest-vcs-type <TYPE> Set to enable revision ID discovery during the Update stage. Choices: [bzr,cvs,git,hg,p4,svn] --pyctest-build-type <TYPE> Specify CMAKE_BUILD_TYPE (if using CMake). Choices: [Release,RelWithDebInfo,Debug,MinSizeRel] --pyctest-trigger <TYPE> DEPRECATED --pyctest-use-launchers <BOOL> Enable launchers --pyctest-ctest-args [<ARG> [<ARG> ...]] CTest arguments --pyctest-cdash-version <STR> Set CTest variable: 'CTEST_CDASH_VERSION' --pyctest-submit-retry-count <INT> Set CTest variable: 'CTEST_SUBMIT_RETRY_COUNT' --pyctest-submit-retry-delay <INT> Set CTest variable: 'CTEST_SUBMIT_RETRY_DELAY' --pyctest-curl-options <LIST> Set CTest variable: 'CTEST_CURL_OPTIONS' --pyctest-drop-location <STR> Set CTest variable: 'CTEST_DROP_LOCATION' --pyctest-drop-method <STR> Set CTest variable: 'CTEST_DROP_METHOD' --pyctest-drop-site <STR> Set CTest variable: 'CTEST_DROP_SITE' --pyctest-drop-site-password <STR> Set CTest variable: 'CTEST_DROP_SITE_PASSWORD' --pyctest-drop-site-user <STR> Set CTest variable: 'CTEST_DROP_SITE_USER' --pyctest-nightly-start-time <STR> Set CTest variable: 'CTEST_NIGHTLY_START_TIME' --pyctest-update-version-only Specify that you want the version control update command to only discover the current version that is checked out, and not to update to a different version