Ticket #13278: 13278.2.patch

File 13278.2.patch, 55.2 KB (added by jdemeyer, 7 years ago)
  • doc/en/developer/doctesting.rst

    # HG changeset patch
    # User David Roe <roed.math@gmail.com>
    # Date 1363407494 21600
    # Node ID 062e2899cfd0eb6b841ede197a594ce1e2d3854f
    # Parent  2c5b455219f82dc5772ebea93d26a66f57688641
    Adds a show_skipped option to the doctesting framework.
    
    Using this option prints the number and type of tests that are skipped when doctesting.
    
    This patch also does some cleanup, changing DocTestSource to use DocTestOptions rather than individual options.
    
    diff --git a/doc/en/developer/doctesting.rst b/doc/en/developer/doctesting.rst
    a b  
    10271027failure in each doctest block use the ``--initial`` flag (``-i`` for
    10281028short).
    10291029
     1030Show skipped optional tests
     1031^^^^^^^^^^^^^^^^^^^^^^^^^^^
     1032
     1033To print a summary at the end of each file with the number of optional
     1034tests skipped, use the ``--show-skipped`` flag::
     1035
     1036   [roed@sage sage-5.9]$ sage -t --show-skipped devel/sage-main/sage/rings/finite_rings/integer_mod.pyx
     1037   Running doctests with ID 2013-03-14-15-32-05-8136f5e3.
     1038   Doctesting 1 file.
     1039   sage -t sage/rings/finite_rings/integer_mod.pyx
     1040       2 axiom tests not run
     1041       1 cunningham test not run
     1042       2 fricas tests not run
     1043       1 long test not run
     1044       3 magma tests not run
     1045       [440 tests, 4.0 s]
     1046   ----------------------------------------------------------------------
     1047   All tests passed!
     1048   ----------------------------------------------------------------------
     1049   Total time for all tests: 4.3 seconds
     1050       cpu time: 2.4 seconds
     1051       cumulative wall time: 4.0 seconds
     1052
    10301053Running tests with iterations
    10311054^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    10321055
  • sage/doctest/control.py

    diff --git a/sage/doctest/control.py b/sage/doctest/control.py
    a b  
    6161
    6262            sage: from sage.doctest.control import DocTestDefaults
    6363            sage: D = DocTestDefaults(); D.optional
    64             'sage'
     64            set(['sage'])
    6565        """
    6666        self.nthreads = 1
    6767        self.serial = False
     
    7171        self.sagenb = False
    7272        self.long = False
    7373        self.warn_long = None
    74         self.optional = "sage"
     74        self.optional = set(["sage"])
    7575        self.randorder = None
    7676        self.global_iterations = 1  # sage-runtests default is 0
    7777        self.file_iterations = 1    # sage-runtests default is 0
     
    8787        self.omega = False
    8888        self.failed = False
    8989        self.new = False
     90        self.show_skipped = False
    9091        # We don't want to use the real stats file by default so that
    9192        # we don't overwrite timings for the actual running doctests.
    9293        self.stats_path = os.path.join(DOT_SAGE, "timings_dt_test.json")
     
    113114        s += ")"
    114115        return s
    115116
     117    def __cmp__(self, other):
     118        """
     119        Comparison by __dict__.
     120
     121        EXAMPLES::
     122
     123            sage: from sage.doctest.control import DocTestDefaults
     124            sage: DD1 = DocTestDefaults(long=True)
     125            sage: DD2 = DocTestDefaults(long=True)
     126            sage: DD1 == DD2
     127            True
     128        """
     129        c = cmp(type(self), type(other))
     130        if c: return c
     131        return cmp(self.__dict__,other.__dict__)
    116132
    117133class DocTestController(SageObject):
    118134    """
     
    165181            options.nthreads = 1
    166182        if options.serial:
    167183            options.nthreads = 1
     184        if options.verbose:
     185            options.show_skipped = True
    168186
     187        if isinstance(options.optional, basestring):
     188            if options.optional.lower() in ['all', 'true']:
     189                options.optional = True
     190            else:
     191                options.optional = set(options.optional.lower().split(','))
    169192        self.options = options
    170193        self.files = args
    171194        if options.all and options.logfile is None:
     
    408431            sage: DC.expand_files_into_sources()
    409432            sage: len(DC.sources)
    410433            9
    411             sage: DC.sources[0].optional
     434            sage: DC.sources[0].options.optional
    412435            True
    413436
    414437        ::
     
    416439            sage: DD = DocTestDefaults(optional='magma,guava')
    417440            sage: DC = DocTestController(DD, [dirname])
    418441            sage: DC.expand_files_into_sources()
    419             sage: sorted(list(DC.sources[0].optional))
     442            sage: sorted(list(DC.sources[0].options.optional))
    420443            ['guava', 'magma']
    421444        """
    422445        def skipdir(dirname):
     
    445468                else:
    446469                    # the user input this file explicitly, so we don't skip it
    447470                    yield path
    448         if self.options.optional == 'all':
    449             optionals = True
    450         else:
    451             optionals = set(self.options.optional.lower().split(','))
    452         self.sources = [FileDocTestSource(path, self.options.force_lib, long=self.options.long, optional=optionals, randorder=self.options.randorder, useabspath=self.options.abspath) for path in expand()]
     471        self.sources = [FileDocTestSource(path, self.options) for path in expand()]
    453472
    454473    def filter_sources(self):
    455474        """
     
    677696            sage: DD = DocTestDefaults(valgrind=True, optional="all", timeout=172800)
    678697            sage: DC = DocTestController(DD, ["hello_world.py"])
    679698            sage: DC.run_val_gdb(testing=True)
    680             exec valgrind --tool=memcheck --leak-resolution=high --leak-check=full --num-callers=25 --suppressions="$SAGE_LOCAL/lib/valgrind/sage.supp"  --log-file=".../valgrind/sage-memcheck.%p" python "$SAGE_LOCAL/bin/sage-runtests" --serial --timeout=172800 --optional=all hello_world.py
     699            exec valgrind --tool=memcheck --leak-resolution=high --leak-check=full --num-callers=25 --suppressions="$SAGE_LOCAL/lib/valgrind/sage.supp"  --log-file=".../valgrind/sage-memcheck.%p" python "$SAGE_LOCAL/bin/sage-runtests" --serial --timeout=172800 --optional=True hello_world.py
    681700        """
    682701        try:
    683702            sage_cmd = self._assemble_cmd()
  • sage/doctest/forker.py

    diff --git a/sage/doctest/forker.py b/sage/doctest/forker.py
    a b  
    389389            sage: import doctest, sys, os
    390390            sage: DTR = SageDocTestRunner(SageOutputChecker(), verbose=False, sage_options=DD, optionflags=doctest.NORMALIZE_WHITESPACE|doctest.ELLIPSIS)
    391391            sage: filename = os.path.join(SAGE_SRC,'sage','doctest','forker.py')
    392             sage: FDS = FileDocTestSource(filename,True,False,set(['sage']),None)
     392            sage: FDS = FileDocTestSource(filename,DD)
    393393            sage: doctests, extras = FDS.create_doctests(globals())
    394394            sage: DTR.run(doctests[0], clear_globs=False) # indirect doctest
    395395            TestResults(failed=0, attempted=4)
     
    565565            sage: import doctest, sys, os
    566566            sage: DTR = SageDocTestRunner(SageOutputChecker(), verbose=False, sage_options=DD, optionflags=doctest.NORMALIZE_WHITESPACE|doctest.ELLIPSIS)
    567567            sage: filename = os.path.join(SAGE_SRC,'sage','doctest','forker.py')
    568             sage: FDS = FileDocTestSource(filename,True,False,set(['sage']),None)
     568            sage: FDS = FileDocTestSource(filename,DD)
    569569            sage: doctests, extras = FDS.create_doctests(globals())
    570570            sage: DTR.run(doctests[0], clear_globs=False)
    571571            TestResults(failed=0, attempted=4)
     
    710710            sage: import doctest, sys, os, hashlib
    711711            sage: DTR = SageDocTestRunner(SageOutputChecker(), verbose=False, sage_options=DD, optionflags=doctest.NORMALIZE_WHITESPACE|doctest.ELLIPSIS)
    712712            sage: filename = os.path.join(SAGE_SRC,'sage','doctest','forker.py')
    713             sage: FDS = FileDocTestSource(filename,True,False,set(['sage']),None)
     713            sage: FDS = FileDocTestSource(filename,DD)
    714714            sage: doctests, extras = FDS.create_doctests(globals())
    715715            sage: DTR.running_global_digest.hexdigest()
    716716            'd41d8cd98f00b204e9800998ecf8427e'
     
    769769            sage: DTR = SageDocTestRunner(SageOutputChecker(), verbose=False, sage_options=DD, optionflags=doctest.NORMALIZE_WHITESPACE|doctest.ELLIPSIS)
    770770            sage: DTR.running_doctest_digest = hashlib.md5()
    771771            sage: filename = os.path.join(SAGE_SRC,'sage','doctest','forker.py')
    772             sage: FDS = FileDocTestSource(filename,True,False,set(['sage']),None)
     772            sage: FDS = FileDocTestSource(filename,DD)
    773773            sage: globs = RecordingDict(globals())
    774774            sage: globs.has_key('doctest_var')
    775775            False
     
    859859            sage: import doctest, sys, os
    860860            sage: DTR = SageDocTestRunner(SageOutputChecker(), verbose=False, sage_options=DD, optionflags=doctest.NORMALIZE_WHITESPACE|doctest.ELLIPSIS)
    861861            sage: filename = os.path.join(SAGE_SRC,'sage','doctest','forker.py')
    862             sage: FDS = FileDocTestSource(filename,True,False,set(['sage']),None)
     862            sage: FDS = FileDocTestSource(filename,DD)
    863863            sage: doctests, extras = FDS.create_doctests(globals())
    864864            sage: ex = doctests[0].examples[0]
    865865            sage: print DTR._failure_header(doctests[0], ex)
     
    908908            sage: import doctest, sys, os
    909909            sage: DTR = SageDocTestRunner(SageOutputChecker(), verbose=True, sage_options=DD, optionflags=doctest.NORMALIZE_WHITESPACE|doctest.ELLIPSIS)
    910910            sage: filename = os.path.join(SAGE_SRC,'sage','doctest','forker.py')
    911             sage: FDS = FileDocTestSource(filename,True,False,set(['sage']),None)
     911            sage: FDS = FileDocTestSource(filename,DD)
    912912            sage: doctests, extras = FDS.create_doctests(globals())
    913913            sage: ex = doctests[0].examples[0]
    914914            sage: DTR.report_start(sys.stdout.write, doctests[0], ex)
     
    956956            sage: import doctest, sys, os
    957957            sage: DTR = SageDocTestRunner(SageOutputChecker(), verbose=True, sage_options=DD, optionflags=doctest.NORMALIZE_WHITESPACE|doctest.ELLIPSIS)
    958958            sage: filename = os.path.join(SAGE_SRC,'sage','doctest','forker.py')
    959             sage: FDS = FileDocTestSource(filename,True,False,set(['sage']),None)
     959            sage: FDS = FileDocTestSource(filename,DD)
    960960            sage: doctests, extras = FDS.create_doctests(globals())
    961961            sage: ex = doctests[0].examples[0]
    962962            sage: ex.walltime = 0.0
     
    997997            sage: import doctest, sys, os
    998998            sage: DTR = SageDocTestRunner(SageOutputChecker(), verbose=True, sage_options=DD, optionflags=doctest.NORMALIZE_WHITESPACE|doctest.ELLIPSIS)
    999999            sage: filename = os.path.join(SAGE_SRC,'sage','doctest','forker.py')
    1000             sage: FDS = FileDocTestSource(filename,True,False,set(['sage']),None)
     1000            sage: FDS = FileDocTestSource(filename,DD)
    10011001            sage: doctests, extras = FDS.create_doctests(globals())
    10021002            sage: ex = doctests[0].examples[0]
    10031003            sage: DTR.no_failure_yet = True
     
    10451045            sage: import doctest, sys, os
    10461046            sage: DTR = SageDocTestRunner(SageOutputChecker(), verbose=True, sage_options=DD, optionflags=doctest.NORMALIZE_WHITESPACE|doctest.ELLIPSIS)
    10471047            sage: filename = os.path.join(SAGE_SRC,'sage','doctest','forker.py')
    1048             sage: FDS = FileDocTestSource(filename,True,False,set(['sage']),None)
     1048            sage: FDS = FileDocTestSource(filename,DD)
    10491049            sage: doctests, extras = FDS.create_doctests(globals())
    10501050            sage: ex = doctests[0].examples[0]
    10511051            sage: ex.walltime = 1.23
     
    11641164            sage: import doctest, sys, os
    11651165            sage: DTR = SageDocTestRunner(SageOutputChecker(), verbose=False, sage_options=DD, optionflags=doctest.NORMALIZE_WHITESPACE|doctest.ELLIPSIS)
    11661166            sage: filename = os.path.join(SAGE_SRC,'sage','doctest','forker.py')
    1167             sage: FDS = FileDocTestSource(filename,True,False,set(['sage']),None)
     1167            sage: FDS = FileDocTestSource(filename,DD)
    11681168            sage: doctests, extras = FDS.create_doctests(globals())
    11691169            sage: from sage.doctest.util import Timer
    11701170            sage: T = Timer().start()
     
    15801580        sage: from sage.env import SAGE_SRC
    15811581        sage: filename = os.path.join(SAGE_SRC,'sage','doctest','util.py')
    15821582        sage: DD = DocTestDefaults()
    1583         sage: FDS = FileDocTestSource(filename,True,False,set(['sage']),None)
     1583        sage: FDS = FileDocTestSource(filename,DD)
    15841584        sage: W = DocTestWorker(FDS, DD)
    15851585        sage: W.start()
    15861586        sage: DC = DocTestController(DD, filename)
     
    17101710            sage: from sage.env import SAGE_SRC
    17111711            sage: filename = os.path.join(SAGE_SRC,'sage','doctest','util.py')
    17121712            sage: DD = DocTestDefaults()
    1713             sage: FDS = FileDocTestSource(filename,True,False,set(['sage']),None)
     1713            sage: FDS = FileDocTestSource(filename,DD)
    17141714            sage: W = DocTestWorker(FDS, DD)
    17151715            sage: W.start()
    17161716            sage: try:
     
    17501750            sage: from sage.env import SAGE_SRC
    17511751            sage: filename = os.path.join(SAGE_SRC,'sage','doctest','util.py')
    17521752            sage: DD = DocTestDefaults(verbose=True,nthreads=2)
    1753             sage: FDS = FileDocTestSource(filename,True,False,set(['sage']),None)
     1753            sage: FDS = FileDocTestSource(filename,DD)
    17541754            sage: W = DocTestWorker(FDS, DD)
    17551755            sage: W.start()
    17561756            sage: while W.rmessages is not None:
     
    17851785            sage: from sage.env import SAGE_SRC
    17861786            sage: filename = os.path.join(SAGE_SRC,'sage','doctest','util.py')
    17871787            sage: DD = DocTestDefaults()
    1788             sage: FDS = FileDocTestSource(filename,True,False,set(['sage']),None)
     1788            sage: FDS = FileDocTestSource(filename,DD)
    17891789            sage: W = DocTestWorker(FDS, DD)
    17901790            sage: W.start()
    17911791            sage: W.join()
    17921792            sage: W.save_result_output()
    17931793            sage: sorted(W.result[1].keys())
    1794             ['cputime', 'err', 'failures', 'walltime']
     1794            ['cputime', 'err', 'failures', 'optionals', 'walltime']
    17951795            sage: len(W.output) > 0
    17961796            True
    17971797        """
     
    18221822            sage: from sage.env import SAGE_SRC
    18231823            sage: filename = os.path.join(SAGE_SRC,'sage','doctest','tests','99seconds.rst')
    18241824            sage: DD = DocTestDefaults()
    1825             sage: FDS = FileDocTestSource(filename,True,False,set(['sage']),None)
     1825            sage: FDS = FileDocTestSource(filename,DD)
    18261826
    18271827        We set up the worker to start by blocking ``SIGHUP``, such that
    18281828        killing will fail initially::
     
    18771877        sage: from sage.env import SAGE_SRC
    18781878        sage: import os
    18791879        sage: filename = os.path.join(SAGE_SRC,'sage','doctest','sources.py')
    1880         sage: FDS = FileDocTestSource(filename,True,False,set(['sage']),None)
     1880        sage: DD = DocTestDefaults()
     1881        sage: FDS = FileDocTestSource(filename,DD)
    18811882        sage: DTT = DocTestTask(FDS)
    1882         sage: DD = DocTestDefaults()
    18831883        sage: DC = DocTestController(DD,[filename])
    18841884        sage: ntests, results = DTT(options=DD)
    1885         sage: ntests
    1886         292
     1885        sage: ntests >= 300 or ntests
     1886        True
    18871887        sage: sorted(results.keys())
    1888         ['cputime', 'err', 'failures', 'walltime']
     1888        ['cputime', 'err', 'failures', 'optionals', 'walltime']
    18891889    """
    18901890    def __init__(self, source):
    18911891        """
     
    18951895
    18961896            sage: from sage.doctest.forker import DocTestTask
    18971897            sage: from sage.doctest.sources import FileDocTestSource
     1898            sage: from sage.doctest.control import DocTestDefaults
    18981899            sage: from sage.env import SAGE_SRC
    18991900            sage: import os
    19001901            sage: filename = os.path.join(SAGE_SRC,'sage','doctest','sources.py')
    1901             sage: FDS = FileDocTestSource(filename,True,False,set(['sage']),None)
     1902            sage: FDS = FileDocTestSource(filename,DocTestDefaults())
    19021903            sage: DocTestTask(FDS)
    19031904            <sage.doctest.forker.DocTestTask object at ...>
    19041905        """
     
    19381939            sage: from sage.env import SAGE_SRC
    19391940            sage: import os
    19401941            sage: filename = os.path.join(SAGE_SRC,'sage','doctest','parsing.py')
    1941             sage: FDS = FileDocTestSource(filename,True,False,set(['sage']),None)
     1942            sage: DD = DocTestDefaults()
     1943            sage: FDS = FileDocTestSource(filename,DD)
    19421944            sage: DTT = DocTestTask(FDS)
    1943             sage: DD = DocTestDefaults()
    19441945            sage: DC = DocTestController(DD, [filename])
    19451946            sage: ntests, runner = DTT(options=DD)
    19461947            sage: runner.failures
    19471948            0
    1948             sage: ntests
    1949             206
     1949            sage: ntests >= 200 or ntests
     1950            True
    19501951        """
    19511952        result = None
    19521953        try:
     
    19801981            if extras['tab']:
    19811982                results.err = 'tab'
    19821983                results.tab_linenos = extras['tab']
     1984            results.optionals = extras['optionals']
    19831985            # We subtract 1 to remove the sig_on_count() tests
    19841986            result = (sum([max(0,len(test.examples) - 1) for test in doctests]), results)
    19851987        except BaseException:
  • sage/doctest/parsing.py

    diff --git a/sage/doctest/parsing.py b/sage/doctest/parsing.py
    a b  
    2020
    2121import re, sys
    2222import doctest
     23import collections
    2324from sage.misc.preparser import preparse
    2425from Cython.Build.Dependencies import strip_string_literals
    2526
     
    5960        sage: sorted(list(parse_optional_tags("    sage: factor(10^(10^10) + 1) # LoNg TiME, NoT TeSTED; OptioNAL -- P4cka9e")))
    6061        ['long time', 'not tested', 'p4cka9e']
    6162        sage: parse_optional_tags("    sage: raise RuntimeError # known bug")
    62         set(['known bug'])
     63        set(['bug'])
    6364        sage: sorted(list(parse_optional_tags("    sage: determine_meaning_of_life() # long time, not implemented")))
    6465        ['long time', 'not implemented']
    6566
     
    8081
    8182    tags = []
    8283    for m in optional_regex.finditer(comment):
    83         if m.group(1):
    84             tags.append(m.group(1))
     84        cmd = m.group(1)
     85        if cmd == 'known bug':
     86            tags.append('bug') # so that such tests will be run by sage -t ... -only-optional=bug
     87        elif cmd:
     88            tags.append(cmd)
    8589        else:
    8690            tags.extend(m.group(3).split() or [""])
    8791    return set(tags)
     
    275279    EXAMPLES::
    276280
    277281        sage: from sage.doctest.sources import FileDocTestSource
     282        sage: from sage.doctest.control import DocTestDefaults
    278283        sage: from sage.env import SAGE_SRC
    279284        sage: import os
    280285        sage: filename = os.path.join(SAGE_SRC,'sage','doctest','forker.py')
    281         sage: FDS = FileDocTestSource(filename,True,False,set(['sage']),None)
     286        sage: FDS = FileDocTestSource(filename,DocTestDefaults())
    282287        sage: doctests, extras = FDS.create_doctests(globals())
    283288        sage: ex = doctests[0].examples[0]
    284289        sage: ex.sage_source
     
    301306        EXAMPLES::
    302307
    303308            sage: from sage.doctest.sources import FileDocTestSource
     309            sage: from sage.doctest.control import DocTestDefaults
    304310            sage: from sage.env import SAGE_SRC
    305311            sage: import os
    306312            sage: filename = os.path.join(SAGE_SRC,'sage','doctest','forker.py')
    307             sage: FDS = FileDocTestSource(filename,True,False,set(['sage']),None)
     313            sage: FDS = FileDocTestSource(filename,DocTestDefaults())
    308314            sage: doctests, extras = FDS.create_doctests(globals())
    309315            sage: ex = doctests[0].examples[0]
    310316            sage: from sage.doctest.parsing import OriginalSource
     
    318324        EXAMPLES::
    319325
    320326            sage: from sage.doctest.sources import FileDocTestSource
     327            sage: from sage.doctest.control import DocTestDefaults
    321328            sage: from sage.env import SAGE_SRC
    322329            sage: import os
    323330            sage: filename = os.path.join(SAGE_SRC,'sage','doctest','forker.py')
    324             sage: FDS = FileDocTestSource(filename,True,False,set(['sage']),None)
     331            sage: FDS = FileDocTestSource(filename,DocTestDefaults())
    325332            sage: doctests, extras = FDS.create_doctests(globals())
    326333            sage: ex = doctests[0].examples[0]
    327334            sage: from sage.doctest.parsing import OriginalSource
     
    338345        EXAMPLES::
    339346
    340347            sage: from sage.doctest.sources import FileDocTestSource
     348            sage: from sage.doctest.control import DocTestDefaults
    341349            sage: from sage.env import SAGE_SRC
    342350            sage: import os
    343351            sage: filename = os.path.join(SAGE_SRC,'sage','doctest','forker.py')
    344             sage: FDS = FileDocTestSource(filename,True,False,set(['sage']),None)
     352            sage: FDS = FileDocTestSource(filename,DocTestDefaults())
    345353            sage: doctests, extras = FDS.create_doctests(globals())
    346354            sage: ex = doctests[0].examples[0]
    347355            sage: from sage.doctest.parsing import OriginalSource
     
    383391            sage: TestSuite(DTP).run()
    384392        """
    385393        self.long = long
     394        self.optionals = collections.defaultdict(int) # record skipped optional tests
    386395        if optional_tags is True: # run all optional tests
    387396            self.optional_tags = True
    388397            self.optional_only = False
     
    510519            if isinstance(item, doctest.Example):
    511520                optional_tags = parse_optional_tags(item.source)
    512521                if optional_tags:
     522                    for tag in optional_tags:
     523                        self.optionals[tag] += 1
    513524                    if ('not implemented' in optional_tags) or ('not tested' in optional_tags):
    514525                        continue
    515                     elif 'known bug' in optional_tags:
    516                         optional_tags.remove('known bug')
    517                         optional_tags.add('bug') # so that such tests will be run by sage -t ... -only-optional=bug
    518526                    if 'long time' in optional_tags:
    519527                        if self.long:
    520528                            optional_tags.remove('long time')
  • sage/doctest/reporting.py

    diff --git a/sage/doctest/reporting.py b/sage/doctest/reporting.py
    a b  
    125125            sage: from sage.doctest.forker import SageDocTestRunner
    126126            sage: from sage.env import SAGE_SRC
    127127            sage: filename = os.path.join(SAGE_SRC,'sage','doctest','reporting.py')
    128             sage: FDS = FileDocTestSource(filename,True,False,set(['sage']),None)
    129128            sage: DD = DocTestDefaults()
     129            sage: FDS = FileDocTestSource(filename,DD)
    130130            sage: DC = DocTestController(DD, [filename])
    131131            sage: DTR = DocTestReporter(DC)
    132132            sage: print DTR.report_head(FDS)
     
    188188            sage: from sage.env import SAGE_SRC
    189189            sage: import os, sys, doctest
    190190            sage: filename = os.path.join(SAGE_SRC,'sage','doctest','reporting.py')
    191             sage: FDS = FileDocTestSource(filename,True,False,set(['sage']),None)
    192191            sage: DD = DocTestDefaults()
     192            sage: FDS = FileDocTestSource(filename,DD)
    193193            sage: DC = DocTestController(DD,[filename])
    194194            sage: DTR = DocTestReporter(DC)
    195195
     
    269269            1
    270270            sage: DTR.report(FDS, False, 0, (sum([len(t.examples) for t in doctests]), D), "Doctest output including the failure...")
    271271                [... tests, 1 failure, 0.0 s]
     272
     273        If the user has requested that we report on skipped doctests,
     274        we do so::
     275
     276            sage: DC.options = DocTestDefaults(show_skipped=True)
     277            sage: import collections
     278            sage: optionals = collections.defaultdict(int)
     279            sage: optionals['magma'] = 5; optionals['long time'] = 4; optionals[''] = 1; optionals['not tested'] = 2
     280            sage: D = DictAsObject(dict(err=None,optionals=optionals))
     281            sage: runner.failures = 0
     282            sage: runner.update_results(D)
     283            0
     284            sage: DTR.report(FDS, False, 0, (sum([len(t.examples) for t in doctests]), D), "Good tests")
     285                1 unlabeled test not run
     286                4 long tests not run
     287                5 magma tests not run
     288                2 other tests skipped
     289                [... tests, 0.0 s]
     290
    272291        """
    273292        try:
    274293            log = self.controller.log
     
    379398                    postscript['cputime'] += cpu
    380399                    postscript['walltime'] += wall
    381400
     401                    if self.controller.options.show_skipped:
     402                        try:
     403                            optionals = result_dict.optionals
     404                        except AttributeError:
     405                            optionals = dict()
     406                        if self.controller.options.optional is not True: # if True we test all optional tags
     407                            untested = 0  # Report not tested/implemented tests at the end
     408                            seen_other = False
     409                            for tag in sorted(optionals.keys()):
     410                                nskipped = optionals[tag]
     411                                if tag == "long time":
     412                                    if not self.controller.options.long:
     413                                        seen_other = True
     414                                        log("    %s not run"%(count_noun(nskipped, "long test")))
     415                                elif tag in ("not tested", "not implemented"):
     416                                    untested += nskipped
     417                                else:
     418                                    if tag not in self.controller.options.optional:
     419                                        seen_other = True
     420                                        if tag == "bug":
     421                                            log("    %s not run due to known bugs"%(count_noun(nskipped, "test")))
     422                                        elif tag == "":
     423                                            log("    %s not run"%(count_noun(nskipped, "unlabeled test")))
     424                                        else:
     425                                            log("    %s not run"%(count_noun(nskipped, tag + " test")))
     426                            if untested:
     427                                log ("    %s skipped"%(count_noun(untested, "%stest"%("other " if seen_other else ""))))
    382428                    log("    [%s, %s%.1f s]" % (count_noun(ntests, "test"), "%s, "%(count_noun(f, "failure")) if f else "", wall))
    383429            self.sources_completed += 1
    384430
     
    403449            sage: from sage.env import SAGE_SRC
    404450            sage: import os, sys, doctest
    405451            sage: filename = os.path.join(SAGE_SRC,'sage','doctest','reporting.py')
    406             sage: FDS = FileDocTestSource(filename,True,False,set(['sage']),None)
    407452            sage: DD = DocTestDefaults()
     453            sage: FDS = FileDocTestSource(filename,DD)
    408454            sage: DC = DocTestController(DD,[filename])
    409455            sage: DTR = DocTestReporter(DC)
    410456
  • sage/doctest/sources.py

    diff --git a/sage/doctest/sources.py b/sage/doctest/sources.py
    a b  
    9898
    9999    INPUT:
    100100
    101     - ``long`` -- whether to execute tests marked as ``# long time``
    102 
    103     - ``optional`` -- either True or a set of optional tags to execute
    104 
    105     - ``randorder`` -- whether to execute the doctests in this source
    106       in a random order
     101    - ``options`` -- a :class:`sage.doctest.control.DocTestDefaults`
     102      instance or equivalent.
    107103    """
    108     def __init__(self, long, optional, randorder):
     104    def __init__(self, options):
    109105        """
    110106        Initialization.
    111107
    112108        EXAMPLES::
    113109
     110            sage: from sage.doctest.control import DocTestDefaults
    114111            sage: from sage.doctest.sources import FileDocTestSource
    115112            sage: from sage.env import SAGE_SRC
    116113            sage: import os
    117114            sage: filename = os.path.join(SAGE_SRC,'sage','doctest','sources.py')
    118             sage: FDS = FileDocTestSource(filename,True,False,set(['sage']),0)
     115            sage: FDS = FileDocTestSource(filename,DocTestDefaults())
    119116            sage: TestSuite(FDS).run()
    120117        """
    121         self.long = long
    122         self.optional = optional
    123         self.randorder = randorder
     118        self.options = options
    124119
    125120    def __cmp__(self, other):
    126121        """
     
    128123
    129124        EXAMPLES::
    130125
     126            sage: from sage.doctest.control import DocTestDefaults
    131127            sage: from sage.doctest.sources import FileDocTestSource
    132128            sage: from sage.env import SAGE_SRC
    133129            sage: import os
    134130            sage: filename = os.path.join(SAGE_SRC,'sage','doctest','sources.py')
    135             sage: FDS = FileDocTestSource(filename,True,False,set(['sage']),0)
    136             sage: FDS2 = FileDocTestSource(filename,True,False,set(['sage']),0)
     131            sage: DD = DocTestDefaults()
     132            sage: FDS = FileDocTestSource(filename,DD)
     133            sage: FDS2 = FileDocTestSource(filename,DD)
    137134            sage: FDS == FDS2
    138135            True
    139136        """
     
    167164
    168165        EXAMPLES::
    169166
     167            sage: from sage.doctest.control import DocTestDefaults
    170168            sage: from sage.doctest.sources import FileDocTestSource
    171169            sage: from sage.doctest.parsing import SageDocTestParser
    172170            sage: from sage.env import SAGE_SRC
    173171            sage: import os
    174172            sage: filename = os.path.join(SAGE_SRC,'sage','doctest','util.py')
    175             sage: FDS = FileDocTestSource(filename,True,False,set(['sage']),None)
     173            sage: FDS = FileDocTestSource(filename,DocTestDefaults())
    176174            sage: doctests, _ = FDS.create_doctests({})
    177175            sage: manual_doctests = []
    178176            sage: for dt in doctests:
     
    217215
    218216        EXAMPLES::
    219217
     218            sage: from sage.doctest.control import DocTestDefaults
    220219            sage: from sage.doctest.sources import FileDocTestSource
    221220            sage: from sage.doctest.util import NestedName
    222221            sage: from sage.env import SAGE_SRC
    223222            sage: import os
    224223            sage: filename = os.path.join(SAGE_SRC,'sage','doctest','sources.py')
    225             sage: FDS = FileDocTestSource(filename,True,False,set(['sage']),None)
     224            sage: FDS = FileDocTestSource(filename,DocTestDefaults())
    226225            sage: FDS.qualified_name = NestedName('sage.doctest.sources')
    227226            sage: doctests, extras = FDS._create_doctests({})
    228227            sage: len(doctests)
     
    234233            tab_okay = isinstance(self,TexSource)
    235234        self._init()
    236235        self.line_shift = 0
    237         self.parser = SageDocTestParser(self.long, self.optional)
     236        self.parser = SageDocTestParser(self.options.long, self.options.optional)
    238237        self.linking = False
    239238        doctests = []
    240239        in_docstring = False
     
    293292        if unparsed_doc:
    294293            self._process_doc(doctests, doc, namespace, start)
    295294
    296         if self.randorder is not None and self.randorder is not False:
     295        extras = dict(tab = not tab_okay and tab_locations,
     296                      optionals = self.parser.optionals)
     297        if self.options.randorder is not None and self.options.randorder is not False:
    297298            # we want to randomize even when self.randorder = 0
    298             random.seed(self.randorder)
     299            random.seed(self.options.randorder)
    299300            randomized = []
    300301            while len(doctests) > 0:
    301302                i = random.randint(0, len(doctests)-1)
    302303                randomized.append(doctests.pop(i))
    303             return randomized, {'tab':not tab_okay and tab_locations}
     304            return randomized, extras
    304305        else:
    305             return doctests, {'tab':not tab_okay and tab_locations}
     306            return doctests, extras
    306307
    307308class StringDocTestSource(DocTestSource):
    308309    """
     
    316317    - ``source`` -- a string, giving the source code to be parsed for
    317318      doctests.
    318319
    319     - ``long`` -- whether to execute tests marked as ``# long time``
    320 
    321     - ``optional`` -- either True or a set of optional tags to execute
    322 
    323     - ``randorder`` -- whether to execute the doctests in this string
    324       in a random order
     320    - ``options`` -- a :class:`sage.doctest.control.DocTestDefaults`
     321      or equivalent.
    325322
    326323    - ``printpath`` -- a string, to be used in place of a filename
    327324      when doctest failures are displayed.
     
    331328
    332329    EXAMPLES::
    333330
     331        sage: from sage.doctest.control import DocTestDefaults
    334332        sage: from sage.doctest.sources import StringDocTestSource, PythonSource
    335333        sage: from sage.structure.dynamic_class import dynamic_class
    336334        sage: s = "'''\n    sage: 2 + 2\n    4\n'''"
    337335        sage: PythonStringSource = dynamic_class('PythonStringSource',(StringDocTestSource, PythonSource))
    338         sage: PSS = PythonStringSource('<runtime>', s, False, set(['sage']), False, 'runtime')
     336        sage: PSS = PythonStringSource('<runtime>', s, DocTestDefaults(), 'runtime')
    339337        sage: dt, extras = PSS.create_doctests({})
    340338        sage: len(dt)
    341339        1
    342340        sage: extras['tab']
    343341        []
    344342    """
    345     def __init__(self, basename, source, long, optional, randorder, printpath, lineno_shift=0):
     343    def __init__(self, basename, source, options, printpath, lineno_shift=0):
    346344        """
    347345        Initialization
    348346
    349347        TESTS::
    350348
     349            sage: from sage.doctest.control import DocTestDefaults
    351350            sage: from sage.doctest.sources import StringDocTestSource, PythonSource
    352351            sage: from sage.structure.dynamic_class import dynamic_class
    353352            sage: s = "'''\n    sage: 2 + 2\n    4\n'''"
    354353            sage: PythonStringSource = dynamic_class('PythonStringSource',(StringDocTestSource, PythonSource))
    355             sage: PSS = PythonStringSource('<runtime>', s, False, set(['sage']), False, 'runtime')
     354            sage: PSS = PythonStringSource('<runtime>', s, DocTestDefaults(), 'runtime')
    356355            sage: TestSuite(PSS).run()
    357356        """
    358357        self.qualified_name = NestedName(basename)
    359358        self.printpath = printpath
    360359        self.source = source
    361360        self.lineno_shift = lineno_shift
    362         DocTestSource.__init__(self, long, optional, randorder)
     361        DocTestSource.__init__(self, options)
    363362
    364363    def __iter__(self):
    365364        """
     
    367366
    368367        EXAMPLES::
    369368
     369            sage: from sage.doctest.control import DocTestDefaults
    370370            sage: from sage.doctest.sources import StringDocTestSource, PythonSource
    371371            sage: from sage.structure.dynamic_class import dynamic_class
    372372            sage: s = "'''\n    sage: 2 + 2\n    4\n'''"
    373373            sage: PythonStringSource = dynamic_class('PythonStringSource',(StringDocTestSource, PythonSource))
    374             sage: PSS = PythonStringSource('<runtime>', s, False, set(['sage']), False, 'runtime')
     374            sage: PSS = PythonStringSource('<runtime>', s, DocTestDefaults(), 'runtime')
    375375            sage: for n, line in PSS:
    376376            ....:     print n, line,
    377377            0 '''
     
    399399
    400400        EXAMPLES::
    401401
     402            sage: from sage.doctest.control import DocTestDefaults
    402403            sage: from sage.doctest.sources import StringDocTestSource, PythonSource
    403404            sage: from sage.structure.dynamic_class import dynamic_class
    404405            sage: s = "'''\n    sage: 2 + 2\n    4\n'''"
    405406            sage: PythonStringSource = dynamic_class('PythonStringSource',(StringDocTestSource, PythonSource))
    406             sage: PSS = PythonStringSource('<runtime>', s, False, set(['sage']), False, 'runtime')
     407            sage: PSS = PythonStringSource('<runtime>', s, DocTestDefaults(), 'runtime')
    407408            sage: dt, tabs = PSS.create_doctests({})
    408409            sage: for t in dt:
    409410            ....:     print t.name, t.examples[0].sage_source
     
    419420
    420421    - ``path`` -- string, the filename
    421422
    422     - ``force_lib`` -- bool, whether this file shoule be considered
    423       part of the Sage library
    424 
    425     - ``long`` -- whether to execute tests marked as ``# long time``
    426 
    427     - ``optional`` -- either True or a set of optional tags to execute
    428 
    429     - ``randorder`` -- whether to execute the doctests in this file in
    430       a random order
    431 
    432     - ``useabspath`` -- bool (default: False), whether paths should be
    433       printed absolutely
     423    - ``options`` -- a :class:`sage.doctest.control.DocTestDefaults`
     424      instance or equivalent.
    434425
    435426    EXAMPLES::
    436427
     428        sage: from sage.doctest.control import DocTestDefaults
    437429        sage: from sage.doctest.sources import FileDocTestSource
    438430        sage: from sage.env import SAGE_SRC
    439431        sage: import os
    440432        sage: filename = os.path.join(SAGE_SRC,'sage','doctest','sources.py')
    441         sage: FDS = FileDocTestSource(filename,True,False,set(['sage']),None)
     433        sage: FDS = FileDocTestSource(filename,DocTestDefaults())
    442434        sage: FDS.basename
    443435        'sage.doctest.sources'
    444436
     
    446438
    447439        sage: TestSuite(FDS).run()
    448440    """
    449     def __init__(self, path, force_lib, long, optional, randorder, useabspath=False):
     441    def __init__(self, path, options):
    450442        """
    451443        Initialization.
    452444
    453445        EXAMPLES::
    454446
     447            sage: from sage.doctest.control import DocTestDefaults
    455448            sage: from sage.doctest.sources import FileDocTestSource
    456449            sage: from sage.env import SAGE_SRC
    457450            sage: import os
    458451            sage: filename = os.path.join(SAGE_SRC,'sage','doctest','sources.py')
    459             sage: FDS = FileDocTestSource(filename,True,False,set(['sage']),0)
    460             sage: FDS.randorder
     452            sage: FDS = FileDocTestSource(filename,DocTestDefaults(randorder=0))
     453            sage: FDS.options.randorder
    461454            0
    462455        """
    463456        self.path = path
    464         self.force_lib = force_lib
    465         DocTestSource.__init__(self, long, optional, randorder)
    466         self.useabspath = useabspath
     457        DocTestSource.__init__(self, options)
    467458        base, ext = os.path.splitext(path)
    468459        if ext in ('.py', '.pyx', '.pxi', '.sage', '.spyx'):
    469460            self.__class__ = dynamic_class('PythonFileSource',(FileDocTestSource,PythonSource))
     
    478469
    479470        EXAMPLES::
    480471
     472            sage: from sage.doctest.control import DocTestDefaults
    481473            sage: from sage.doctest.sources import FileDocTestSource
    482474            sage: filename = tmp_filename(ext=".py")
    483475            sage: s = "'''\n    sage: 2 + 2\n    4\n'''"
    484476            sage: open(filename, 'w').write(s)
    485             sage: FDS = FileDocTestSource(filename, False, False, set(['sage']), False)
     477            sage: FDS = FileDocTestSource(filename, DocTestDefaults())
    486478            sage: for n, line in FDS:
    487479            ....:     print n, line,
    488480            0 '''
     
    501493
    502494        EXAMPLES::
    503495
     496            sage: from sage.doctest.control import DocTestDefaults
    504497            sage: from sage.doctest.sources import FileDocTestSource
    505498            sage: from sage.env import SAGE_SRC
    506499            sage: import os
     
    508501            sage: filename = os.path.join(root,'doctest','sources.py')
    509502            sage: cwd = os.getcwd()
    510503            sage: os.chdir(root)
    511             sage: FDS = FileDocTestSource(filename,True,False,set(['sage']),0)
     504            sage: FDS = FileDocTestSource(filename,DocTestDefaults(randorder=0,abspath=False))
    512505            sage: FDS.printpath
    513506            'doctest/sources.py'
    514             sage: FDS = FileDocTestSource(filename,True,False,set(['sage']),0,useabspath=True)
     507            sage: FDS = FileDocTestSource(filename,DocTestDefaults(randorder=0,abspath=True))
    515508            sage: FDS.printpath
    516509            '.../sage/doctest/sources.py'
    517510            sage: os.chdir(cwd)
    518511        """
    519         if self.useabspath:
     512        if self.options.abspath:
    520513            return os.path.abspath(self.path)
    521514        else:
    522515            relpath = os.path.relpath(self.path)
     
    532525
    533526        EXAMPLES::
    534527
     528            sage: from sage.doctest.control import DocTestDefaults
    535529            sage: from sage.doctest.sources import FileDocTestSource
    536530            sage: from sage.env import SAGE_SRC
    537531            sage: import os
    538532            sage: filename = os.path.join(SAGE_SRC,'sage','rings','integer.pyx')
    539             sage: FDS = FileDocTestSource(filename,False,False,set(['sage']),None)
     533            sage: FDS = FileDocTestSource(filename,DocTestDefaults())
    540534            sage: FDS.basename
    541535            'sage.rings.integer'
    542536        """
     
    551545
    552546        EXAMPLES::
    553547
     548            sage: from sage.doctest.control import DocTestDefaults
    554549            sage: from sage.doctest.sources import FileDocTestSource
    555550            sage: from sage.env import SAGE_SRC
    556551            sage: import os
    557552            sage: filename = os.path.join(SAGE_SRC,'sage','rings','integer.pyx')
    558             sage: FDS = FileDocTestSource(filename,False,False,set(['sage']),None)
     553            sage: FDS = FileDocTestSource(filename,DocTestDefaults())
    559554            sage: FDS.in_lib
    560555            True
    561556
    562557        You can override the default::
    563558
    564             sage: FDS = FileDocTestSource("hello_world.py",False,False,set(['sage']),None)
     559            sage: FDS = FileDocTestSource("hello_world.py",DocTestDefaults())
    565560            sage: FDS.in_lib
    566561            False
    567             sage: FDS = FileDocTestSource("hello_world.py",True,False,set(['sage']),None)
     562            sage: FDS = FileDocTestSource("hello_world.py",DocTestDefaults(force_lib=True))
     563            sage: FDS.in_lib
     564            True
    568565        """
    569         return (self.force_lib or
     566        return (self.options.force_lib or
    570567                self.basename.startswith('sage.') or
    571568                self.basename.startswith('doc.') or
    572569                self.basename.startswith('sagenb.'))
     
    587584
    588585        EXAMPLES::
    589586
     587            sage: from sage.doctest.control import DocTestDefaults
    590588            sage: from sage.doctest.sources import FileDocTestSource
    591589            sage: from sage.env import SAGE_SRC
    592590            sage: import os
    593591            sage: filename = os.path.join(SAGE_SRC,'sage','doctest','sources.py')
    594             sage: FDS = FileDocTestSource(filename,True,False,set(['sage']),None)
     592            sage: FDS = FileDocTestSource(filename,DocTestDefaults())
    595593            sage: doctests, extras = FDS.create_doctests(globals())
    596594            sage: len(doctests)
    597595            40
     
    602600
    603601            sage: doctests[17].name
    604602            'sage.doctest.sources.FileDocTestSource.create_doctests'
    605             sage: doctests[17].examples[9].source
    606             'doctests[Integer(17)].examples[Integer(9)].source\n'
     603            sage: doctests[17].examples[10].source
     604            'doctests[Integer(17)].examples[Integer(10)].source\n'
    607605
    608606        TESTS:
    609607
     
    615613            sage: n = -920390823904823094890238490238484; hash(n) > 0
    616614            False # 32-bit
    617615            True  # 64-bit
    618             sage: ex = doctests[17].examples[12]
     616            sage: ex = doctests[17].examples[13]
    619617            sage: (bitness == '64' and ex.want == 'True  \n') or (bitness == '32' and ex.want == 'False \n')
    620618            True
    621619
     
    657655
    658656        TESTS::
    659657
     658            sage: from sage.doctest.control import DocTestDefaults
    660659            sage: from sage.doctest.sources import FileDocTestSource
    661660            sage: from sage.env import SAGE_SRC
    662661            sage: cwd = os.getcwd()
     
    669668            ....:         _, ext = os.path.splitext(F)
    670669            ....:         if ext in ('.py', '.pyx', '.sage', '.spyx', '.rst'):
    671670            ....:             filename = os.path.join(path, F)
    672             ....:             FDS = FileDocTestSource(filename, True, True, True, False)
     671            ....:             FDS = FileDocTestSource(filename, DocTestDefaults(long=True,optional=True))
    673672            ....:             FDS._test_enough_doctests(verbose=False)
    674673            There are 18 tests in sage/combinat/partition.py that are not being run
    675674            There are 12 tests in sage/combinat/tableau.py that are not being run
    676675            There are 3 unexpected tests being run in sage/doctest/parsing.py
     676            There are 1 unexpected tests being run in sage/doctest/reporting.py
    677677            There are 1 tests in sage/ext/c_lib.pyx that are not being run
    678678            There are 9 tests in sage/graphs/graph_plot.py that are not being run
    679679            There are 2 tests in sage/server/notebook/worksheet.py that are not being run
     
    762762
    763763        EXAMPLES::
    764764
     765            sage: from sage.doctest.control import DocTestDefaults
    765766            sage: from sage.doctest.sources import FileDocTestSource
    766767            sage: from sage.doctest.parsing import SageDocTestParser
    767768            sage: from sage.doctest.util import NestedName
    768769            sage: from sage.env import SAGE_SRC
    769770            sage: import os
    770771            sage: filename = os.path.join(SAGE_SRC,'sage','doctest','util.py')
    771             sage: FDS = FileDocTestSource(filename,True,False,set(['sage']),None)
     772            sage: FDS = FileDocTestSource(filename,DocTestDefaults())
    772773            sage: doctests, _ = FDS.create_doctests({})
    773774            sage: for dt in doctests:
    774775            ....:     FDS.qualified_name = dt.name
     
    784785
    785786    EXAMPLES::
    786787
     788        sage: from sage.doctest.control import DocTestDefaults
    787789        sage: from sage.doctest.sources import FileDocTestSource
    788790        sage: from sage.env import SAGE_SRC
    789791        sage: import os
    790792        sage: filename = os.path.join(SAGE_SRC,'sage','doctest','sources.py')
    791         sage: FDS = FileDocTestSource(filename,True,False,set(['sage']),None)
     793        sage: FDS = FileDocTestSource(filename,DocTestDefaults())
    792794        sage: type(FDS)
    793795        <class 'sage.doctest.sources.PythonFileSource'>
    794796    """
     
    801803
    802804        EXAMPLES::
    803805
     806            sage: from sage.doctest.control import DocTestDefaults
    804807            sage: from sage.doctest.sources import FileDocTestSource
    805808            sage: from sage.env import SAGE_SRC
    806809            sage: import os
    807810            sage: filename = os.path.join(SAGE_SRC,'sage','doctest','sources.py')
    808             sage: FDS = FileDocTestSource(filename,True,False,set(['sage']),None)
     811            sage: FDS = FileDocTestSource(filename,DocTestDefaults())
    809812            sage: FDS._init()
    810813            sage: FDS.last_indent
    811814            -1
     
    837840
    838841        EXAMPLES::
    839842
     843            sage: from sage.doctest.control import DocTestDefaults
    840844            sage: from sage.doctest.sources import FileDocTestSource
    841845            sage: from sage.env import SAGE_SRC
    842846            sage: import os
    843847            sage: filename = os.path.join(SAGE_SRC,'sage','doctest','sources.py')
    844             sage: FDS = FileDocTestSource(filename,True,False,set(['sage']),None)
     848            sage: FDS = FileDocTestSource(filename,DocTestDefaults())
    845849            sage: FDS._init()
    846850            sage: FDS._update_quotetype('\"\"\"'); print " ".join(list(FDS.quotetype))
    847851            " " "
     
    932936
    933937        EXAMPLES::
    934938
     939            sage: from sage.doctest.control import DocTestDefaults
    935940            sage: from sage.doctest.sources import FileDocTestSource
    936941            sage: from sage.doctest.util import NestedName
    937942            sage: from sage.env import SAGE_SRC
    938943            sage: import os
    939944            sage: filename = os.path.join(SAGE_SRC,'sage','doctest','sources.py')
    940             sage: FDS = FileDocTestSource(filename,True,False,set(['sage']),None)
     945            sage: FDS = FileDocTestSource(filename,DocTestDefaults())
    941946            sage: FDS._init()
    942947            sage: FDS.starting_docstring("r'''")
    943948            <_sre.SRE_Match object at ...>
     
    9971002
    9981003        EXAMPLES::
    9991004
     1005            sage: from sage.doctest.control import DocTestDefaults
    10001006            sage: from sage.doctest.sources import FileDocTestSource
    10011007            sage: from sage.doctest.util import NestedName
    10021008            sage: from sage.env import SAGE_SRC
    10031009            sage: import os
    10041010            sage: filename = os.path.join(SAGE_SRC,'sage','doctest','sources.py')
    1005             sage: FDS = FileDocTestSource(filename,True,False,set(['sage']),None)
     1011            sage: FDS = FileDocTestSource(filename,DocTestDefaults())
    10061012            sage: FDS._init()
    10071013            sage: FDS.quotetype = "'''"
    10081014            sage: FDS.ending_docstring("'''")
     
    10321038
    10331039        EXAMPLES::
    10341040
     1041            sage: from sage.doctest.control import DocTestDefaults
    10351042            sage: from sage.doctest.sources import StringDocTestSource, PythonSource
    10361043            sage: from sage.structure.dynamic_class import dynamic_class
    10371044            sage: s = "'''\n    sage: 2 + 2\n    4\n'''"
    10381045            sage: PythonStringSource = dynamic_class('PythonStringSource',(StringDocTestSource, PythonSource))
    1039             sage: PSS = PythonStringSource('<runtime>', s, False, set(['sage']), False, 'runtime')
     1046            sage: PSS = PythonStringSource('<runtime>', s, DocTestDefaults(), 'runtime')
    10401047            sage: print PSS._neutralize_doctests(0),
    10411048            '''
    10421049                safe: 2 + 2
     
    10661073
    10671074    EXAMPLES::
    10681075
     1076        sage: from sage.doctest.control import DocTestDefaults
    10691077        sage: from sage.doctest.sources import FileDocTestSource
    10701078        sage: filename = "sage_paper.tex"
    1071         sage: FDS = FileDocTestSource(filename,False,False,set(['sage']),None)
     1079        sage: FDS = FileDocTestSource(filename,DocTestDefaults())
    10721080        sage: type(FDS)
    10731081        <class 'sage.doctest.sources.TexFileSource'>
    10741082    """
     
    10811089
    10821090        EXAMPLES::
    10831091
     1092            sage: from sage.doctest.control import DocTestDefaults
    10841093            sage: from sage.doctest.sources import FileDocTestSource
    10851094            sage: filename = "sage_paper.tex"
    1086             sage: FDS = FileDocTestSource(filename,False,False,set(['sage']),None)
     1095            sage: FDS = FileDocTestSource(filename,DocTestDefaults())
    10871096            sage: FDS._init()
    10881097            sage: FDS.skipping
    10891098            False
     
    11121121
    11131122        EXAMPLES::
    11141123
     1124            sage: from sage.doctest.control import DocTestDefaults
    11151125            sage: from sage.doctest.sources import FileDocTestSource
    11161126            sage: filename = "sage_paper.tex"
    1117             sage: FDS = FileDocTestSource(filename,False,False,set(['sage']),None)
     1127            sage: FDS = FileDocTestSource(filename,DocTestDefaults())
    11181128            sage: FDS._init()
    11191129
    11201130        We start docstrings with \begin{verbatim}::
     
    11881198
    11891199        EXAMPLES::
    11901200
     1201            sage: from sage.doctest.control import DocTestDefaults
    11911202            sage: from sage.doctest.sources import FileDocTestSource
    11921203            sage: filename = "sage_paper.tex"
    1193             sage: FDS = FileDocTestSource(filename,False,False,set(['sage']),None)
     1204            sage: FDS = FileDocTestSource(filename,DocTestDefaults())
    11941205            sage: FDS._init()
    11951206            sage: FDS.ending_docstring(r"\end{verbatim}")
    11961207            True
     
    12281239
    12291240    EXAMPLES::
    12301241
     1242        sage: from sage.doctest.control import DocTestDefaults
    12311243        sage: from sage.doctest.sources import FileDocTestSource
    12321244        sage: filename = "sage_doc.rst"
    1233         sage: FDS = FileDocTestSource(filename,False,False,set(['sage']),None)
     1245        sage: FDS = FileDocTestSource(filename,DocTestDefaults())
    12341246        sage: type(FDS)
    12351247        <class 'sage.doctest.sources.RestFileSource'>
    12361248    """
     
    12431255
    12441256        EXAMPLES::
    12451257
     1258            sage: from sage.doctest.control import DocTestDefaults
    12461259            sage: from sage.doctest.sources import FileDocTestSource
    12471260            sage: filename = "sage_doc.rst"
    1248             sage: FDS = FileDocTestSource(filename,False,False,set(['sage']),None)
     1261            sage: FDS = FileDocTestSource(filename,DocTestDefaults())
    12491262            sage: FDS._init()
    12501263            sage: FDS.link_all
    12511264            False
     
    12731286
    12741287        EXAMPLES::
    12751288
     1289            sage: from sage.doctest.control import DocTestDefaults
    12761290            sage: from sage.doctest.sources import FileDocTestSource
    12771291            sage: filename = "sage_doc.rst"
    1278             sage: FDS = FileDocTestSource(filename,False,False,set(['sage']),None)
     1292            sage: FDS = FileDocTestSource(filename,DocTestDefaults())
    12791293            sage: FDS._init()
    12801294            sage: FDS.starting_docstring("Hello world::")
    12811295            True
     
    13311345
    13321346        EXAMPLES::
    13331347
     1348            sage: from sage.doctest.control import DocTestDefaults
    13341349            sage: from sage.doctest.sources import FileDocTestSource
    13351350            sage: filename = "sage_doc.rst"
    1336             sage: FDS = FileDocTestSource(filename,False,False,set(['sage']),None)
     1351            sage: FDS = FileDocTestSource(filename,DocTestDefaults())
    13371352            sage: FDS._init()
    13381353            sage: FDS.starting_docstring("Hello world::")
    13391354            True
     
    13751390
    13761391        EXAMPLES::
    13771392
     1393            sage: from sage.doctest.control import DocTestDefaults
    13781394            sage: from sage.doctest.sources import FileDocTestSource
    13791395            sage: from sage.doctest.parsing import SageDocTestParser
    13801396            sage: from sage.doctest.util import NestedName
    13811397            sage: filename = "sage_doc.rst"
    1382             sage: FDS = FileDocTestSource(filename,False,False,set(['sage']),None)
     1398            sage: FDS = FileDocTestSource(filename,DocTestDefaults())
    13831399            sage: FDS.parser = SageDocTestParser(False, set(['sage']))
    13841400            sage: FDS.qualified_name = NestedName('sage_doc')
    13851401            sage: s = "Some text::\n\n    def example_python_function(a, \
     
    14051421        min_indent = self.parser._min_indent(docstring)
    14061422        pysource = '\n'.join([l[min_indent:] for l in docstring.split('\n')])
    14071423        inner_source = PythonStringSource(self.basename, pysource,
    1408                                           self.long, self.optional, self.randorder,
     1424                                          self.options,
    14091425                                          self.printpath, lineno_shift=start+1)
    14101426        inner_doctests, _ = inner_source._create_doctests(namespace, True)
    14111427        safe_docstring = inner_source._neutralize_doctests(min_indent)
  • sage/doctest/test.py

    diff --git a/sage/doctest/test.py b/sage/doctest/test.py
    a b  
    217217    Doctesting 1 file.
    218218        Time out
    219219    4
     220
     221Test the ``--show-skipped`` option::
     222
     223    sage: subprocess.call(["sage", "-t", "--show-skipped", "show_skipped.rst"], cwd=tests_dir)  # long time
     224    Running doctests ...
     225    Doctesting 1 file.
     226    sage -t show_skipped.rst
     227        1 unlabeled test not run
     228        2 tests not run due to known bugs
     229        1 gap test not run
     230        1 long test not run
     231        1 other test skipped
     232        [1 test, ... s]
     233    ----------------------------------------------------------------------
     234    All tests passed!
     235    ----------------------------------------------------------------------
     236    ...
     237    0
     238
     239Optional tests are run correctly::
     240
     241    sage: subprocess.call(["sage", "-t", "--long", "--show-skipped", "--optional=sage,gap", "show_skipped.rst"], cwd=tests_dir)  # long time
     242    Running doctests ...
     243    Doctesting 1 file.
     244    sage -t --long show_skipped.rst
     245        1 unlabeled test not run
     246        2 tests not run due to known bugs
     247        1 other test skipped
     248        [3 tests, ... s]
     249    ----------------------------------------------------------------------
     250    All tests passed!
     251    ----------------------------------------------------------------------
     252    ...
     253    0
    220254"""
  • new file sage/doctest/tests/show_skipped.rst

    diff --git a/sage/doctest/tests/show_skipped.rst b/sage/doctest/tests/show_skipped.rst
    new file mode 100644
    - +  
     1We test that optional tests are run correctly and the
     2``--show-skipped`` option displays the correctly::
     3
     4    sage: 2 + 3
     5    5
     6    sage: 1 + 1 # optional - gap
     7    2
     8    sage: 1 - 1 # known bug
     9    17
     10    sage: 4 / 2 # long time
     11    2
     12    sage: 1 - 2 # optional - bug
     13    16
     14    sage: 8 + 1 # optional
     15    9
     16    sage: 1 / 0 # not tested
     17    I'm on fire!