# 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
|
|
27 | 27 | from reporting import DocTestReporter |
28 | 28 | from util import NestedName, Timer, count_noun, dict_difference |
29 | 29 | |
| 30 | nodoctest_regex = re.compile(r'\s*(#+|%+|\.\.)\s*nodoctest') |
30 | 31 | |
31 | 32 | class DocTestDefaults(SageObject): |
32 | 33 | """ |
… |
… |
|
391 | 392 | self.files.append(opj(sagenb_loc, 'sagenb')) |
392 | 393 | |
393 | 394 | def expand_files_into_sources(self): |
394 | | """ |
| 395 | r""" |
395 | 396 | Expands ``self.files``, which may include directories, into a |
396 | 397 | list of :class:`sage.doctest.FileDocTestSource` |
397 | 398 | |
… |
… |
|
417 | 418 | sage: DC.expand_files_into_sources() |
418 | 419 | sage: sorted(list(DC.sources[0].optional)) |
419 | 420 | ['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 | [] |
420 | 432 | """ |
421 | 433 | def skipdir(dirname): |
422 | 434 | if os.path.exists(os.path.join(dirname, "nodoctest.py")): |
… |
… |
|
430 | 442 | if ext not in ('.py', '.pyx', '.pxi', '.sage', '.spyx', '.rst', '.tex'): |
431 | 443 | return True |
432 | 444 | 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 |
434 | 452 | def expand(): |
435 | 453 | for path in self.files: |
436 | 454 | if os.path.isdir(path): |