doctest

python3: doctest helper/internal functions?

女生的网名这么多〃 提交于 2020-07-23 11:50:07
问题 How do I make the following work so that helpers's test is run? It doesen't. def B(): def helper(): """ >>> some doctest result """ ... if __name__ == "__main__": import doctest doctest.testmod() 回答1: Nested functions cannot be found, because the function object doesn't exist until the B() function is run. You'd have to return it as the result of calling the B() function, then assign it to the __test__ dictionary: def B() def helper() """ >>> some doctest result """ return helper # ... if _

python3: doctest helper/internal functions?

╄→尐↘猪︶ㄣ 提交于 2020-07-23 11:49:40
问题 How do I make the following work so that helpers's test is run? It doesen't. def B(): def helper(): """ >>> some doctest result """ ... if __name__ == "__main__": import doctest doctest.testmod() 回答1: Nested functions cannot be found, because the function object doesn't exist until the B() function is run. You'd have to return it as the result of calling the B() function, then assign it to the __test__ dictionary: def B() def helper() """ >>> some doctest result """ return helper # ... if _

Specify expected outcome in a docstring as hexadecimal?

a 夏天 提交于 2020-07-06 18:43:52
问题 Is there a way to specify expected integer outcomes in a docstring in hex notation? def identity(val): """ >>> identity(243) 243 >>> identity(243) 0xf3 """ return val if __name__ == "__main__": import doctest doctest.testmod() Doctest doesn't interpret the hex notation, resulting in a failure: ********************************************************************** File "hextest.py", line 5, in __main__.identity Failed example: identity(243) Expected: 0xf3 Got: 243 *****************************

Sphinx not removing doctest flags in html output

风流意气都作罢 提交于 2020-05-31 03:04:31
问题 I cannot eliminate the doctest flags (ie. <BLANKLINE> , # doctest: +ELLIPSIS ) for the html output. I am able to generate the documentation as I would like, so no errors there but it includes theses flags which I would like removed. Sphinx documentation here claims this is possible so I must be doing something wrong. My documentation examples are in numpy style and I have tried using both the napoleon and numpydoc extensions. Here are the steps I have taken. run sphinx-quickstart (enabling

python中错误、调试、单元测试、文档测试

本小妞迷上赌 提交于 2020-05-08 03:52:02
错误分为程序的错误和由用户错误的输入引起的错误,此外还有因为各种各样意外的情况导致的错误,比如在磁盘满的时候写入、从网络爬取东西的时候,网络断了。这类错误称为异常 错误处理    普通的错误处理机制就是在出错的时候返回一个错误代码,但是这样十分不方便,一是因为错误码是和正常结果一样的方式返回的,判断起来十分不方便,二是错误还需要一级一级的向上报,直到错误处理程序。 所以高级语言通常都内置了一套 try...except...finally... 的错误处理机制,Python也不例外。 try: A#如果A中的代码执行过程中出错,就会执行B中的代码 except ZeroDivisionError as e: B finally: C#C中的代码无论是否出错都会正常执行(可以不要这个)<br>。。。 如果错误有不同的类型,可以说使用多个except语句,每个语句处理一个类型的错误 另外,可以在except后面加一个else,如果没有出错,会执行else Python 的错误其实也是一个类,所有的异常类型都是从BaseException类派生的 except在捕获错误时,不但捕获该类型的错误,而且还会把子类一网打尽 try: foo() except ValueError as e: print('ValueError') except UnicodeError as e: print

适用于Mac电脑的Python开发工具哪款好用?

蹲街弑〆低调 提交于 2020-04-05 20:58:48
适用于Mac电脑的Python开发工具哪款好用?WingPro 7 Mac版好用吗?wingpro mac破解版是一款跨平台 Python IDE 系列通过强大的集成编辑,调试,单元测试和项目管理功能,使Python开发变得更加容易。Wing可在Windows,Linux和OS X上运行,可用于开发用于Web,桌面,科学,数据分析,嵌入式脚本和其他应用程序的任何类型的Python代码。 wingpro mac破解版功能介绍 强大的调试器 WingIDE Pro 6 for Mac 破解版的调试器可以轻松修复错误并以交互方式编写新代码。使用条件断点来隔离问题,然后逐步执行代码,检查数据,观察值,从Debug Probe的命令行进行交互,以及递归调试。您可以调试从IDE启动的多进程和多线程代码,托管在Web框架中,从嵌入式Python实例调用或在远程系统上调用。 智能编辑器 WingIDE Pro 6 for Mac 破解版的编辑器通过适合上下文的自动完成和文档,调用辅助,自动编辑,重构,代码折叠,多选,可自定义的内联代码片段,书签等来加速交互式Python开发。Wing可以模拟vi,emacs,Eclipse,Visual Studio和Xcode。 简单的代码导航 WingIDE Pro 6 for Mac 破解版通过goto-definition,查找用途,在项目中查找符号

ValueError: wrapper loop when unwrapping

血红的双手。 提交于 2020-02-23 10:22:42
问题 Python3 test cases (doctests) are failing with my sample code. But the same is working fine in Python2. test.py class Test(object): def __init__(self, a=0): self.a = a def __getattr__(self, attr): return Test(a=str(self.a) + attr) tst.py from test import Test t = Test() Run test cases: python3 -m doctest -v tst.py Error: Traceback (most recent call last): File "/usr/lib/python3.6/runpy.py", line 193, in _run_module_as_main "__main__", mod_spec) File "/usr/lib/python3.6/runpy.py", line 85, in

Doctest for nested docstring

喜欢而已 提交于 2020-01-23 06:17:22
问题 Suppose I have following code: def foo(s): """A dummy function foo. For example: >>> a = '''This is a test string line 1 This is a test string line 2 This is a test string line 3''' >>> foo(a) This is a test string line 1 This is a test string line 2 This is a test string line 3 >>> """ print s if __name__ == '__main__': import doctest doctest.testmod() And let's save it as foo.py. When I run: C:\Python27>python.exe foo.py **********************************************************************

Doctest for nested docstring

删除回忆录丶 提交于 2020-01-23 06:16:31
问题 Suppose I have following code: def foo(s): """A dummy function foo. For example: >>> a = '''This is a test string line 1 This is a test string line 2 This is a test string line 3''' >>> foo(a) This is a test string line 1 This is a test string line 2 This is a test string line 3 >>> """ print s if __name__ == '__main__': import doctest doctest.testmod() And let's save it as foo.py. When I run: C:\Python27>python.exe foo.py **********************************************************************

Are portable doctests for python 2 / python 3 possible?

你离开我真会死。 提交于 2020-01-13 08:25:29
问题 def fib_r(n, memo={0: 0, 1: 1}): """recursive fibonacci numbers generation with memoisation >>> [fib_r(n) for n in range(10)] [0, 1, 1, 2, 3, 5, 8, 13, 21, 34] >>> fib_r(100) 354224848179261915075""" if n not in memo: memo[n] = fib(n - 1) + fib(n - 2) return memo[n] The doctest above passes on python 3 but fails on 2.x like this: ********************************************************************** File "euler.py", line 93, in __main__.fib Failed example: fib_r(100) Expected: