Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
mkoeppe committed Feb 26, 2022
2 parents 73cf76d + e80c135 commit 511005c
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 13 deletions.
7 changes: 4 additions & 3 deletions src/bin/sage-runtests
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ if __name__ == "__main__":
parser.add_argument("-T", "--timeout", type=int, default=-1, help="timeout (in seconds) for doctesting one file, 0 for no timeout")
what = parser.add_mutually_exclusive_group()
what.add_argument("-a", "--all", action="store_true", default=False, help="test all files in the Sage library")
what.add_argument("--installed", action="store_true", default=False, help="test all installed modules of the Sage library")
parser.add_argument("--logfile", type=argparse.FileType('a'), metavar="FILE", help="log all output to FILE")

parser.add_argument("-l", "--long", action="store_true", default=False, help="include lines with the phrase 'long time'")
Expand Down Expand Up @@ -119,7 +120,7 @@ if __name__ == "__main__":
in_filenames = False
afterlog = False
for arg in sys.argv[1:]:
if arg in ('-n', '--new', '-a', '--all'):
if arg in ('-n', '--new', '-a', '--all', '--installed'):
need_filenames = False
elif need_filenames and not (afterlog or in_filenames) and os.path.exists(arg):
in_filenames = True
Expand All @@ -129,8 +130,8 @@ if __name__ == "__main__":

args = parser.parse_args(new_arguments)

if not args.filenames and not (args.all or args.new):
print('either use --new or --all or some filenames')
if not args.filenames and not (args.all or args.new or args.installed):
print('either use --new, --all, --installed, or some filenames')
sys.exit(2)

# Limit the number of threads to 2 to save system resources.
Expand Down
50 changes: 44 additions & 6 deletions src/sage/doctest/control.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ def __init__(self, **kwds):
self.serial = False
self.timeout = -1
self.all = False
self.installed = False
self.logfile = None
self.long = False
self.warn_long = -1.0
Expand Down Expand Up @@ -249,8 +250,12 @@ def skipfile(filename, tested_optional_tags=False):
sage: skipfile(filename, True)
False
"""
base, ext = os.path.splitext(filename)
if ext not in ('.py', '.pyx', '.pxd', '.pxi', '.sage', '.spyx', '.rst', '.tex'):
if filename.endswith('.rst.txt'):
ext = '.rst.txt'
else:
base, ext = os.path.splitext(filename)
# .rst.txt appear in the installed documentation in subdirectories named "_sources"
if ext not in ('.py', '.pyx', '.pxd', '.pxi', '.sage', '.spyx', '.rst', '.tex', '.rst.txt'):
return True
with open(filename) as F:
line_count = 0
Expand Down Expand Up @@ -724,15 +729,38 @@ def add_files(self):
Doctesting ...
"""
opj = os.path.join
from sage.env import SAGE_SRC, SAGE_DOC_SRC, SAGE_ROOT, SAGE_ROOT_GIT
from sage.env import SAGE_SRC, SAGE_DOC_SRC, SAGE_ROOT, SAGE_ROOT_GIT, SAGE_DOC
# SAGE_ROOT_GIT can be None on distributions which typically
# only have the SAGE_LOCAL install tree but not SAGE_ROOT
if SAGE_ROOT_GIT is not None:
have_git = os.path.isdir(SAGE_ROOT_GIT)
else:
have_git = False

def all_installed_modules():
self.log("Doctesting all installed modules of the Sage library.")
import sage
self.files.extend(sage.__path__)
try:
import sage_setup
self.files.extend(sage_setup.__path__)
except ImportError:
pass
try:
import sage_docbuild
self.files.extend(sage_docbuild.__path__)
except ImportError:
pass

def all_installed_doc():
if SAGE_DOC and os.path.isdir(SAGE_DOC):
self.log("Doctesting all installed documentation sources.")
self.files.append(SAGE_DOC)

def all_files():
if not SAGE_SRC:
return all_installed_modules()
self.log("Doctesting entire Sage library.")
self.files.append(opj(SAGE_SRC, 'sage'))
# Only test sage_setup and sage_docbuild if the relevant
# imports work. They may not work if not in a build
Expand All @@ -748,12 +776,22 @@ def all_files():
self.files.append(opj(SAGE_SRC, 'sage_docbuild'))
except ImportError:
pass
if os.path.isdir(SAGE_DOC_SRC):

def all_doc_sources():
if SAGE_DOC_SRC and os.path.isdir(SAGE_DOC_SRC):
self.log("Doctesting all documentation sources.")
self.files.append(SAGE_DOC_SRC)
else:
all_installed_doc()

if self.options.all or (self.options.new and not have_git):
self.log("Doctesting entire Sage library.")
if self.options.installed:
all_installed_modules()
all_installed_doc()

elif self.options.all or (self.options.new and not have_git):
all_files()
all_doc_sources()

elif self.options.new and have_git:
# Get all files changed in the working repo.
self.log("Doctesting files changed since last git commit")
Expand Down
11 changes: 7 additions & 4 deletions src/sage/doctest/sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ class FileDocTestSource(DocTestSource):
Traceback (most recent call last):
...
ValueError: unknown extension for the file to test (=...txtt),
valid extensions are: .py, .pyx, .pxd, .pxi, .sage, .spyx, .tex, .rst
valid extensions are: .py, .pyx, .pxd, .pxi, .sage, .spyx, .tex, .rst, .rst.txt
"""
def __init__(self, path, options):
Expand All @@ -525,19 +525,22 @@ def __init__(self, path, options):
"""
self.path = path
DocTestSource.__init__(self, options)
base, ext = os.path.splitext(path)
if path.endswith('.rst.txt'):
ext = '.rst.txt'
else:
base, ext = os.path.splitext(path)
valid_code_ext = ('.py', '.pyx', '.pxd', '.pxi', '.sage', '.spyx')
if ext in valid_code_ext:
self.__class__ = dynamic_class('PythonFileSource',(FileDocTestSource,PythonSource))
self.encoding = "utf-8"
elif ext == '.tex':
self.__class__ = dynamic_class('TexFileSource',(FileDocTestSource,TexSource))
self.encoding = "utf-8"
elif ext == '.rst':
elif ext == '.rst' or ext == '.rst.txt':
self.__class__ = dynamic_class('RestFileSource',(FileDocTestSource,RestSource))
self.encoding = "utf-8"
else:
valid_ext = ", ".join(valid_code_ext + ('.tex', '.rst'))
valid_ext = ", ".join(valid_code_ext + ('.tex', '.rst', '.rst.txt'))
raise ValueError("unknown extension for the file to test (={}),"
" valid extensions are: {}".format(path, valid_ext))

Expand Down

0 comments on commit 511005c

Please sign in to comment.