Skip to content

Commit 22a2f5d

Browse files
author
Matthias Koeppe
committed
src/sage/repl: sage -fixdoctests --only-tags
1 parent 2ea7108 commit 22a2f5d

File tree

14 files changed

+110
-105
lines changed

14 files changed

+110
-105
lines changed

src/sage/repl/configuration.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
the IPython simple prompt is being used::
88
99
sage: cmd = 'print([sys.stdin.isatty(), sys.stdout.isatty()])'
10-
sage: import pexpect # optional - pexpect
11-
sage: output = pexpect.run( # optional - pexpect
10+
sage: import pexpect # needs pexpect
11+
sage: output = pexpect.run( # needs pexpect
1212
....: 'bash -c \'echo "{0}" | sage\''.format(cmd),
1313
....: ).decode('utf-8', 'surrogateescape')
14-
sage: 'sage: [False, True]' in output # optional - pexpect
14+
sage: 'sage: [False, True]' in output # needs pexpect
1515
True
1616
"""
1717

src/sage/repl/display/formatter.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,17 @@
2424
sage: from sage.repl.interpreter import get_test_shell
2525
sage: shell = get_test_shell()
2626
sage: shell.run_cell('%display ascii_art')
27-
sage: shell.run_cell('integral(x^2/pi^x, x)')
27+
sage: shell.run_cell('integral(x^2/pi^x, x)') # needs sage.symbolic
2828
-x / 2 2 \
2929
-pi *\x *log (pi) + 2*x*log(pi) + 2/
3030
--------------------------------------
3131
3
3232
log (pi)
33-
sage: shell.run_cell("i = var('i')")
34-
sage: shell.run_cell('sum(i*x^i, i, 0, 10)')
33+
sage: shell.run_cell("i = var('i')") # needs sage.symbolic
34+
sage: shell.run_cell('sum(i*x^i, i, 0, 10)') # needs sage.symbolic
3535
10 9 8 7 6 5 4 3 2
3636
10*x + 9*x + 8*x + 7*x + 6*x + 5*x + 4*x + 3*x + 2*x + x
37-
sage: shell.run_cell('StandardTableaux(4).list()')
37+
sage: shell.run_cell('StandardTableaux(4).list()') # needs sage.combinat
3838
[
3939
[ 1 4 1 3
4040
[ 1 3 4 1 2 4 1 2 3 1 3 1 2 2 2
@@ -121,7 +121,7 @@ def format(self, obj, include=None, exclude=None):
121121
122122
EXAMPLES::
123123
124-
sage: [identity_matrix(i) for i in range(3,7)]
124+
sage: [identity_matrix(i) for i in range(3,7)] # needs sage.modules
125125
[
126126
[1 0 0 0 0 0]
127127
[1 0 0 0 0] [0 1 0 0 0 0]
@@ -133,8 +133,8 @@ def format(self, obj, include=None, exclude=None):
133133
sage: from sage.repl.interpreter import get_test_shell
134134
sage: shell = get_test_shell()
135135
sage: shell.run_cell('%display ascii_art') # indirect doctest
136-
sage: shell.run_cell("i = var('i')")
137-
sage: shell.run_cell('sum(i*x^i, i, 0, 10)')
136+
sage: shell.run_cell("i = var('i')") # needs sage.symbolic
137+
sage: shell.run_cell('sum(i*x^i, i, 0, 10)') # needs sage.symbolic
138138
10 9 8 7 6 5 4 3 2
139139
10*x + 9*x + 8*x + 7*x + 6*x + 5*x + 4*x + 3*x + 2*x + x
140140
sage: shell.run_cell('%display default')
@@ -229,11 +229,11 @@ def _ipython_float_precision_changed(change):
229229
sage: shell = get_test_shell()
230230
sage: shell.run_cell('%precision 4')
231231
'%.4f'
232-
sage: shell.run_cell('matrix.options.precision') # indirect doctest # optional - sage.modules
232+
sage: shell.run_cell('matrix.options.precision') # indirect doctest # needs sage.modules
233233
4
234234
sage: shell.run_cell('%precision')
235235
'%r'
236-
sage: shell.run_cell('matrix.options.precision') # indirect doctest # optional - sage.modules
236+
sage: shell.run_cell('matrix.options.precision') # indirect doctest # needs sage.modules
237237
None
238238
"""
239239
from sage.matrix.constructor import options
@@ -305,8 +305,8 @@ def __call__(self, obj):
305305
sage: fmt(2)
306306
---- calling ipython formatter ----
307307
'2'
308-
sage: a = identity_matrix(ZZ, 2) # optional - sage.modules
309-
sage: fmt([a, a]) # optional - sage.modules
308+
sage: a = identity_matrix(ZZ, 2) # needs sage.modules
309+
sage: fmt([a, a]) # needs sage.modules
310310
---- calling ipython formatter ----
311311
'[\n[1 0] [1 0]\n[0 1], [0 1]\n]'
312312
"""

src/sage/repl/display/jsmol_iframe.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ def __init__(self, jmol, path_to_jsmol=None, width='100%', height='100%'):
112112
EXAMPLES::
113113
114114
sage: from sage.repl.display.jsmol_iframe import JSMolHtml
115-
sage: JSMolHtml(sphere(), width=500, height=300)
115+
sage: JSMolHtml(sphere(), width=500, height=300) # needs sage.plot
116116
JSmol Window 500x300
117117
"""
118118
from sage.repl.rich_output.output_graphics3d import OutputSceneJmol

src/sage/repl/display/util.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def try_format(self, the_list):
7474
TESTS::
7575
7676
sage: from sage.repl.display.util import format_list
77-
sage: print(format_list.try_format(
77+
sage: print(format_list.try_format( # needs sage.modules
7878
....: [matrix([[1, 2, 3, 4], [5, 6, 7, 8]]) for i in range(7)]))
7979
[
8080
[1 2 3 4] [1 2 3 4] [1 2 3 4] [1 2 3 4] [1 2 3 4] [1 2 3 4]

src/sage/repl/interface_magic.py

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,9 @@ def register_all(cls, shell=None):
121121
...
122122
('maxima', 'line')
123123
('maxima', 'cell')
124-
sage: 'gap' in MockShell.magics # optional - sage.libs.gap
124+
sage: 'gap' in MockShell.magics # needs sage.libs.gap
125125
True
126-
sage: 'maxima' in MockShell.magics
126+
sage: 'maxima' in MockShell.magics # needs sage.symbolic
127127
True
128128
"""
129129
if shell is None:
@@ -159,7 +159,7 @@ def find(cls, name):
159159
EXAMPLES::
160160
161161
sage: from sage.repl.interface_magic import InterfaceMagic
162-
sage: InterfaceMagic.find('gap') # optional - sage.libs.gap
162+
sage: InterfaceMagic.find('gap') # needs sage.libs.gap
163163
<sage.repl.interface_magic.InterfaceMagic object at 0x...>
164164
"""
165165
for magic in cls.all_iter():
@@ -183,7 +183,7 @@ def __init__(self, name, interface):
183183
EXAMPLES::
184184
185185
sage: from sage.repl.interface_magic import InterfaceMagic
186-
sage: InterfaceMagic.find('gap') # optional - sage.libs.gap
186+
sage: InterfaceMagic.find('gap') # needs sage.libs.gap
187187
<sage.repl.interface_magic.InterfaceMagic object at 0x...>
188188
"""
189189
self._name = name
@@ -199,21 +199,22 @@ def line_magic_factory(self):
199199
200200
EXAMPLES::
201201
202+
sage: # needs sage.libs.gap
202203
sage: from sage.repl.interface_magic import InterfaceMagic
203-
sage: line_magic = InterfaceMagic.find('gap').line_magic_factory() # optional - sage.libs.gap
204-
sage: output = line_magic('1+1') # optional - sage.libs.gap
205-
sage: output # optional - sage.libs.gap
204+
sage: line_magic = InterfaceMagic.find('gap').line_magic_factory()
205+
sage: output = line_magic('1+1')
206+
sage: output
206207
2
207-
sage: type(output) # optional - sage.libs.gap
208+
sage: type(output)
208209
<class 'sage.interfaces.gap.GapElement'>
209210
210211
This is how the built line magic is used in practice::
211212
212213
sage: from sage.repl.interpreter import get_test_shell
213214
sage: shell = get_test_shell()
214-
sage: shell.run_cell('%gap 1+1') # optional - sage.libs.gap
215+
sage: shell.run_cell('%gap 1+1') # needs sage.libs.gap
215216
2
216-
sage: shell.run_cell('%gap?') # optional - sage.libs.gap
217+
sage: shell.run_cell('%gap?') # needs sage.libs.gap
217218
Docstring:
218219
Interact with gap
219220
<BLANKLINE>
@@ -243,13 +244,14 @@ def cell_magic_factory(self):
243244
244245
EXAMPLES::
245246
247+
sage: # needs sage.libs.gap
246248
sage: from sage.repl.interface_magic import InterfaceMagic
247-
sage: cell_magic = InterfaceMagic.find('gap').cell_magic_factory() # optional - sage.libs.gap
248-
sage: output = cell_magic('', '1+1;') # optional - sage.libs.gap
249+
sage: cell_magic = InterfaceMagic.find('gap').cell_magic_factory()
250+
sage: output = cell_magic('', '1+1;')
249251
2
250-
sage: output is None # optional - sage.libs.gap
252+
sage: output is None
251253
True
252-
sage: cell_magic('foo', '1+1;') # optional - sage.libs.gap
254+
sage: cell_magic('foo', '1+1;')
253255
Traceback (most recent call last):
254256
...
255257
SyntaxError: Interface magics have no options, got "foo"
@@ -258,15 +260,15 @@ def cell_magic_factory(self):
258260
259261
sage: from sage.repl.interpreter import get_test_shell
260262
sage: shell = get_test_shell()
261-
sage: shell.run_cell('%%gap\nG:=SymmetricGroup(5);\n1+1;Order(G);') # optional - sage.libs.gap
263+
sage: shell.run_cell('%%gap\nG:=SymmetricGroup(5);\n1+1;Order(G);') # needs sage.libs.gap
262264
Sym( [ 1 .. 5 ] )
263265
2
264266
120
265-
sage: shell.run_cell('%%gap foo\n1+1;\n') # optional - sage.libs.gap
267+
sage: shell.run_cell('%%gap foo\n1+1;\n') # needs sage.libs.gap
266268
...File...<string>...
267269
SyntaxError: Interface magics have no options, got "foo"
268270
<BLANKLINE>
269-
sage: shell.run_cell('%%gap?') # optional - sage.libs.gap
271+
sage: shell.run_cell('%%gap?') # needs sage.libs.gap
270272
Docstring:
271273
Interact with gap
272274
<BLANKLINE>

src/sage/repl/interpreter.py

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -508,12 +508,13 @@ def __init__(self, *args, **kwds):
508508
509509
TESTS::
510510
511+
sage: # needs sage.symbolic
511512
sage: from sage.repl.interpreter import interface_shell_embed
512-
sage: shell = interface_shell_embed(maxima) # optional - sage.symbolic
513-
sage: ift = shell.prefilter_manager.transformers[0] # optional - sage.symbolic
514-
sage: ift.temporary_objects # optional - sage.symbolic
513+
sage: shell = interface_shell_embed(maxima)
514+
sage: ift = shell.prefilter_manager.transformers[0]
515+
sage: ift.temporary_objects
515516
set()
516-
sage: ift._sage_import_re.findall('sage(a) + maxima(b)') # optional - sage.symbolic
517+
sage: ift._sage_import_re.findall('sage(a) + maxima(b)')
517518
['sage(', 'maxima(']
518519
"""
519520
super().__init__(*args, **kwds)
@@ -535,30 +536,32 @@ def preparse_imports_from_sage(self, line):
535536
536537
EXAMPLES::
537538
539+
sage: # needs sage.symbolic
538540
sage: from sage.repl.interpreter import interface_shell_embed, InterfaceShellTransformer
539-
sage: shell = interface_shell_embed(maxima) # optional - sage.symbolic
540-
sage: ift = InterfaceShellTransformer(shell=shell, config=shell.config, # optional - sage.symbolic
541+
sage: shell = interface_shell_embed(maxima)
542+
sage: ift = InterfaceShellTransformer(shell=shell, config=shell.config,
541543
....: prefilter_manager=shell.prefilter_manager)
542-
sage: ift.shell.ex('a = 3') # optional - sage.symbolic
543-
sage: ift.preparse_imports_from_sage('2 + sage(a)') # optional - sage.symbolic
544+
sage: ift.shell.ex('a = 3')
545+
sage: ift.preparse_imports_from_sage('2 + sage(a)')
544546
'2 + sage0 '
545-
sage: maxima.eval('sage0') # optional - sage.symbolic
547+
sage: maxima.eval('sage0')
546548
'3'
547-
sage: ift.preparse_imports_from_sage('2 + maxima(a)') # maxima calls set_seed on startup which is why 'sage0' will becomes 'sage4' and not just 'sage1' # optional - sage.symbolic
549+
sage: ift.preparse_imports_from_sage('2 + maxima(a)') # maxima calls set_seed on startup which is why 'sage0' will becomes 'sage4' and not just 'sage1'
548550
'2 + sage4 '
549-
sage: ift.preparse_imports_from_sage('2 + gap(a)') # optional - sage.symbolic
551+
sage: ift.preparse_imports_from_sage('2 + gap(a)')
550552
'2 + gap(a)'
551553
552554
Since :trac:`28439`, this also works with more complicated expressions
553555
containing nested parentheses::
554556
555-
sage: shell = interface_shell_embed(gap) # optional - sage.libs.gap
556-
sage: shell.user_ns = locals() # optional - sage.libs.gap
557-
sage: ift = InterfaceShellTransformer(shell=shell, config=shell.config, # optional - sage.libs.gap
557+
sage: # needs sage.libs.gap
558+
sage: shell = interface_shell_embed(gap)
559+
sage: shell.user_ns = locals()
560+
sage: ift = InterfaceShellTransformer(shell=shell, config=shell.config,
558561
....: prefilter_manager=shell.prefilter_manager)
559-
sage: line = '2 + sage((1+2)*gap(-(5-3)^2).sage()) - gap(1+(2-1))' # optional - sage.libs.gap
560-
sage: line = ift.preparse_imports_from_sage(line) # optional - sage.libs.gap
561-
sage: gap.eval(line) # optional - sage.libs.gap
562+
sage: line = '2 + sage((1+2)*gap(-(5-3)^2).sage()) - gap(1+(2-1))'
563+
sage: line = ift.preparse_imports_from_sage(line)
564+
sage: gap.eval(line)
562565
'-12'
563566
"""
564567
new_line = []
@@ -612,9 +615,8 @@ def transform(self, line, continue_prompt):
612615
Check that whitespace is not stripped and that special characters are
613616
escaped (:trac:`28439`)::
614617
615-
sage: # needs sage.libs.gap
616-
sage: shell = interface_shell_embed(gap)
617-
sage: ift = InterfaceShellTransformer(shell=shell, config=shell.config,
618+
sage: shell = interface_shell_embed(gap) # needs sage.libs.gap sage.symbolic
619+
sage: ift = InterfaceShellTransformer(shell=shell, config=shell.config, # needs sage.libs.gap sage.symbolic
618620
....: prefilter_manager=shell.prefilter_manager)
619621
sage: ift.transform(r'Print(" -\n\\\\- ");', False)
620622
'sage.repl.interpreter.logstr(r""" -\n\\\\-""")'
@@ -653,8 +655,8 @@ def interface_shell_embed(interface):
653655
EXAMPLES::
654656
655657
sage: from sage.repl.interpreter import interface_shell_embed
656-
sage: shell = interface_shell_embed(gap) # optional - sage.libs.gap
657-
sage: shell.run_cell('List( [1..10], IsPrime )') # optional - sage.libs.gap
658+
sage: shell = interface_shell_embed(gap) # needs sage.libs.gap
659+
sage: shell.run_cell('List( [1..10], IsPrime )') # needs sage.libs.gap
658660
[ false, true, true, false, true, false, true, false, false, false ]
659661
<ExecutionResult object at ..., execution_count=None error_before_exec=None error_in_exec=None ...result=[ false, true, true, false, true, false, true, false, false, false ]>
660662
"""

0 commit comments

Comments
 (0)