Skip to content
This repository was archived by the owner on Jan 30, 2023. It is now read-only.

Commit 07818e6

Browse files
committed
trac 30778: when a module is labeled "optional - xyz",
print a warning when doing introspection. Documentation: recommend that people document it if they add such a tag to a module.
1 parent b92e036 commit 07818e6

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

src/doc/en/developer/coding_basics.rst

+5
Original file line numberDiff line numberDiff line change
@@ -1074,6 +1074,11 @@ framework. Here is a comprehensive list:
10741074
This does not apply to files which are explicitly given
10751075
as command line arguments: those are always tested.
10761076

1077+
If you add such a line to a file, you are strongly encouraged
1078+
to add a note to the module-level documentation, saying that
1079+
the doctests in this file will be skipped unless the
1080+
appropriate conditions are met.
1081+
10771082
- **internet:** For lines that require an internet connection::
10781083

10791084
sage: oeis(60843) # optional - internet

src/sage/doctest/control.py

+10-3
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,11 @@ def skipfile(filename, tested_optional_tags=False):
216216
- ``tested_optional_tags`` - a list or tuple or set of optional tags to test,
217217
or ``False`` (no optional test) or ``True`` (all optional tests)
218218
219+
If ``filename`` contains a line of the form ``"# sage.doctest:
220+
optional - xyz")``, then this will return ``False`` if "xyz" is in
221+
``tested_optional_tags``. Otherwise, it returns the matching tag
222+
("optional - xyz").
223+
219224
EXAMPLES::
220225
221226
sage: from sage.doctest.control import skipfile
@@ -231,9 +236,11 @@ def skipfile(filename, tested_optional_tags=False):
231236
sage: with open(filename, "w") as f:
232237
....: _ = f.write("# sage.doctest: optional - xyz")
233238
sage: skipfile(filename, False)
239+
'optional - xyz'
240+
sage: bool(skipfile(filename, False))
234241
True
235242
sage: skipfile(filename, ['abc'])
236-
True
243+
'optional - xyz'
237244
sage: skipfile(filename, ['abc', 'xyz'])
238245
False
239246
sage: skipfile(filename, True)
@@ -252,11 +259,11 @@ def skipfile(filename, tested_optional_tags=False):
252259
m = optionalfiledirective_regex.match(line)
253260
if m:
254261
if tested_optional_tags is False:
255-
return True
262+
return m.group(2)
256263
optional_tags = parse_optional_tags('#' + m.group(2))
257264
extra = optional_tags - set(tested_optional_tags)
258265
if extra:
259-
return True
266+
return m.group(2)
260267
line_count += 1
261268
if line_count >= 10:
262269
break

src/sage/misc/sageinspect.py

+9
Original file line numberDiff line numberDiff line change
@@ -2031,6 +2031,15 @@ def sage_getdoc(obj, obj_name='', embedded_override=False):
20312031
return ''
20322032
r = sage_getdoc_original(obj)
20332033
s = sage.misc.sagedoc.format(r, embedded=(embedded_override or EMBEDDED_MODE))
2034+
f = sage_getfile(obj)
2035+
if f:
2036+
from sage.doctest.control import skipfile
2037+
skip = skipfile(f)
2038+
if skip:
2039+
warn = """WARNING: the enclosing module is marked '{}',
2040+
so doctests may not pass.""".format(skip)
2041+
s = warn + "\n\n" + s
2042+
pass
20342043

20352044
# Fix object naming
20362045
if obj_name != '':

0 commit comments

Comments
 (0)