Anonymous avatar Anonymous committed 6dd66bb

* Don't "build" dependent files, makes no sense.
* Don't resolve the pickled doctrees, not needed for doctests.

Comments (0)

Files changed (1)

sphinx/ext/doctest.py

 from docutils.parsers.rst import directives
 
 from sphinx.builder import Builder
+from sphinx.util.console import bold
 
 
 # set up the necessary directives
     # so that our builder recognizes them, and the other builders are happy.
     code = '\n'.join(content)
     nodetype = nodes.literal_block
-    if name == 'testsetup' or \
-       (name == 'testoutput' and 'hide' in options):
+    if name == 'testsetup' or 'hide' in options:
         nodetype = nodes.comment
     node = nodetype(code, code)
     node.line = lineno
         # don't try to highlight output
         node['language'] = 'none'
     node['options'] = {}
-    if name == 'testoutput' and 'options' in options:
+    if name in ('doctest', 'testoutput') and 'options' in options:
         # parse doctest-like output comparison flags
         option_strings = options['options'].replace(',', ' ').split()
         for option in option_strings:
             raise RuntimeError('invalid TestCode type')
 
     def __repr__(self):
-        return 'TestGroup(name=%r, setup=%r, code=%r)' % (
-            self.name, self.setup, self.code)
+        return 'TestGroup(name=%r, setup=%r, tests=%r)' % (
+            self.name, self.setup, self.tests)
 
 
 class TestCode(object):
     def get_outdated_docs(self):
         return self.env.all_docs
 
-    def prepare_writing(self, docnames):
-        return
-
     def finish(self):
         # write executive summary
         def s(v):
 
         sys.path[0:0] = self.config.doctest_path
 
-    def write_doc(self, docname, doctree):
+    def write(self, build_docnames, updated_docnames):
+        if build_docnames is None:
+            build_docnames = self.env.all_docs
+
+        self.info(bold('running tests...'))
+        for docname in build_docnames:
+            # no need to resolve the doctree
+            doctree = self.env.get_doctree(docname)
+            self.test_doc(docname, doctree)
+
+    def test_doc(self, docname, doctree):
         groups = {}
         add_to_all_groups = []
         self.setup_runner = SphinxDocTestRunner(verbose=False,
                                                 optionflags=self.opt)
         self.test_runner = SphinxDocTestRunner(verbose=False,
                                                optionflags=self.opt)
-        self.info()
         if self.config.doctest_test_doctest_blocks:
             def condition(node):
                 return (isinstance(node, (nodes.literal_block, nodes.comment))
         if not groups:
             return
 
-        self.outfile.write('\nDocument: %s\n----------%s\n' %
-                           (docname, '-'*len(docname)))
+        self._out('\nDocument: %s\n----------%s\n' % (docname, '-'*len(docname)))
         for group in groups.itervalues():
             self.test_group(group, self.env.doc2path(docname, base=None))
         # Separately count results from setup code
                     self._out('WARNING: no examples in doctest block at '
                               + filename + ', line %s' % code[0].lineno)
                     continue
+                for example in test.examples:
+                    # apply directive's comparison options
+                    new_opt = code[0].options.copy()
+                    new_opt.update(example.options)
+                    example.options = new_opt
             else:
                 output = code[1] and code[1].code or ''
                 options = code[1] and code[1].options or None
 
 def setup(app):
     app.add_directive('testsetup', testsetup_directive, 1, (0, 1, 1))
-    app.add_directive('doctest', doctest_directive, 1, (0, 1, 1))
-    app.add_directive('testcode', testcode_directive, 1, (0, 1, 1))
+    app.add_directive('doctest', doctest_directive, 1, (0, 1, 1),
+                      hide=directives.flag, options=directives.unchanged)
+    app.add_directive('testcode', testcode_directive, 1, (0, 1, 1),
+                      hide=directives.flag)
     app.add_directive('testoutput', testoutput_directive, 1, (0, 1, 1),
                       hide=directives.flag, options=directives.unchanged)
     app.add_builder(DocTestBuilder)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.