python3 文档测试
来源:互联网 发布:你瞒我瞒网络链接 编辑:程序博客网 时间:2024/06/03 16:53
在python交互命令行里面,最后加上 -v 会显示的更加全面
python3 test3.py -v
class Dict(dict): ''' Simple dict but also support access as x.y style. >>> d1 = Dict() >>> d1['x'] = 100 >>> d1.x 100 >>> d1.y = 200 >>> d1['y'] 200 >>> d2 = Dict(a=1, b=2, c='3') >>> d2.c '3' >>> d2['empty'] Traceback (most recent call last): ... KeyError: 'empty' >>> d2.empty Traceback (most recent call last): ... AttributeError: 'Dict' object has no attribute 'empty' ''' def __init__(self, **kw): super(Dict, self).__init__(**kw) def __getattr__(self, key): try: return self[key] except KeyError: raise AttributeError(r"'Dict' object has no attribute '%s'" % key) def __setattr__(self, key, value): self[key] = valueif __name__=='__main__': import doctest doctest.testmod()
显示结果
wulimindeMacBook-Pro:Python wulimin$ python3 test3.py -vTrying: d1 = Dict()Expecting nothingokTrying: d1['x'] = 100Expecting nothingokTrying: d1.xExpecting: 100okTrying: d1.y = 200Expecting nothingokTrying: d1['y']Expecting: 200okTrying: d2 = Dict(a=1, b=2, c='3')Expecting nothingokTrying: d2.cExpecting: '3'okTrying: d2['empty']Expecting: Traceback (most recent call last): ... KeyError: 'empty'okTrying: d2.emptyExpecting: Traceback (most recent call last): ... AttributeError: 'Dict' object has no attribute 'empty'ok4 items had no tests: __main__ __main__.Dict.__getattr__ __main__.Dict.__init__ __main__.Dict.__setattr__1 items passed all tests: 9 tests in __main__.Dict9 tests in 5 items.9 passed and 0 failed.Test passed.
0 0
- python3 文档测试
- python3 读取execle文档
- Python3 pexpect自动化测试
- 测试文档
- 测试文档
- 测试文档
- 测试文档
- 测试文档
- 测试文档
- 文档测试
- 文档测试
- 文档测试
- 文档测试
- 测试文档
- 文档测试
- 文档测试
- 测试,文档
- 文档测试
- 不用加减乘除做加法
- 水仙花数 (sdut oj)
- Cocoa 禁止APP多重启动
- FJOI2017 滚蛋记
- Android中的Service与进程间通信(IPC)详解
- python3 文档测试
- PHP的一些天坑
- addShutdownHook
- ThreadPoolExecutor机制(一)--基本介绍
- C语言贪吃蛇。
- SpringMVC之HandlerMethodArgumentResolver和<mvc:argument-resolvers>
- KiCad设计PCB-14-CAN通信与USB通信接口电路设计
- Bshare分享的常见用法
- squid日志处理(天)