mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Fix doctest to work with Python 2.5 and lower
This commit is contained in:
@@ -50,23 +50,24 @@ Special directives
|
|||||||
|
|
||||||
.. testsetup:: *
|
.. testsetup:: *
|
||||||
|
|
||||||
from math import factorial
|
def squared(x):
|
||||||
|
return x * x
|
||||||
|
|
||||||
.. doctest::
|
.. doctest::
|
||||||
|
|
||||||
>>> factorial(1)
|
>>> squared(2)
|
||||||
1
|
4
|
||||||
|
|
||||||
.. testcode::
|
.. testcode::
|
||||||
|
|
||||||
print(factorial(1))
|
print(squared(2))
|
||||||
|
|
||||||
.. testoutput::
|
.. testoutput::
|
||||||
|
|
||||||
1
|
4
|
||||||
|
|
||||||
>>> factorial(1)
|
>>> squared(2)
|
||||||
1
|
4
|
||||||
|
|
||||||
* options for testcode/testoutput blocks
|
* options for testcode/testoutput blocks
|
||||||
|
|
||||||
@@ -85,36 +86,38 @@ Special directives
|
|||||||
|
|
||||||
.. testsetup:: group1
|
.. testsetup:: group1
|
||||||
|
|
||||||
from math import trunc
|
def add(x, y):
|
||||||
|
return x + y
|
||||||
|
|
||||||
``trunc`` is now known in "group1", but not in others.
|
|
||||||
|
``add`` is now known in "group1", but not in others.
|
||||||
|
|
||||||
.. doctest:: group1
|
.. doctest:: group1
|
||||||
|
|
||||||
>>> trunc(1.1)
|
>>> add(1, 1)
|
||||||
1
|
2
|
||||||
|
|
||||||
.. doctest:: group2
|
.. doctest:: group2
|
||||||
|
|
||||||
>>> trunc(1.1)
|
>>> add(1, 1)
|
||||||
Traceback (most recent call last):
|
Traceback (most recent call last):
|
||||||
...
|
...
|
||||||
NameError: name 'trunc' is not defined
|
NameError: name 'add' is not defined
|
||||||
|
|
||||||
Interleaving testcode/testoutput:
|
Interleaving testcode/testoutput:
|
||||||
|
|
||||||
.. testcode:: group1
|
.. testcode:: group1
|
||||||
|
|
||||||
print(factorial(3))
|
print(squared(3))
|
||||||
|
|
||||||
.. testcode:: group2
|
.. testcode:: group2
|
||||||
|
|
||||||
print(factorial(4))
|
print(squared(4))
|
||||||
|
|
||||||
.. testoutput:: group1
|
.. testoutput:: group1
|
||||||
|
|
||||||
6
|
9
|
||||||
|
|
||||||
.. testoutput:: group2
|
.. testoutput:: group2
|
||||||
|
|
||||||
24
|
16
|
||||||
|
|||||||
Reference in New Issue
Block a user