Ticket #13062: 13062.patch

File 13062.patch, 2.2 KB (added by roed, 9 years ago)
  • sage/doctest/control.py

    # HG changeset patch
    # User David Roe <roed.math@gmail.com>
    # Date 1363299872 21600
    # Node ID 4def9c442be395eca2ee36de31c775c58217e3ad
    # Parent  20299a82927b6d0ceb9a7856540be09d2de26c97
    Change parsing behavior for nodoctest flags at top of file.
    
    diff --git a/sage/doctest/control.py b/sage/doctest/control.py
    a b  
    2727from reporting import DocTestReporter
    2828from util import NestedName, Timer, count_noun, dict_difference
    2929
     30nodoctest_regex = re.compile(r'\s*(#+|%+|\.\.)\s*nodoctest')
    3031
    3132class DocTestDefaults(SageObject):
    3233    """
     
    391392            self.files.append(opj(sagenb_loc, 'sagenb'))
    392393
    393394    def expand_files_into_sources(self):
    394         """
     395        r"""
    395396        Expands ``self.files``, which may include directories, into a
    396397        list of :class:`sage.doctest.FileDocTestSource`
    397398
     
    417418            sage: DC.expand_files_into_sources()
    418419            sage: sorted(list(DC.sources[0].optional))
    419420            ['guava', 'magma']
     421
     422        We check that files are skipped appropriately::
     423
     424            sage: dirname = tmp_dir()
     425            sage: filename = os.path.join(dirname, 'not_tested.py')
     426            sage: with open(filename, 'w') as F:
     427            ....:     F.write("#"*80 + "\n\n\n\n## nodoctest\n    sage: 1+1\n    4")
     428            sage: DC = DocTestController(DD, [dirname])
     429            sage: DC.expand_files_into_sources()
     430            sage: DC.sources
     431            []
    420432        """
    421433        def skipdir(dirname):
    422434            if os.path.exists(os.path.join(dirname, "nodoctest.py")):
     
    430442            if ext not in ('.py', '.pyx', '.pxi', '.sage', '.spyx', '.rst', '.tex'):
    431443                return True
    432444            with open(filename) as F:
    433                 return 'nodoctest' in F.read(50)
     445                line_count = 0
     446                for line in F:
     447                    if nodoctest_regex.match(line):
     448                        return True
     449                    line_count += 1
     450                    if line_count >= 10:
     451                        return False
    434452        def expand():
    435453            for path in self.files:
    436454                if os.path.isdir(path):