Check code in a text file. Mimic `check_doctests` above, differing mostly in test discovery. (which is borrowed from stdlib's doctest.testfile here, https://github.com/python-git/python/blob/master/Lib/doctest.py) Parameters ---------- fname : str File name
(fname, verbose, ns=None,
dots=True, doctest_warnings=False)
| 910 | |
| 911 | |
| 912 | def check_doctests_testfile(fname, verbose, ns=None, |
| 913 | dots=True, doctest_warnings=False): |
| 914 | """ |
| 915 | Check code in a text file. |
| 916 | |
| 917 | Mimic `check_doctests` above, differing mostly in test discovery. |
| 918 | (which is borrowed from stdlib's doctest.testfile here, |
| 919 | https://github.com/python-git/python/blob/master/Lib/doctest.py) |
| 920 | |
| 921 | Parameters |
| 922 | ---------- |
| 923 | fname : str |
| 924 | File name |
| 925 | verbose : bool |
| 926 | |
| 927 | ns : dict |
| 928 | Name space |
| 929 | |
| 930 | dots : bool |
| 931 | |
| 932 | doctest_warnings : bool |
| 933 | |
| 934 | Returns |
| 935 | ------- |
| 936 | list |
| 937 | List of [(item_name, success_flag, output), ...] |
| 938 | |
| 939 | Notes |
| 940 | ----- |
| 941 | |
| 942 | refguide can be signalled to skip testing code by adding |
| 943 | ``#doctest: +SKIP`` to the end of the line. If the output varies or is |
| 944 | random, add ``# may vary`` or ``# random`` to the comment. for example |
| 945 | |
| 946 | >>> plt.plot(...) # doctest: +SKIP |
| 947 | >>> random.randint(0,10) |
| 948 | 5 # random |
| 949 | |
| 950 | We also try to weed out pseudocode: |
| 951 | * We maintain a list of exceptions which signal pseudocode, |
| 952 | * We split the text file into "blocks" of code separated by empty lines |
| 953 | and/or intervening text. |
| 954 | * If a block contains a marker, the whole block is then assumed to be |
| 955 | pseudocode. It is then not being doctested. |
| 956 | |
| 957 | The rationale is that typically, the text looks like this: |
| 958 | |
| 959 | blah |
| 960 | <BLANKLINE> |
| 961 | >>> from numpy import some_module # pseudocode! |
| 962 | >>> func = some_module.some_function |
| 963 | >>> func(42) # still pseudocode |
| 964 | 146 |
| 965 | <BLANKLINE> |
| 966 | blah |
| 967 | <BLANKLINE> |
| 968 | >>> 2 + 3 # real code, doctest it |
| 969 | 5 |
no test coverage detected