用于测试软件库api相似性的集成测试框架。
doppel-cli的Python项目详细描述
doppel cli
doppel-cli
是一个集成测试框架,用于测试跨语言的api相似性。
保持相同的公共接口有什么价值?
此项目测试跨语言库中的API一致性
为什么这么值钱?
- 对于开发人员:
- 减少跨语言实现更改的通信开销
- 强制函数限制公共API 复杂性的增长
- 对于用户:
- 切换语言时无需重新学习API
- 在转换语言时形成更好的期望
文件
有关最新的文档,请参见https://doppel-cli.readthedocs.io/en/latest/。
入门
doppel-cli
可以像任何其他python包一样从源代码安装。
python setup.py install
您还可以从pypi安装,python的官方包管理器。为了避免与存储库上的现有项目相关联的冲突,它被分配为。
pip install doppel-cli
示例:测试r和python实现之间的连续性
在本例中,我将展示如何使用doppel
来测试同一api的r和python实现之间的连续性。在这个例子中,我使用了argparse
库。
注意:本例假设您已经在本地安装了argparse
。
如果不运行其中一个或两个:
Rscript -e "install.packages('argparse')" pip install argparse
首先,您需要生成doppel
用于存储有关项目api的信息的特殊文件。这些是使用doppel-describe
工具创建的。
PACKAGE=argparse # The R package doppel-describe \ -p ${PACKAGE} \ --language R \ --data-dir $(pwd)/test_data # The python package doppel-describe \ -p ${PACKAGE} \ --language python \ --data-dir $(pwd)/test_data
太酷了!让我们做些测试!doppel-test
可用于比较多个包。
doppel-test \ --files $(pwd)/test_data/python_${PACKAGE}.json,$(pwd)/test_data/r_${PACKAGE}.json \ | tee out.log \ | cat
这将产生如下结果:
Function Count ============== +---------------------+----------------+ | argparse [python] | argparse [r] | +=====================+================+ | 0 | 1 | +---------------------+----------------+ Function Names ============== +-----------------+---------------------+----------------+ | function_name | argparse [python] | argparse [r] | +=================+=====================+================+ | ArgumentParser | no | yes | +-----------------+---------------------+----------------+ Function Argument Names ======================= No shared functions. Class Count =========== +---------------------+----------------+ | argparse [python] | argparse [r] | +=====================+================+ | 9 | 0 | +---------------------+----------------+ Class Names =========== +-------------------------------+---------------------+----------------+ | class_name | argparse [python] | argparse [r] | +===============================+=====================+================+ | MetavarTypeHelpFormatter | yes | no | +-------------------------------+---------------------+----------------+ | ArgumentParser | yes | no | +-------------------------------+---------------------+----------------+ | FileType | yes | no | +-------------------------------+---------------------+----------------+ | HelpFormatter | yes | no | +-------------------------------+---------------------+----------------+ | RawDescriptionHelpFormatter | yes | no | +-------------------------------+---------------------+----------------+ | Action | yes | no | +-------------------------------+---------------------+----------------+ | ArgumentDefaultsHelpFormatter | yes | no | +-------------------------------+---------------------+----------------+ | Namespace | yes | no | +-------------------------------+---------------------+----------------+ | RawTextHelpFormatter | yes | no | +-------------------------------+---------------------+----------------+ Class Public Methods ==================== No shared classes. Arguments in Class Public Methods ================================= No shared classes. Test Failures (12) =================== 1. Function 'ngettext()' is not exported by all packages 2. Function 'ArgumentParser()' is not exported by all packages 3. Packages have different counts of exported classes! argparse [python] (9), argparse [r] (0) 4. Class 'HelpFormatter()' is not exported by all packages 5. Class 'Namespace()' is not exported by all packages 6. Class 'RawDescriptionHelpFormatter()' is not exported by all packages 7. Class 'ArgumentParser()' is not exported by all packages 8. Class 'MetavarTypeHelpFormatter()' is not exported by all packages 9. Class 'Action()' is not exported by all packages 10. Class 'ArgumentDefaultsHelpFormatter()' is not exported by all packages 11. Class 'FileType()' is not exported by all packages 12. Class 'RawTextHelpFormatter()' is not exported by all packages
如上所示,argparse
python包有9个导出类,而r包没有。
从doppel
的角度来看,这被视为测试失败。如果在终端中运行echo $?
,应该会看到1
打印出来。像这样返回一个非零的退出代码告诉CI工具,比如Travis,测试是一个失败,使得^ {CD3}}对CI很有用(在将来的例子中更多关于这个)。
你可能会想“好吧,等等,你肯定想测试更多的东西,而不仅仅是类和函数的计数,对吧?”完全正确!请参阅the project issues issues以获取我要添加的积压功能欢迎您的加入!!!
要了解有关当前可配置的内容的更多信息,您可以运行:
doppel-describe --help
以及
doppel-test --help
贡献
错误报告、问题和功能请求应该指向the issues page
有关如何贡献的信息,请参见CONTRIBUTING.md。