Ticket #13278: 13278.patch

File 13278.patch, 55.1 KB (added by roed, 7 years ago)
  • doc/en/developer/doctesting.rst

    # HG changeset patch
    # User David Roe <roed.math@gmail.com>
    # Date 1363407494 21600
    # Node ID 4e7cc696925901685c16635476e2a9acd42aab2c
    # Parent  01055ef32bc9ba74cb5695164b41d79994001647
    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  
    6262
    6363            sage: from sage.doctest.control import DocTestDefaults
    6464            sage: D = DocTestDefaults(); D.optional
    65             'sage'
     65            set(['sage'])
    6666        """
    6767        self.nthreads = 1
    6868        self.serial = False
     
    7272        self.sagenb = False
    7373        self.long = False
    7474        self.warn_long = None
    75         self.optional = "sage"
     75        self.optional = set(["sage"])
    7676        self.randorder = None
    7777        self.global_iterations = 1  # sage-runtests default is 0
    7878        self.file_iterations = 1    # sage-runtests default is 0
     
    8888        self.omega = False
    8989        self.failed = False
    9090        self.new = False
     91        self.show_skipped = False
    9192        # We don't want to use the real stats file by default so that
    9293        # we don't overwrite timings for the actual running doctests.
    9394        self.stats_path = os.path.join(DOT_SAGE, "timings_dt_test.json")
     
    114115        s += ")"
    115116        return s
    116117
     118    def __cmp__(self, other):
     119        """
     120        Comparison by __dict__.
     121
     122        EXAMPLES::
     123
     124            sage: from sage.doctest.control import DocTestDefaults
     125            sage: DD1 = DocTestDefaults(long=True)
     126            sage: DD2 = DocTestDefaults(long=True)
     127            sage: DD1 == DD2
     128            True
     129        """
     130        c = cmp(type(self), type(other))
     131        if c: return c
     132        return cmp(self.__dict__,other.__dict__)
    117133
    118134class DocTestController(SageObject):
    119135    """
     
    166182            options.nthreads = 1
    167183        if options.serial:
    168184            options.nthreads = 1
     185        if options.verbose:
     186            options.show_skipped = True
    169187
     188        if isinstance(options.optional, basestring):
     189            if options.optional.lower() in ['all', 'true']:
     190                options.optional = True
     191            else:
     192                options.optional = set(options.optional.lower().split(','))
    170193        self.options = options
    171194        self.files = args
    172195        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        We check that files are skipped appropriately::
     
    462485                else:
    463486                    # the user input this file explicitly, so we don't skip it
    464487                    yield path
    465         if self.options.optional == 'all':
    466             optionals = True
    467         else:
    468             optionals = set(self.options.optional.lower().split(','))
    469         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()]
     488        self.sources = [FileDocTestSource(path, self.options) for path in expand()]
    470489
    471490    def filter_sources(self):
    472491        """
     
    690709            sage: DD = DocTestDefaults(valgrind=True, optional="all", timeout=172800)
    691710            sage: DC = DocTestController(DD, ["hello_world.py"])
    692711            sage: DC.run_val_gdb(testing=True)
    693             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
     712            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
    694713        """
    695714        try:
    696715            sage_cmd = self._assemble_cmd()
  • sage/doctest/forker.py

    diff --git a/sage/doctest/forker.py b/sage/doctest/forker.py
    a b  
    384384            sage: import doctest, sys, os
    385385            sage: DTR = SageDocTestRunner(SageOutputChecker(), verbose=False, sage_options=DD, optionflags=doctest.NORMALIZE_WHITESPACE|doctest.ELLIPSIS)
    386386            sage: filename = os.path.join(os.environ['SAGE_ROOT'],'devel','sage','sage','doctest','forker.py')
    387             sage: FDS = FileDocTestSource(filename,True,False,set(['sage']),None)
     387            sage: FDS = FileDocTestSource(filename,DD)
    388388            sage: doctests, extras = FDS.create_doctests(globals())
    389389            sage: DTR.run(doctests[0], clear_globs=False) # indirect doctest
    390390            TestResults(failed=0, attempted=4)
     
    559559            sage: import doctest, sys, os
    560560            sage: DTR = SageDocTestRunner(SageOutputChecker(), verbose=False, sage_options=DD, optionflags=doctest.NORMALIZE_WHITESPACE|doctest.ELLIPSIS)
    561561            sage: filename = os.path.join(os.environ['SAGE_ROOT'],'devel','sage','sage','doctest','forker.py')
    562             sage: FDS = FileDocTestSource(filename,True,False,set(['sage']),None)
     562            sage: FDS = FileDocTestSource(filename,DD)
    563563            sage: doctests, extras = FDS.create_doctests(globals())
    564564            sage: DTR.run(doctests[0], clear_globs=False)
    565565            TestResults(failed=0, attempted=4)
     
    703703            sage: import doctest, sys, os, hashlib
    704704            sage: DTR = SageDocTestRunner(SageOutputChecker(), verbose=False, sage_options=DD, optionflags=doctest.NORMALIZE_WHITESPACE|doctest.ELLIPSIS)
    705705            sage: filename = os.path.join(os.environ['SAGE_ROOT'],'devel','sage','sage','doctest','forker.py')
    706             sage: FDS = FileDocTestSource(filename,True,False,set(['sage']),None)
     706            sage: FDS = FileDocTestSource(filename,DD)
    707707            sage: doctests, extras = FDS.create_doctests(globals())
    708708            sage: DTR.running_global_digest.hexdigest()
    709709            'd41d8cd98f00b204e9800998ecf8427e'
     
    761761            sage: DTR = SageDocTestRunner(SageOutputChecker(), verbose=False, sage_options=DD, optionflags=doctest.NORMALIZE_WHITESPACE|doctest.ELLIPSIS)
    762762            sage: DTR.running_doctest_digest = hashlib.md5()
    763763            sage: filename = os.path.join(os.environ['SAGE_ROOT'],'devel','sage','sage','doctest','forker.py')
    764             sage: FDS = FileDocTestSource(filename,True,False,set(['sage']),None)
     764            sage: FDS = FileDocTestSource(filename,DD)
    765765            sage: globs = RecordingDict(globals())
    766766            sage: globs.has_key('doctest_var')
    767767            False
     
    850850            sage: import doctest, sys, os
    851851            sage: DTR = SageDocTestRunner(SageOutputChecker(), verbose=False, sage_options=DD, optionflags=doctest.NORMALIZE_WHITESPACE|doctest.ELLIPSIS)
    852852            sage: filename = os.path.join(os.environ['SAGE_ROOT'],'devel','sage','sage','doctest','forker.py')
    853             sage: FDS = FileDocTestSource(filename,True,False,set(['sage']),None)
     853            sage: FDS = FileDocTestSource(filename,DD)
    854854            sage: doctests, extras = FDS.create_doctests(globals())
    855855            sage: ex = doctests[0].examples[0]
    856856            sage: print DTR._failure_header(doctests[0], ex)
     
    898898            sage: import doctest, sys, os
    899899            sage: DTR = SageDocTestRunner(SageOutputChecker(), verbose=True, sage_options=DD, optionflags=doctest.NORMALIZE_WHITESPACE|doctest.ELLIPSIS)
    900900            sage: filename = os.path.join(os.environ['SAGE_ROOT'],'devel','sage','sage','doctest','forker.py')
    901             sage: FDS = FileDocTestSource(filename,True,False,set(['sage']),None)
     901            sage: FDS = FileDocTestSource(filename,DD)
    902902            sage: doctests, extras = FDS.create_doctests(globals())
    903903            sage: ex = doctests[0].examples[0]
    904904            sage: DTR.report_start(sys.stdout.write, doctests[0], ex)
     
    945945            sage: import doctest, sys, os
    946946            sage: DTR = SageDocTestRunner(SageOutputChecker(), verbose=True, sage_options=DD, optionflags=doctest.NORMALIZE_WHITESPACE|doctest.ELLIPSIS)
    947947            sage: filename = os.path.join(os.environ['SAGE_ROOT'],'devel','sage','sage','doctest','forker.py')
    948             sage: FDS = FileDocTestSource(filename,True,False,set(['sage']),None)
     948            sage: FDS = FileDocTestSource(filename,DD)
    949949            sage: doctests, extras = FDS.create_doctests(globals())
    950950            sage: ex = doctests[0].examples[0]
    951951            sage: ex.walltime = 0.0
     
    985985            sage: import doctest, sys, os
    986986            sage: DTR = SageDocTestRunner(SageOutputChecker(), verbose=True, sage_options=DD, optionflags=doctest.NORMALIZE_WHITESPACE|doctest.ELLIPSIS)
    987987            sage: filename = os.path.join(os.environ['SAGE_ROOT'],'devel','sage','sage','doctest','forker.py')
    988             sage: FDS = FileDocTestSource(filename,True,False,set(['sage']),None)
     988            sage: FDS = FileDocTestSource(filename,DD)
    989989            sage: doctests, extras = FDS.create_doctests(globals())
    990990            sage: ex = doctests[0].examples[0]
    991991            sage: DTR.no_failure_yet = True
     
    10321032            sage: import doctest, sys, os
    10331033            sage: DTR = SageDocTestRunner(SageOutputChecker(), verbose=True, sage_options=DD, optionflags=doctest.NORMALIZE_WHITESPACE|doctest.ELLIPSIS)
    10341034            sage: filename = os.path.join(os.environ['SAGE_ROOT'],'devel','sage','sage','doctest','forker.py')
    1035             sage: FDS = FileDocTestSource(filename,True,False,set(['sage']),None)
     1035            sage: FDS = FileDocTestSource(filename,DD)
    10361036            sage: doctests, extras = FDS.create_doctests(globals())
    10371037            sage: ex = doctests[0].examples[0]
    10381038            sage: ex.walltime = 1.23
     
    11501150            sage: import doctest, sys, os
    11511151            sage: DTR = SageDocTestRunner(SageOutputChecker(), verbose=False, sage_options=DD, optionflags=doctest.NORMALIZE_WHITESPACE|doctest.ELLIPSIS)
    11521152            sage: filename = os.path.join(os.environ['SAGE_ROOT'],'devel','sage','sage','doctest','forker.py')
    1153             sage: FDS = FileDocTestSource(filename,True,False,set(['sage']),None)
     1153            sage: FDS = FileDocTestSource(filename,DD)
    11541154            sage: doctests, extras = FDS.create_doctests(globals())
    11551155            sage: from sage.doctest.util import Timer
    11561156            sage: T = Timer().start()
     
    15621562        sage: from sage.doctest.control import DocTestController, DocTestDefaults
    15631563        sage: filename = os.path.join(os.environ['SAGE_ROOT'],'devel','sage','sage','doctest','util.py')
    15641564        sage: DD = DocTestDefaults()
    1565         sage: FDS = FileDocTestSource(filename,True,False,set(['sage']),None)
     1565        sage: FDS = FileDocTestSource(filename,DD)
    15661566        sage: W = DocTestWorker(FDS, DD)
    15671567        sage: W.start()
    15681568        sage: DC = DocTestController(DD, filename)
     
    16831683            sage: from sage.doctest.control import DocTestController, DocTestDefaults
    16841684            sage: filename = os.path.join(os.environ['SAGE_ROOT'],'devel','sage','sage','doctest','util.py')
    16851685            sage: DD = DocTestDefaults()
    1686             sage: FDS = FileDocTestSource(filename,True,False,set(['sage']),None)
     1686            sage: FDS = FileDocTestSource(filename,DD)
    16871687            sage: W = DocTestWorker(FDS, DD)
    16881688            sage: W.start()
    16891689            sage: try:
     
    17221722            sage: from sage.doctest.control import DocTestController, DocTestDefaults
    17231723            sage: filename = os.path.join(os.environ['SAGE_ROOT'],'devel','sage','sage','doctest','util.py')
    17241724            sage: DD = DocTestDefaults(verbose=True,nthreads=2)
    1725             sage: FDS = FileDocTestSource(filename,True,False,set(['sage']),None)
     1725            sage: FDS = FileDocTestSource(filename,DD)
    17261726            sage: W = DocTestWorker(FDS, DD)
    17271727            sage: W.start()
    17281728            sage: while W.rmessages is not None:
     
    17561756            sage: from sage.doctest.control import DocTestController, DocTestDefaults
    17571757            sage: filename = os.path.join(os.environ['SAGE_ROOT'],'devel','sage','sage','doctest','util.py')
    17581758            sage: DD = DocTestDefaults()
    1759             sage: FDS = FileDocTestSource(filename,True,False,set(['sage']),None)
     1759            sage: FDS = FileDocTestSource(filename,DD)
    17601760            sage: W = DocTestWorker(FDS, DD)
    17611761            sage: W.start()
    17621762            sage: W.join()
    17631763            sage: W.save_result_output()
    17641764            sage: sorted(W.result[1].keys())
    1765             ['cputime', 'err', 'failures', 'walltime']
     1765            ['cputime', 'err', 'failures', 'optionals', 'walltime']
    17661766            sage: len(W.output) > 0
    17671767            True
    17681768        """
     
    17921792            sage: from sage.doctest.control import DocTestController, DocTestDefaults
    17931793            sage: filename = os.path.join(os.environ['SAGE_ROOT'],'devel','sage','sage','doctest','tests','99seconds.rst')
    17941794            sage: DD = DocTestDefaults()
    1795             sage: FDS = FileDocTestSource(filename,True,False,set(['sage']),None)
     1795            sage: FDS = FileDocTestSource(filename,DD)
    17961796
    17971797        We set up the worker to start by blocking ``SIGHUP``, such that
    17981798        killing will fail initially::
     
    18461846        sage: from sage.doctest.control import DocTestDefaults, DocTestController
    18471847        sage: import os
    18481848        sage: filename = os.path.join(os.environ['SAGE_ROOT'],'devel','sage','sage','doctest','sources.py')
    1849         sage: FDS = FileDocTestSource(filename,True,False,set(['sage']),None)
     1849        sage: DD = DocTestDefaults()
     1850        sage: FDS = FileDocTestSource(filename,DD)
    18501851        sage: DTT = DocTestTask(FDS)
    1851         sage: DD = DocTestDefaults()
    18521852        sage: DC = DocTestController(DD,[filename])
    18531853        sage: ntests, results = DTT(options=DD)
    18541854        sage: ntests
    1855         275
     1855        309
    18561856        sage: sorted(results.keys())
    1857         ['cputime', 'err', 'failures', 'walltime']
     1857        ['cputime', 'err', 'failures', 'optionals', 'walltime']
    18581858    """
    18591859    def __init__(self, source):
    18601860        """
     
    18641864
    18651865            sage: from sage.doctest.forker import DocTestTask
    18661866            sage: from sage.doctest.sources import FileDocTestSource
     1867            sage: from sage.doctest.control import DocTestDefaults
    18671868            sage: import os
    18681869            sage: filename = os.path.join(os.environ['SAGE_ROOT'],'devel','sage','sage','doctest','sources.py')
    1869             sage: FDS = FileDocTestSource(filename,True,False,set(['sage']),None)
     1870            sage: FDS = FileDocTestSource(filename,DocTestDefaults())
    18701871            sage: DocTestTask(FDS)
    18711872            <sage.doctest.forker.DocTestTask object at ...>
    18721873        """
     
    19051906            sage: from sage.doctest.control import DocTestDefaults, DocTestController
    19061907            sage: import os
    19071908            sage: filename = os.path.join(os.environ['SAGE_ROOT'],'devel','sage','sage','doctest','parsing.py')
    1908             sage: FDS = FileDocTestSource(filename,True,False,set(['sage']),None)
     1909            sage: DD = DocTestDefaults()
     1910            sage: FDS = FileDocTestSource(filename,DD)
    19091911            sage: DTT = DocTestTask(FDS)
    1910             sage: DD = DocTestDefaults()
    19111912            sage: DC = DocTestController(DD, [filename])
    19121913            sage: ntests, runner = DTT(options=DD)
    19131914            sage: runner.failures
    19141915            0
    19151916            sage: ntests
    1916             202
     1917            206
    19171918        """
    19181919        result = None
    19191920        try:
     
    19471948            if extras['tab']:
    19481949                results.err = 'tab'
    19491950                results.tab_linenos = extras['tab']
     1951            results.optionals = extras['optionals']
    19501952            # We subtract 1 to remove the sig_on_count() tests
    19511953            result = (sum([max(0,len(test.examples) - 1) for test in doctests]), results)
    19521954        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
     
    275276    EXAMPLES::
    276277
    277278        sage: from sage.doctest.sources import FileDocTestSource
     279        sage: from sage.doctest.control import DocTestDefaults
    278280        sage: import os
    279281        sage: filename = os.path.join(os.environ['SAGE_ROOT'],'devel','sage','sage','doctest','forker.py')
    280         sage: FDS = FileDocTestSource(filename,True,False,set(['sage']),None)
     282        sage: FDS = FileDocTestSource(filename,DocTestDefaults())
    281283        sage: doctests, extras = FDS.create_doctests(globals())
    282284        sage: ex = doctests[0].examples[0]
    283285        sage: ex.sage_source
     
    300302        EXAMPLES::
    301303
    302304            sage: from sage.doctest.sources import FileDocTestSource
     305            sage: from sage.doctest.control import DocTestDefaults
    303306            sage: import os
    304307            sage: filename = os.path.join(os.environ['SAGE_ROOT'],'devel','sage','sage','doctest','forker.py')
    305             sage: FDS = FileDocTestSource(filename,True,False,set(['sage']),None)
     308            sage: FDS = FileDocTestSource(filename,DocTestDefaults())
    306309            sage: doctests, extras = FDS.create_doctests(globals())
    307310            sage: ex = doctests[0].examples[0]
    308311            sage: from sage.doctest.parsing import OriginalSource
     
    316319        EXAMPLES::
    317320
    318321            sage: from sage.doctest.sources import FileDocTestSource
     322            sage: from sage.doctest.control import DocTestDefaults
    319323            sage: import os
    320324            sage: filename = os.path.join(os.environ['SAGE_ROOT'],'devel','sage','sage','doctest','forker.py')
    321             sage: FDS = FileDocTestSource(filename,True,False,set(['sage']),None)
     325            sage: FDS = FileDocTestSource(filename,DocTestDefaults())
    322326            sage: doctests, extras = FDS.create_doctests(globals())
    323327            sage: ex = doctests[0].examples[0]
    324328            sage: from sage.doctest.parsing import OriginalSource
     
    335339        EXAMPLES::
    336340
    337341            sage: from sage.doctest.sources import FileDocTestSource
     342            sage: from sage.doctest.control import DocTestDefaults
    338343            sage: import os
    339344            sage: filename = os.path.join(os.environ['SAGE_ROOT'],'devel','sage','sage','doctest','forker.py')
    340             sage: FDS = FileDocTestSource(filename,True,False,set(['sage']),None)
     345            sage: FDS = FileDocTestSource(filename,DocTestDefaults())
    341346            sage: doctests, extras = FDS.create_doctests(globals())
    342347            sage: ex = doctests[0].examples[0]
    343348            sage: from sage.doctest.parsing import OriginalSource
     
    379384            sage: TestSuite(DTP).run()
    380385        """
    381386        self.long = long
     387        self.optionals = collections.defaultdict(int) # record skipped optional tests
    382388        if optional_tags is True: # run all optional tests
    383389            self.optional_tags = True
    384390            self.optional_only = False
     
    506512            if isinstance(item, doctest.Example):
    507513                optional_tags = parse_optional_tags(item.source)
    508514                if optional_tags:
     515                    if '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
     518                    for tag in optional_tags:
     519                        self.optionals[tag] += 1
    509520                    if ('not implemented' in optional_tags) or ('not tested' in optional_tags):
    510521                        continue
    511                     elif 'known bug' in optional_tags:
    512                         optional_tags.remove('known bug')
    513                         optional_tags.add('bug') # so that such tests will be run by sage -t ... -only-optional=bug
    514522                    if 'long time' in optional_tags:
    515523                        if self.long:
    516524                            optional_tags.remove('long time')
  • sage/doctest/reporting.py

    diff --git a/sage/doctest/reporting.py b/sage/doctest/reporting.py
    a b  
    123123            sage: from sage.doctest.sources import FileDocTestSource
    124124            sage: from sage.doctest.forker import SageDocTestRunner
    125125            sage: filename = os.path.join(os.environ['SAGE_ROOT'],'devel','sage','sage','doctest','reporting.py')
    126             sage: FDS = FileDocTestSource(filename,True,False,set(['sage']),None)
    127126            sage: DD = DocTestDefaults()
     127            sage: FDS = FileDocTestSource(filename,DD)
    128128            sage: DC = DocTestController(DD, [filename])
    129129            sage: DTR = DocTestReporter(DC)
    130130            sage: print DTR.report_head(FDS)
     
    183183            sage: from sage.doctest.forker import SageDocTestRunner
    184184            sage: from sage.doctest.parsing import SageOutputChecker
    185185            sage: from sage.doctest.util import Timer
    186             sage: import os, sys, doctest
     186            sage: import os, sys, doctest, collections
    187187            sage: filename = os.path.join(os.environ['SAGE_ROOT'],'devel','sage','sage','doctest','reporting.py')
    188             sage: FDS = FileDocTestSource(filename,True,False,set(['sage']),None)
    189188            sage: DD = DocTestDefaults()
     189            sage: FDS = FileDocTestSource(filename,DD)
    190190            sage: DC = DocTestController(DD,[filename])
    191191            sage: DTR = DocTestReporter(DC)
    192192
     
    266266            1
    267267            sage: DTR.report(FDS, False, 0, (sum([len(t.examples) for t in doctests]), D), "Doctest output including the failure...")
    268268                [... tests, 1 failure, 0.0 s]
     269
     270        If the user has requested that we report on skipped doctests,
     271        we do so::
     272
     273            sage: DC.options = DocTestDefaults(show_skipped = True)
     274            sage: optionals = collections.defaultdict(int)
     275            sage: optionals['magma'] = 5; optionals['long time'] = 4; optionals[''] = 1; optionals['not tested'] = 2
     276            sage: D = DictAsObject(dict(err=None,optionals=optionals))
     277            sage: runner.failures = 0
     278            sage: runner.update_results(D)
     279            0
     280            sage: DTR.report(FDS, False, 0, (sum([len(t.examples) for t in doctests]), D), "Good tests")
     281                1 unlabeled test not run
     282                4 long tests not run
     283                5 magma tests not run
     284                2 other tests skipped
     285                [... tests, 0.0 s]
     286
    269287        """
    270288        try:
    271289            log = self.controller.log
     
    376394                    postscript['cputime'] += cpu
    377395                    postscript['walltime'] += wall
    378396
     397                    if self.controller.options.show_skipped:
     398                        try:
     399                            optionals = result_dict.optionals
     400                        except AttributeError:
     401                            pass
     402                        else:
     403                            if self.controller.options.optional is not True: # if True we test all optional tags
     404                                tags = sorted(optionals.keys())
     405                                untested = optionals["not tested"] + optionals["not implemented"]
     406                                seen_other = False
     407                                for tag in tags:
     408                                    nskipped = optionals[tag]
     409                                    if tag == "long time":
     410                                        if not self.controller.options.long:
     411                                            seen_other = True
     412                                            log("    %s not run"%(count_noun(nskipped, "long test")))
     413                                    elif (tag not in self.controller.options.optional and
     414                                          tag not in ["not tested", "not implemented"]):
     415                                        seen_other = True
     416                                        if tag == "bug":
     417                                            log("    %s not run due to known bugs"%(count_noun(nskipped, "test")))
     418                                        elif tag == "":
     419                                            log("    %s not run"%(count_noun(nskipped, "unlabeled test")))
     420                                        else:
     421                                            log("    %s not run"%(count_noun(nskipped, tag + " test")))
     422                                if untested:
     423                                    log ("    %s skipped"%(count_noun(untested, "%stest"%("other " if seen_other else ""))))
    379424                    log("    [%s, %s%.1f s]" % (count_noun(ntests, "test"), "%s, "%(count_noun(f, "failure")) if f else "", wall))
    380425            self.sources_completed += 1
    381426
     
    399444            sage: from sage.doctest.util import Timer
    400445            sage: import os, sys, doctest
    401446            sage: filename = os.path.join(os.environ['SAGE_ROOT'],'devel','sage','sage','doctest','reporting.py')
    402             sage: FDS = FileDocTestSource(filename,True,False,set(['sage']),None)
    403447            sage: DD = DocTestDefaults()
     448            sage: FDS = FileDocTestSource(filename,DD)
    404449            sage: DC = DocTestController(DD,[filename])
    405450            sage: DTR = DocTestReporter(DC)
    406451
  • sage/doctest/sources.py

    diff --git a/sage/doctest/sources.py b/sage/doctest/sources.py
    a b  
    9797
    9898    INPUT:
    9999
    100     - ``long`` -- whether to execute tests marked as ``# long time``
    101 
    102     - ``optional`` -- either True or a set of optional tags to execute
    103 
    104     - ``randorder`` -- whether to execute the doctests in this source
    105       in a random order
     100    - ``options`` -- a :class:`sage.doctest.control.DocTestDefaults`
     101      instance or equivalent.
    106102    """
    107     def __init__(self, long, optional, randorder):
     103    def __init__(self, options):
    108104        """
    109105        Initialization.
    110106
    111107        EXAMPLES::
    112108
     109            sage: from sage.doctest.control import DocTestDefaults
    113110            sage: from sage.doctest.sources import FileDocTestSource
    114111            sage: import os
    115112            sage: filename = os.path.join(os.environ['SAGE_ROOT'],'devel','sage','sage','doctest','sources.py')
    116             sage: FDS = FileDocTestSource(filename,True,False,set(['sage']),0)
     113            sage: FDS = FileDocTestSource(filename,DocTestDefaults())
    117114            sage: TestSuite(FDS).run()
    118115        """
    119         self.long = long
    120         self.optional = optional
    121         self.randorder = randorder
     116        self.options = options
    122117
    123118    def __cmp__(self, other):
    124119        """
     
    126121
    127122        EXAMPLES::
    128123
     124            sage: from sage.doctest.control import DocTestDefaults
    129125            sage: from sage.doctest.sources import FileDocTestSource
    130126            sage: import os
    131127            sage: filename = os.path.join(os.environ['SAGE_ROOT'],'devel','sage','sage','doctest','sources.py')
    132             sage: FDS = FileDocTestSource(filename,True,False,set(['sage']),0)
    133             sage: FDS2 = FileDocTestSource(filename,True,False,set(['sage']),0)
     128            sage: DD = DocTestDefaults()
     129            sage: FDS = FileDocTestSource(filename,DD)
     130            sage: FDS2 = FileDocTestSource(filename,DD)
    134131            sage: FDS == FDS2
    135132            True
    136133        """
     
    164161
    165162        EXAMPLES::
    166163
     164            sage: from sage.doctest.control import DocTestDefaults
    167165            sage: from sage.doctest.sources import FileDocTestSource
    168166            sage: from sage.doctest.parsing import SageDocTestParser
    169167            sage: import os
    170168            sage: filename = os.path.join(os.environ['SAGE_ROOT'],'devel','sage','sage','doctest','util.py')
    171             sage: FDS = FileDocTestSource(filename,True,False,set(['sage']),None)
     169            sage: FDS = FileDocTestSource(filename,DocTestDefaults())
    172170            sage: doctests, _ = FDS.create_doctests({})
    173171            sage: manual_doctests = []
    174172            sage: for dt in doctests:
     
    213211
    214212        EXAMPLES::
    215213
     214            sage: from sage.doctest.control import DocTestDefaults
    216215            sage: from sage.doctest.sources import FileDocTestSource
    217216            sage: from sage.doctest.util import NestedName
    218217            sage: import os
    219218            sage: filename = os.path.join(os.environ['SAGE_ROOT'],'devel','sage','sage','doctest','sources.py')
    220             sage: FDS = FileDocTestSource(filename,True,False,set(['sage']),None)
     219            sage: FDS = FileDocTestSource(filename,DocTestDefaults())
    221220            sage: FDS.qualified_name = NestedName('sage.doctest.sources')
    222221            sage: doctests, extras = FDS._create_doctests({})
    223222            sage: len(doctests)
     
    229228            tab_okay = isinstance(self,TexSource)
    230229        self._init()
    231230        self.line_shift = 0
    232         self.parser = SageDocTestParser(self.long, self.optional)
     231        self.parser = SageDocTestParser(self.options.long, self.options.optional)
    233232        self.linking = False
    234233        doctests = []
    235234        in_docstring = False
     
    288287        if unparsed_doc:
    289288            self._process_doc(doctests, doc, namespace, start)
    290289
    291         if self.randorder is not None and self.randorder is not False:
     290        extras = dict(tab = not tab_okay and tab_locations,
     291                      optionals = self.parser.optionals)
     292        if self.options.randorder is not None and self.options.randorder is not False:
    292293            # we want to randomize even when self.randorder = 0
    293             random.seed(self.randorder)
     294            random.seed(self.options.randorder)
    294295            randomized = []
    295296            while len(doctests) > 0:
    296297                i = random.randint(0, len(doctests)-1)
    297298                randomized.append(doctests.pop(i))
    298             return randomized, {'tab':not tab_okay and tab_locations}
     299            return randomized, extras
    299300        else:
    300             return doctests, {'tab':not tab_okay and tab_locations}
     301            return doctests, extras
    301302
    302303class StringDocTestSource(DocTestSource):
    303304    """
     
    311312    - ``source`` -- a string, giving the source code to be parsed for
    312313      doctests.
    313314
    314     - ``long`` -- whether to execute tests marked as ``# long time``
    315 
    316     - ``optional`` -- either True or a set of optional tags to execute
    317 
    318     - ``randorder`` -- whether to execute the doctests in this string
    319       in a random order
     315    - ``options`` -- a :class:`sage.doctest.control.DocTestDefaults`
     316      or equivalent.
    320317
    321318    - ``printpath`` -- a string, to be used in place of a filename
    322319      when doctest failures are displayed.
     
    326323
    327324    EXAMPLES::
    328325
     326        sage: from sage.doctest.control import DocTestDefaults
    329327        sage: from sage.doctest.sources import StringDocTestSource, PythonSource
    330328        sage: from sage.structure.dynamic_class import dynamic_class
    331329        sage: s = "'''\n    sage: 2 + 2\n    4\n'''"
    332330        sage: PythonStringSource = dynamic_class('PythonStringSource',(StringDocTestSource, PythonSource))
    333         sage: PSS = PythonStringSource('<runtime>', s, False, set(['sage']), False, 'runtime')
     331        sage: PSS = PythonStringSource('<runtime>', s, DocTestDefaults(), 'runtime')
    334332        sage: dt, extras = PSS.create_doctests({})
    335333        sage: len(dt)
    336334        1
    337335        sage: extras['tab']
    338336        []
    339337    """
    340     def __init__(self, basename, source, long, optional, randorder, printpath, lineno_shift=0):
     338    def __init__(self, basename, source, options, printpath, lineno_shift=0):
    341339        """
    342340        Initialization
    343341
    344342        TESTS::
    345343
     344            sage: from sage.doctest.control import DocTestDefaults
    346345            sage: from sage.doctest.sources import StringDocTestSource, PythonSource
    347346            sage: from sage.structure.dynamic_class import dynamic_class
    348347            sage: s = "'''\n    sage: 2 + 2\n    4\n'''"
    349348            sage: PythonStringSource = dynamic_class('PythonStringSource',(StringDocTestSource, PythonSource))
    350             sage: PSS = PythonStringSource('<runtime>', s, False, set(['sage']), False, 'runtime')
     349            sage: PSS = PythonStringSource('<runtime>', s, DocTestDefaults(), 'runtime')
    351350            sage: TestSuite(PSS).run()
    352351        """
    353352        self.qualified_name = NestedName(basename)
    354353        self.printpath = printpath
    355354        self.source = source
    356355        self.lineno_shift = lineno_shift
    357         DocTestSource.__init__(self, long, optional, randorder)
     356        DocTestSource.__init__(self, options)
    358357
    359358    def __iter__(self):
    360359        """
     
    362361
    363362        EXAMPLES::
    364363
     364            sage: from sage.doctest.control import DocTestDefaults
    365365            sage: from sage.doctest.sources import StringDocTestSource, PythonSource
    366366            sage: from sage.structure.dynamic_class import dynamic_class
    367367            sage: s = "'''\n    sage: 2 + 2\n    4\n'''"
    368368            sage: PythonStringSource = dynamic_class('PythonStringSource',(StringDocTestSource, PythonSource))
    369             sage: PSS = PythonStringSource('<runtime>', s, False, set(['sage']), False, 'runtime')
     369            sage: PSS = PythonStringSource('<runtime>', s, DocTestDefaults(), 'runtime')
    370370            sage: for n, line in PSS:
    371371            ....:     print n, line,
    372372            0 '''
     
    394394
    395395        EXAMPLES::
    396396
     397            sage: from sage.doctest.control import DocTestDefaults
    397398            sage: from sage.doctest.sources import StringDocTestSource, PythonSource
    398399            sage: from sage.structure.dynamic_class import dynamic_class
    399400            sage: s = "'''\n    sage: 2 + 2\n    4\n'''"
    400401            sage: PythonStringSource = dynamic_class('PythonStringSource',(StringDocTestSource, PythonSource))
    401             sage: PSS = PythonStringSource('<runtime>', s, False, set(['sage']), False, 'runtime')
     402            sage: PSS = PythonStringSource('<runtime>', s, DocTestDefaults(), 'runtime')
    402403            sage: dt, tabs = PSS.create_doctests({})
    403404            sage: for t in dt:
    404405            ....:     print t.name, t.examples[0].sage_source
     
    414415
    415416    - ``path`` -- string, the filename
    416417
    417     - ``force_lib`` -- bool, whether this file shoule be considered
    418       part of the Sage library
    419 
    420     - ``long`` -- whether to execute tests marked as ``# long time``
    421 
    422     - ``optional`` -- either True or a set of optional tags to execute
    423 
    424     - ``randorder`` -- whether to execute the doctests in this file in
    425       a random order
    426 
    427     - ``useabspath`` -- bool (default: False), whether paths should be
    428       printed absolutely
     418    - ``options`` -- a :class:`sage.doctest.control.DocTestDefaults`
     419      instance or equivalent.
    429420
    430421    EXAMPLES::
    431422
     423        sage: from sage.doctest.control import DocTestDefaults
    432424        sage: from sage.doctest.sources import FileDocTestSource
    433425        sage: import os
    434426        sage: filename = os.path.join(os.environ['SAGE_ROOT'],'devel','sage','sage','doctest','sources.py')
    435         sage: FDS = FileDocTestSource(filename,True,False,set(['sage']),None)
     427        sage: FDS = FileDocTestSource(filename,DocTestDefaults())
    436428        sage: FDS.basename
    437429        'sage.doctest.sources'
    438430
     
    440432
    441433        sage: TestSuite(FDS).run()
    442434    """
    443     def __init__(self, path, force_lib, long, optional, randorder, useabspath=False):
     435    def __init__(self, path, options, useabspath=False):
    444436        """
    445437        Initialization.
    446438
    447439        EXAMPLES::
    448440
     441            sage: from sage.doctest.control import DocTestDefaults
    449442            sage: from sage.doctest.sources import FileDocTestSource
    450443            sage: import os
    451444            sage: filename = os.path.join(os.environ['SAGE_ROOT'],'devel','sage','sage','doctest','sources.py')
    452             sage: FDS = FileDocTestSource(filename,True,False,set(['sage']),0)
    453             sage: FDS.randorder
     445            sage: FDS = FileDocTestSource(filename,DocTestDefaults(randorder=0))
     446            sage: FDS.options.randorder
    454447            0
    455448        """
    456449        self.path = path
    457         self.force_lib = force_lib
    458         DocTestSource.__init__(self, long, optional, randorder)
     450        DocTestSource.__init__(self, options)
    459451        self.useabspath = useabspath
    460452        base, ext = os.path.splitext(path)
    461453        if ext in ('.py', '.pyx', '.pxi', '.sage', '.spyx'):
     
    471463
    472464        EXAMPLES::
    473465
     466            sage: from sage.doctest.control import DocTestDefaults
    474467            sage: from sage.doctest.sources import FileDocTestSource
    475468            sage: filename = tmp_filename(ext=".py")
    476469            sage: s = "'''\n    sage: 2 + 2\n    4\n'''"
    477470            sage: open(filename, 'w').write(s)
    478             sage: FDS = FileDocTestSource(filename, False, False, set(['sage']), False)
     471            sage: FDS = FileDocTestSource(filename, DocTestDefaults())
    479472            sage: for n, line in FDS:
    480473            ....:     print n, line,
    481474            0 '''
     
    494487
    495488        EXAMPLES::
    496489
     490            sage: from sage.doctest.control import DocTestDefaults
    497491            sage: from sage.doctest.sources import FileDocTestSource
    498492            sage: import os
    499493            sage: br = os.readlink(os.path.join(os.environ['SAGE_ROOT'], 'devel', 'sage'))
     
    501495            sage: filename = os.path.join(root,'doctest','sources.py')
    502496            sage: cwd = os.getcwd()
    503497            sage: os.chdir(root)
    504             sage: FDS = FileDocTestSource(filename,True,False,set(['sage']),0)
     498            sage: FDS = FileDocTestSource(filename,DocTestDefaults(randorder=0,abspath=False))
    505499            sage: FDS.printpath
    506500            'doctest/sources.py'
    507             sage: FDS = FileDocTestSource(filename,True,False,set(['sage']),0,useabspath=True)
     501            sage: FDS = FileDocTestSource(filename,DocTestDefaults(randorder=0,abspath=True))
    508502            sage: FDS.printpath
    509503            '.../sage/doctest/sources.py'
    510504            sage: os.chdir(cwd)
    511505        """
    512         if self.useabspath:
     506        if self.options.abspath:
    513507            return os.path.abspath(self.path)
    514508        else:
    515509            relpath = os.path.relpath(self.path)
     
    525519
    526520        EXAMPLES::
    527521
     522            sage: from sage.doctest.control import DocTestDefaults
    528523            sage: from sage.doctest.sources import FileDocTestSource
    529524            sage: import os
    530525            sage: filename = os.path.join(os.environ['SAGE_ROOT'],'devel','sage','sage','rings','integer.pyx')
    531             sage: FDS = FileDocTestSource(filename,False,False,set(['sage']),None)
     526            sage: FDS = FileDocTestSource(filename,DocTestDefaults())
    532527            sage: FDS.basename
    533528            'sage.rings.integer'
    534529        """
     
    543538
    544539        EXAMPLES::
    545540
     541            sage: from sage.doctest.control import DocTestDefaults
    546542            sage: from sage.doctest.sources import FileDocTestSource
    547543            sage: import os
    548544            sage: filename = os.path.join(os.environ['SAGE_ROOT'],'devel','sage','sage','rings','integer.pyx')
    549             sage: FDS = FileDocTestSource(filename,False,False,set(['sage']),None)
     545            sage: FDS = FileDocTestSource(filename,DocTestDefaults())
    550546            sage: FDS.in_lib
    551547            True
    552548
    553549        You can override the default::
    554550
    555             sage: FDS = FileDocTestSource("hello_world.py",False,False,set(['sage']),None)
     551            sage: FDS = FileDocTestSource("hello_world.py",DocTestDefaults())
    556552            sage: FDS.in_lib
    557553            False
    558             sage: FDS = FileDocTestSource("hello_world.py",True,False,set(['sage']),None)
     554            sage: FDS = FileDocTestSource("hello_world.py",DocTestDefaults(force_lib=True))
     555            sage: FDS.in_lib
     556            True
    559557        """
    560         return (self.force_lib or
     558        return (self.options.force_lib or
    561559                self.basename.startswith('sage.') or
    562560                self.basename.startswith('doc.') or
    563561                self.basename.startswith('sagenb.'))
     
    578576
    579577        EXAMPLES::
    580578
     579            sage: from sage.doctest.control import DocTestDefaults
    581580            sage: from sage.doctest.sources import FileDocTestSource
    582581            sage: import os
    583582            sage: filename = os.path.join(os.environ['SAGE_ROOT'],'devel','sage','sage','doctest','sources.py')
    584             sage: FDS = FileDocTestSource(filename,True,False,set(['sage']),None)
     583            sage: FDS = FileDocTestSource(filename,DocTestDefaults())
    585584            sage: doctests, extras = FDS.create_doctests(globals())
    586585            sage: len(doctests)
    587586            40
     
    592591
    593592            sage: doctests[17].name
    594593            'sage.doctest.sources.FileDocTestSource.create_doctests'
    595             sage: doctests[17].examples[8].source
    596             'doctests[Integer(17)].examples[Integer(8)].source\n'
     594            sage: doctests[17].examples[9].source
     595            'doctests[Integer(17)].examples[Integer(9)].source\n'
    597596
    598597        TESTS:
    599598
     
    605604            sage: n = -920390823904823094890238490238484; hash(n) > 0
    606605            False # 32-bit
    607606            True  # 64-bit
    608             sage: ex = doctests[17].examples[11]
     607            sage: ex = doctests[17].examples[12]
    609608            sage: (bitness == '64' and ex.want == 'True  \n') or (bitness == '32' and ex.want == 'False \n')
    610609            True
    611610
     
    647646
    648647        TESTS::
    649648
     649            sage: from sage.doctest.control import DocTestDefaults
    650650            sage: from sage.doctest.sources import FileDocTestSource
    651651            sage: cwd = os.getcwd()
    652652            sage: os.chdir(os.path.join(os.environ['SAGE_ROOT'],'devel','sage'))
     
    658658            ....:         _, ext = os.path.splitext(F)
    659659            ....:         if ext in ('.py', '.pyx', '.sage', '.spyx', '.rst'):
    660660            ....:             filename = os.path.join(path, F)
    661             ....:             FDS = FileDocTestSource(filename, True, True, True, False)
     661            ....:             FDS = FileDocTestSource(filename, DocTestDefaults(long=True,optional=True))
    662662            ....:             FDS._test_enough_doctests(verbose=False)
    663663            There are 18 tests in sage/combinat/partition.py that are not being run
    664664            There are 12 tests in sage/combinat/tableau.py that are not being run
    665665            There are 3 unexpected tests being run in sage/doctest/parsing.py
     666            There are 1 unexpected tests being run in sage/doctest/reporting.py
    666667            There are 1 tests in sage/ext/c_lib.pyx that are not being run
    667668            There are 9 tests in sage/graphs/graph_plot.py that are not being run
    668669            There are 2 tests in sage/server/notebook/worksheet.py that are not being run
     
    751752
    752753        EXAMPLES::
    753754
     755            sage: from sage.doctest.control import DocTestDefaults
    754756            sage: from sage.doctest.sources import FileDocTestSource
    755757            sage: from sage.doctest.parsing import SageDocTestParser
    756758            sage: from sage.doctest.util import NestedName
    757759            sage: import os
    758760            sage: filename = os.path.join(os.environ['SAGE_ROOT'],'devel','sage','sage','doctest','util.py')
    759             sage: FDS = FileDocTestSource(filename,True,False,set(['sage']),None)
     761            sage: FDS = FileDocTestSource(filename,DocTestDefaults())
    760762            sage: doctests, _ = FDS.create_doctests({})
    761763            sage: for dt in doctests:
    762764            ....:     FDS.qualified_name = dt.name
     
    772774
    773775    EXAMPLES::
    774776
     777        sage: from sage.doctest.control import DocTestDefaults
    775778        sage: from sage.doctest.sources import FileDocTestSource
    776779        sage: import os
    777780        sage: filename = os.path.join(os.environ['SAGE_ROOT'],'devel','sage','sage','doctest','sources.py')
    778         sage: FDS = FileDocTestSource(filename,True,False,set(['sage']),None)
     781        sage: FDS = FileDocTestSource(filename,DocTestDefaults())
    779782        sage: type(FDS)
    780783        <class 'sage.doctest.sources.PythonFileSource'>
    781784    """
     
    788791
    789792        EXAMPLES::
    790793
     794            sage: from sage.doctest.control import DocTestDefaults
    791795            sage: from sage.doctest.sources import FileDocTestSource
    792796            sage: import os
    793797            sage: filename = os.path.join(os.environ['SAGE_ROOT'],'devel','sage','sage','doctest','sources.py')
    794             sage: FDS = FileDocTestSource(filename,True,False,set(['sage']),None)
     798            sage: FDS = FileDocTestSource(filename,DocTestDefaults())
    795799            sage: FDS._init()
    796800            sage: FDS.last_indent
    797801            -1
     
    823827
    824828        EXAMPLES::
    825829
     830            sage: from sage.doctest.control import DocTestDefaults
    826831            sage: from sage.doctest.sources import FileDocTestSource
    827832            sage: import os
    828833            sage: filename = os.path.join(os.environ['SAGE_ROOT'],'devel','sage','sage','doctest','sources.py')
    829             sage: FDS = FileDocTestSource(filename,True,False,set(['sage']),None)
     834            sage: FDS = FileDocTestSource(filename,DocTestDefaults())
    830835            sage: FDS._init()
    831836            sage: FDS._update_quotetype('\"\"\"'); print " ".join(list(FDS.quotetype))
    832837            " " "
     
    917922
    918923        EXAMPLES::
    919924
     925            sage: from sage.doctest.control import DocTestDefaults
    920926            sage: from sage.doctest.sources import FileDocTestSource
    921927            sage: from sage.doctest.util import NestedName
    922928            sage: import os
    923929            sage: filename = os.path.join(os.environ['SAGE_ROOT'],'devel','sage','sage','doctest','sources.py')
    924             sage: FDS = FileDocTestSource(filename,True,False,set(['sage']),None)
     930            sage: FDS = FileDocTestSource(filename,DocTestDefaults())
    925931            sage: FDS._init()
    926932            sage: FDS.starting_docstring("r'''")
    927933            <_sre.SRE_Match object at ...>
     
    981987
    982988        EXAMPLES::
    983989
     990            sage: from sage.doctest.control import DocTestDefaults
    984991            sage: from sage.doctest.sources import FileDocTestSource
    985992            sage: from sage.doctest.util import NestedName
    986993            sage: import os
    987994            sage: filename = os.path.join(os.environ['SAGE_ROOT'],'devel','sage','sage','doctest','sources.py')
    988             sage: FDS = FileDocTestSource(filename,True,False,set(['sage']),None)
     995            sage: FDS = FileDocTestSource(filename,DocTestDefaults())
    989996            sage: FDS._init()
    990997            sage: FDS.quotetype = "'''"
    991998            sage: FDS.ending_docstring("'''")
     
    10151022
    10161023        EXAMPLES::
    10171024
     1025            sage: from sage.doctest.control import DocTestDefaults
    10181026            sage: from sage.doctest.sources import StringDocTestSource, PythonSource
    10191027            sage: from sage.structure.dynamic_class import dynamic_class
    10201028            sage: s = "'''\n    sage: 2 + 2\n    4\n'''"
    10211029            sage: PythonStringSource = dynamic_class('PythonStringSource',(StringDocTestSource, PythonSource))
    1022             sage: PSS = PythonStringSource('<runtime>', s, False, set(['sage']), False, 'runtime')
     1030            sage: PSS = PythonStringSource('<runtime>', s, DocTestDefaults(), 'runtime')
    10231031            sage: print PSS._neutralize_doctests(0),
    10241032            '''
    10251033                safe: 2 + 2
     
    10491057
    10501058    EXAMPLES::
    10511059
     1060        sage: from sage.doctest.control import DocTestDefaults
    10521061        sage: from sage.doctest.sources import FileDocTestSource
    10531062        sage: filename = "sage_paper.tex"
    1054         sage: FDS = FileDocTestSource(filename,False,False,set(['sage']),None)
     1063        sage: FDS = FileDocTestSource(filename,DocTestDefaults())
    10551064        sage: type(FDS)
    10561065        <class 'sage.doctest.sources.TexFileSource'>
    10571066    """
     
    10641073
    10651074        EXAMPLES::
    10661075
     1076            sage: from sage.doctest.control import DocTestDefaults
    10671077            sage: from sage.doctest.sources import FileDocTestSource
    10681078            sage: filename = "sage_paper.tex"
    1069             sage: FDS = FileDocTestSource(filename,False,False,set(['sage']),None)
     1079            sage: FDS = FileDocTestSource(filename,DocTestDefaults())
    10701080            sage: FDS._init()
    10711081            sage: FDS.skipping
    10721082            False
     
    10951105
    10961106        EXAMPLES::
    10971107
     1108            sage: from sage.doctest.control import DocTestDefaults
    10981109            sage: from sage.doctest.sources import FileDocTestSource
    10991110            sage: filename = "sage_paper.tex"
    1100             sage: FDS = FileDocTestSource(filename,False,False,set(['sage']),None)
     1111            sage: FDS = FileDocTestSource(filename,DocTestDefaults())
    11011112            sage: FDS._init()
    11021113
    11031114        We start docstrings with \begin{verbatim}::
     
    11711182
    11721183        EXAMPLES::
    11731184
     1185            sage: from sage.doctest.control import DocTestDefaults
    11741186            sage: from sage.doctest.sources import FileDocTestSource
    11751187            sage: filename = "sage_paper.tex"
    1176             sage: FDS = FileDocTestSource(filename,False,False,set(['sage']),None)
     1188            sage: FDS = FileDocTestSource(filename,DocTestDefaults())
    11771189            sage: FDS._init()
    11781190            sage: FDS.ending_docstring(r"\end{verbatim}")
    11791191            True
     
    12111223
    12121224    EXAMPLES::
    12131225
     1226        sage: from sage.doctest.control import DocTestDefaults
    12141227        sage: from sage.doctest.sources import FileDocTestSource
    12151228        sage: filename = "sage_doc.rst"
    1216         sage: FDS = FileDocTestSource(filename,False,False,set(['sage']),None)
     1229        sage: FDS = FileDocTestSource(filename,DocTestDefaults())
    12171230        sage: type(FDS)
    12181231        <class 'sage.doctest.sources.RestFileSource'>
    12191232    """
     
    12261239
    12271240        EXAMPLES::
    12281241
     1242            sage: from sage.doctest.control import DocTestDefaults
    12291243            sage: from sage.doctest.sources import FileDocTestSource
    12301244            sage: filename = "sage_doc.rst"
    1231             sage: FDS = FileDocTestSource(filename,False,False,set(['sage']),None)
     1245            sage: FDS = FileDocTestSource(filename,DocTestDefaults())
    12321246            sage: FDS._init()
    12331247            sage: FDS.link_all
    12341248            False
     
    12561270
    12571271        EXAMPLES::
    12581272
     1273            sage: from sage.doctest.control import DocTestDefaults
    12591274            sage: from sage.doctest.sources import FileDocTestSource
    12601275            sage: filename = "sage_doc.rst"
    1261             sage: FDS = FileDocTestSource(filename,False,False,set(['sage']),None)
     1276            sage: FDS = FileDocTestSource(filename,DocTestDefaults())
    12621277            sage: FDS._init()
    12631278            sage: FDS.starting_docstring("Hello world::")
    12641279            True
     
    13141329
    13151330        EXAMPLES::
    13161331
     1332            sage: from sage.doctest.control import DocTestDefaults
    13171333            sage: from sage.doctest.sources import FileDocTestSource
    13181334            sage: filename = "sage_doc.rst"
    1319             sage: FDS = FileDocTestSource(filename,False,False,set(['sage']),None)
     1335            sage: FDS = FileDocTestSource(filename,DocTestDefaults())
    13201336            sage: FDS._init()
    13211337            sage: FDS.starting_docstring("Hello world::")
    13221338            True
     
    13581374
    13591375        EXAMPLES::
    13601376
     1377            sage: from sage.doctest.control import DocTestDefaults
    13611378            sage: from sage.doctest.sources import FileDocTestSource
    13621379            sage: from sage.doctest.parsing import SageDocTestParser
    13631380            sage: from sage.doctest.util import NestedName
    13641381            sage: filename = "sage_doc.rst"
    1365             sage: FDS = FileDocTestSource(filename,False,False,set(['sage']),None)
     1382            sage: FDS = FileDocTestSource(filename,DocTestDefaults())
    13661383            sage: FDS.parser = SageDocTestParser(False, set(['sage']))
    13671384            sage: FDS.qualified_name = NestedName('sage_doc')
    13681385            sage: s = "Some text::\n\n    def example_python_function(a, \
     
    13881405        min_indent = self.parser._min_indent(docstring)
    13891406        pysource = '\n'.join([l[min_indent:] for l in docstring.split('\n')])
    13901407        inner_source = PythonStringSource(self.basename, pysource,
    1391                                           self.long, self.optional, self.randorder,
     1408                                          self.options,
    13921409                                          self.printpath, lineno_shift=start+1)
    13931410        inner_doctests, _ = inner_source._create_doctests(namespace, True)
    13941411        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  
    216216    Doctesting 1 file.
    217217        Time out
    218218    4
     219
     220Test the ``--show-skipped`` option::
     221
     222    sage: subprocess.call(["sage", "-t", "--show-skipped", "show_skipped.rst"], cwd=tests_dir)
     223    Running doctests ...
     224    Doctesting 1 file.
     225    sage -t show_skipped.rst
     226        1 unlabeled test not run
     227        2 tests not run due to known bugs
     228        1 gap test not run
     229        1 long test not run
     230        1 other test skipped
     231        [1 test, ... s]
     232    ----------------------------------------------------------------------
     233    All tests passed!
     234    ----------------------------------------------------------------------
     235    ...
     236    0
     237
     238Optional tests are run correctly::
     239
     240    sage: subprocess.call(["sage", "-t", "--long", "--show-skipped", "--optional=sage,gap", "show_skipped.rst"], cwd=tests_dir)
     241    Running doctests ...
     242    Doctesting 1 file.
     243    sage -t show_skipped.rst
     244        1 unlabeled test not run
     245        2 tests not run due to known bugs
     246        1 other test skipped
     247        [3 tests, ... s]
     248    ----------------------------------------------------------------------
     249    All tests passed!
     250    ----------------------------------------------------------------------
     251    ...
     252    0
    219253"""
  • 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!