File: doctest.py

package info (click to toggle)
python-astropy-helpers 1.3-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 756 kB
  • ctags: 698
  • sloc: python: 5,929; ansic: 88; makefile: 11
file content (38 lines) | stat: -rw-r--r-- 1,310 bytes parent folder | download | duplicates (19)
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
# Licensed under a 3-clause BSD style license - see LICENSE.rst
"""
This is a set of three directives that allow us to insert metadata
about doctests into the .rst files so the testing framework knows
which tests to skip.

This is quite different from the doctest extension in Sphinx itself,
which actually does something.  For astropy, all of the testing is
centrally managed from py.test and Sphinx is not used for running
tests.
"""
import re
from docutils.nodes import literal_block
from sphinx.util.compat import Directive


class DoctestSkipDirective(Directive):
    has_content = True

    def run(self):
        # Check if there is any valid argument, and skip it. Currently only
        # 'win32' is supported in astropy.tests.pytest_plugins.
        if re.match('win32', self.content[0]):
            self.content = self.content[2:]
        code = '\n'.join(self.content)
        return [literal_block(code, code)]


class DoctestRequiresDirective(DoctestSkipDirective):
    # This is silly, but we really support an unbounded number of
    # optional arguments
    optional_arguments = 64


def setup(app):
    app.add_directive('doctest-requires', DoctestRequiresDirective)
    app.add_directive('doctest-skip', DoctestSkipDirective)
    app.add_directive('doctest-skip-all', DoctestSkipDirective)