1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142
|
:orphan:
Some Good Test Cases
********************
Some of the example code blocks in this file are perfectly valid and will pass
if they run. Some are not. The intent of this file is to test the directives
that are provided by the `--doctest-rst` option to make sure that the bad ones
get skipped.
.. This will not show in doc but it will run in doctestplus.
.. testsetup::
>>> x = 42
This code will show the value of ``x`` that is set within ``testsetup``::
>>> x
42
.. testcleanup::
>>> x = x + 1
This code will show the value of ``x`` that is set within ``testcleanup``::
>>> x
43
Here's One That Works
=====================
This code block should work just fine::
>>> 1 + 1
2
This one should work just fine as well::
>>> x = 5
>>> x
5
Here's One That Doesn't
=======================
This code won't run. So let's make sure that it gets skipped:
.. doctest-skip::
>>> y + z
42
This one doesn't work either:
.. doctest-skip::
>>> print(blue)
'blue'
Good Imports
============
There should be nothing wrong with this code, so we'll let it run::
>>> import os
>>> os.path.curdir
'.'
Make sure the `doctest-requires` directive works for modules that are
available:
.. doctest-requires:: sys
>>> import sys
Bad Imports
===========
I don't think this module exists, so we should make sure that this code doesn't
run:
.. doctest-requires:: foobar
>>> import foobar
>>> foobar.baz(42)
1
Package version
===============
Code in doctest should run only if version condition is satisfied:
.. doctest-requires:: numpy<=0.1
>>> import numpy
>>> assert 0
.. doctest-requires:: pytest>=1.0 pytest>=2.0
>>> import pytest
Combined Directives
===================
Marking code with two directives:
.. deprecated:: 1.0
.. doctest-requires:: numpy<=0.1
>>> 1 + 3
2
The order should not matter:
.. doctest-requires:: numpy<=0.1
.. deprecated:: 1.0
>>> 1 + 3
2
Try two doctestplus directives:
.. doctest-requires:: sys
.. doctest-skip::
>>> 1 + 3
2
Switch the order and it should still not run:
.. doctest-skip::
.. doctest-requires:: sys
>>> 1 + 3
2
|