passagemath-repl 10.5.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (162) hide show
  1. passagemath_repl-10.5.1.data/scripts/sage-cachegrind +25 -0
  2. passagemath_repl-10.5.1.data/scripts/sage-callgrind +16 -0
  3. passagemath_repl-10.5.1.data/scripts/sage-cleaner +230 -0
  4. passagemath_repl-10.5.1.data/scripts/sage-coverage +327 -0
  5. passagemath_repl-10.5.1.data/scripts/sage-eval +14 -0
  6. passagemath_repl-10.5.1.data/scripts/sage-fixdoctests +710 -0
  7. passagemath_repl-10.5.1.data/scripts/sage-inline-fortran +12 -0
  8. passagemath_repl-10.5.1.data/scripts/sage-ipynb2rst +50 -0
  9. passagemath_repl-10.5.1.data/scripts/sage-ipython +16 -0
  10. passagemath_repl-10.5.1.data/scripts/sage-massif +25 -0
  11. passagemath_repl-10.5.1.data/scripts/sage-notebook +267 -0
  12. passagemath_repl-10.5.1.data/scripts/sage-omega +25 -0
  13. passagemath_repl-10.5.1.data/scripts/sage-preparse +302 -0
  14. passagemath_repl-10.5.1.data/scripts/sage-run +27 -0
  15. passagemath_repl-10.5.1.data/scripts/sage-run-cython +10 -0
  16. passagemath_repl-10.5.1.data/scripts/sage-runtests +9 -0
  17. passagemath_repl-10.5.1.data/scripts/sage-startuptime.py +163 -0
  18. passagemath_repl-10.5.1.data/scripts/sage-valgrind +34 -0
  19. passagemath_repl-10.5.1.dist-info/METADATA +77 -0
  20. passagemath_repl-10.5.1.dist-info/RECORD +162 -0
  21. passagemath_repl-10.5.1.dist-info/WHEEL +5 -0
  22. passagemath_repl-10.5.1.dist-info/top_level.txt +1 -0
  23. sage/all__sagemath_repl.py +119 -0
  24. sage/doctest/__init__.py +4 -0
  25. sage/doctest/__main__.py +236 -0
  26. sage/doctest/all.py +4 -0
  27. sage/doctest/check_tolerance.py +261 -0
  28. sage/doctest/control.py +1727 -0
  29. sage/doctest/external.py +534 -0
  30. sage/doctest/fixtures.py +383 -0
  31. sage/doctest/forker.py +2665 -0
  32. sage/doctest/marked_output.py +102 -0
  33. sage/doctest/parsing.py +1708 -0
  34. sage/doctest/parsing_test.py +79 -0
  35. sage/doctest/reporting.py +733 -0
  36. sage/doctest/rif_tol.py +124 -0
  37. sage/doctest/sources.py +1657 -0
  38. sage/doctest/test.py +584 -0
  39. sage/doctest/tests/1second.rst +4 -0
  40. sage/doctest/tests/99seconds.rst +4 -0
  41. sage/doctest/tests/abort.rst +5 -0
  42. sage/doctest/tests/atexit.rst +7 -0
  43. sage/doctest/tests/fail_and_die.rst +6 -0
  44. sage/doctest/tests/initial.rst +15 -0
  45. sage/doctest/tests/interrupt.rst +7 -0
  46. sage/doctest/tests/interrupt_diehard.rst +14 -0
  47. sage/doctest/tests/keyboardinterrupt.rst +11 -0
  48. sage/doctest/tests/longtime.rst +5 -0
  49. sage/doctest/tests/nodoctest +5 -0
  50. sage/doctest/tests/random_seed.rst +4 -0
  51. sage/doctest/tests/show_skipped.rst +18 -0
  52. sage/doctest/tests/sig_on.rst +9 -0
  53. sage/doctest/tests/simple_failure.rst +8 -0
  54. sage/doctest/tests/sleep_and_raise.rst +106 -0
  55. sage/doctest/tests/tolerance.rst +31 -0
  56. sage/doctest/util.py +750 -0
  57. sage/interfaces/cleaner.py +48 -0
  58. sage/interfaces/quit.py +163 -0
  59. sage/misc/all__sagemath_repl.py +51 -0
  60. sage/misc/banner.py +235 -0
  61. sage/misc/benchmark.py +221 -0
  62. sage/misc/classgraph.py +134 -0
  63. sage/misc/copying.py +22 -0
  64. sage/misc/cython.py +694 -0
  65. sage/misc/dev_tools.py +745 -0
  66. sage/misc/edit_module.py +304 -0
  67. sage/misc/explain_pickle.py +3079 -0
  68. sage/misc/gperftools.py +361 -0
  69. sage/misc/inline_fortran.py +212 -0
  70. sage/misc/messaging.py +86 -0
  71. sage/misc/pager.py +21 -0
  72. sage/misc/profiler.py +179 -0
  73. sage/misc/python.py +70 -0
  74. sage/misc/remote_file.py +53 -0
  75. sage/misc/sage_eval.py +249 -0
  76. sage/misc/sage_input.py +3621 -0
  77. sage/misc/sagedoc.py +1742 -0
  78. sage/misc/sh.py +38 -0
  79. sage/misc/trace.py +90 -0
  80. sage/repl/__init__.py +16 -0
  81. sage/repl/all.py +15 -0
  82. sage/repl/attach.py +625 -0
  83. sage/repl/configuration.py +186 -0
  84. sage/repl/display/__init__.py +1 -0
  85. sage/repl/display/fancy_repr.py +354 -0
  86. sage/repl/display/formatter.py +318 -0
  87. sage/repl/display/jsmol_iframe.py +290 -0
  88. sage/repl/display/pretty_print.py +153 -0
  89. sage/repl/display/util.py +163 -0
  90. sage/repl/image.py +302 -0
  91. sage/repl/inputhook.py +91 -0
  92. sage/repl/interface_magic.py +298 -0
  93. sage/repl/interpreter.py +854 -0
  94. sage/repl/ipython_extension.py +593 -0
  95. sage/repl/ipython_kernel/__init__.py +1 -0
  96. sage/repl/ipython_kernel/__main__.py +4 -0
  97. sage/repl/ipython_kernel/all_jupyter.py +10 -0
  98. sage/repl/ipython_kernel/install.py +301 -0
  99. sage/repl/ipython_kernel/interact.py +278 -0
  100. sage/repl/ipython_kernel/kernel.py +217 -0
  101. sage/repl/ipython_kernel/widgets.py +466 -0
  102. sage/repl/ipython_kernel/widgets_sagenb.py +587 -0
  103. sage/repl/ipython_tests.py +163 -0
  104. sage/repl/load.py +326 -0
  105. sage/repl/preparse.py +2218 -0
  106. sage/repl/prompts.py +90 -0
  107. sage/repl/rich_output/__init__.py +4 -0
  108. sage/repl/rich_output/backend_base.py +648 -0
  109. sage/repl/rich_output/backend_doctest.py +316 -0
  110. sage/repl/rich_output/backend_emacs.py +151 -0
  111. sage/repl/rich_output/backend_ipython.py +596 -0
  112. sage/repl/rich_output/buffer.py +311 -0
  113. sage/repl/rich_output/display_manager.py +829 -0
  114. sage/repl/rich_output/example.avi +0 -0
  115. sage/repl/rich_output/example.canvas3d +1 -0
  116. sage/repl/rich_output/example.dvi +0 -0
  117. sage/repl/rich_output/example.flv +0 -0
  118. sage/repl/rich_output/example.gif +0 -0
  119. sage/repl/rich_output/example.jpg +0 -0
  120. sage/repl/rich_output/example.mkv +0 -0
  121. sage/repl/rich_output/example.mov +0 -0
  122. sage/repl/rich_output/example.mp4 +0 -0
  123. sage/repl/rich_output/example.ogv +0 -0
  124. sage/repl/rich_output/example.pdf +0 -0
  125. sage/repl/rich_output/example.png +0 -0
  126. sage/repl/rich_output/example.svg +54 -0
  127. sage/repl/rich_output/example.webm +0 -0
  128. sage/repl/rich_output/example.wmv +0 -0
  129. sage/repl/rich_output/example_jmol.spt.zip +0 -0
  130. sage/repl/rich_output/example_wavefront_scene.mtl +7 -0
  131. sage/repl/rich_output/example_wavefront_scene.obj +17 -0
  132. sage/repl/rich_output/output_basic.py +391 -0
  133. sage/repl/rich_output/output_browser.py +103 -0
  134. sage/repl/rich_output/output_catalog.py +54 -0
  135. sage/repl/rich_output/output_graphics.py +320 -0
  136. sage/repl/rich_output/output_graphics3d.py +345 -0
  137. sage/repl/rich_output/output_video.py +231 -0
  138. sage/repl/rich_output/preferences.py +432 -0
  139. sage/repl/rich_output/pretty_print.py +339 -0
  140. sage/repl/rich_output/test_backend.py +201 -0
  141. sage/repl/user_globals.py +214 -0
  142. sage/tests/all.py +0 -0
  143. sage/tests/all__sagemath_repl.py +3 -0
  144. sage/tests/article_heuberger_krenn_kropf_fsm-in-sage.py +630 -0
  145. sage/tests/arxiv_0812_2725.py +351 -0
  146. sage/tests/benchmark.py +1925 -0
  147. sage/tests/book_schilling_zabrocki_kschur_primer.py +795 -0
  148. sage/tests/book_stein_ent.py +651 -0
  149. sage/tests/book_stein_modform.py +558 -0
  150. sage/tests/cmdline.py +796 -0
  151. sage/tests/combinatorial_hopf_algebras.py +52 -0
  152. sage/tests/finite_poset.py +623 -0
  153. sage/tests/functools_partial_src.py +27 -0
  154. sage/tests/gosper-sum.py +218 -0
  155. sage/tests/lazy_imports.py +28 -0
  156. sage/tests/modular_group_cohomology.py +80 -0
  157. sage/tests/numpy.py +21 -0
  158. sage/tests/parigp.py +76 -0
  159. sage/tests/startup.py +27 -0
  160. sage/tests/symbolic-series.py +76 -0
  161. sage/tests/sympy.py +16 -0
  162. sage/tests/test_deprecation.py +31 -0
sage/tests/cmdline.py ADDED
@@ -0,0 +1,796 @@
1
+ # sage_setup: distribution = sagemath-repl
2
+ r"""
3
+ This file contains some tests that Sage command line options actually
4
+ do something.
5
+
6
+ We test the following command line options:
7
+
8
+ test.py
9
+ /path/to/test.py
10
+ test.sage
11
+ /path/to/test.sage
12
+ test.spyx
13
+ /path/to/test.spyx
14
+ --advanced
15
+ -c
16
+ --cython
17
+ --dev
18
+ --ecl
19
+ --experimental
20
+ --fixdoctests
21
+ --gap
22
+ --gdb
23
+ --gp
24
+ -h
25
+ --help
26
+ --info
27
+ --ipython
28
+ --lisp
29
+ --maxima
30
+ --min
31
+ --mwrank
32
+ --optional
33
+ --preparse
34
+ --python
35
+ --python3
36
+ -q
37
+ --R
38
+ --root
39
+ --rst2ipynb
40
+ --ipynb2rst
41
+ --sh
42
+ --singular
43
+ --sqlite3
44
+ --standard
45
+ --startuptime
46
+ -t
47
+ -v
48
+ --zzfoobar (illegal option)
49
+
50
+
51
+ AUTHORS:
52
+
53
+ - Jeroen Demeyer (2010-11-20): initial version (:issue:`10300`)
54
+ """
55
+ from subprocess import Popen, PIPE
56
+ import os
57
+ import sys
58
+ import select
59
+
60
+
61
+ def test_executable(args, input='', timeout=100.0, pydebug_ignore_warnings=False, **kwds):
62
+ r"""
63
+ Run the program defined by ``args`` using the string ``input`` on
64
+ the standard input.
65
+
66
+ INPUT:
67
+
68
+ - ``args`` -- list of program arguments, the first being the
69
+ executable
70
+
71
+ - ``input`` -- string serving as standard input; usually, this
72
+ should end with a newline
73
+
74
+ - ``timeout`` -- if the program produces no output for ``timeout``
75
+ seconds, a :exc:`RuntimeError` is raised
76
+
77
+ - ``pydebug_ignore_warnings`` -- boolean. Set the PYTHONWARNINGS environment variable to ignore
78
+ Python warnings when on a Python debug build (`--with-pydebug`, e.g. from building with
79
+ `SAGE_DEBUG=yes`). Debug builds do not install the default warning filters, which can break
80
+ some doctests. Unfortunately the environment variable does not support regex message filters,
81
+ so the filter will catch a bit more than the default filters. Hence we only enable it on debug
82
+ builds.
83
+
84
+ - ``**kwds`` -- additional keyword arguments passed to the
85
+ :class:`Popen` constructor
86
+
87
+ OUTPUT: a tuple ``(out, err, ret)`` with the standard output,
88
+ standard error and exitcode of the program run.
89
+
90
+ EXAMPLES::
91
+
92
+ sage: from sage.tests.cmdline import test_executable
93
+ sage: (out, err, ret) = test_executable(["cat"], "Hello World!")
94
+ sage: out
95
+ 'Hello World!'
96
+ sage: err
97
+ ''
98
+ sage: ret
99
+ 0
100
+
101
+ We test the timeout option::
102
+
103
+ sage: (out, err, ret) = test_executable(["sleep", "1"], timeout=0.1)
104
+ Traceback (most recent call last):
105
+ ...
106
+ RuntimeError: timeout in test_executable()
107
+
108
+ TESTS:
109
+
110
+ Run Sage itself with various options::
111
+
112
+ sage: # long time
113
+ sage: (out, err, ret) = test_executable([
114
+ ....: "sage"], pydebug_ignore_warnings=True)
115
+ sage: out.find(version()) >= 0
116
+ True
117
+ sage: err
118
+ ''
119
+ sage: ret
120
+ 0
121
+
122
+ sage: # long time
123
+ sage: (out, err, ret) = test_executable([
124
+ ....: "sage"], "3^33\n", pydebug_ignore_warnings=True)
125
+ sage: out.find(version()) >= 0
126
+ True
127
+ sage: out.find("5559060566555523") >= 0
128
+ True
129
+ sage: err
130
+ ''
131
+ sage: ret
132
+ 0
133
+
134
+ sage: # long time
135
+ sage: (out, err, ret) = test_executable([
136
+ ....: "sage", "-q"], "3^33\n", pydebug_ignore_warnings=True)
137
+ sage: out.find(version()) >= 0
138
+ False
139
+ sage: out.find("5559060566555523") >= 0
140
+ True
141
+ sage: err
142
+ ''
143
+ sage: ret
144
+ 0
145
+
146
+ sage: # long time
147
+ sage: (out, err, ret) = test_executable([
148
+ ....: "sage", "-c", "print(3^33)"])
149
+ sage: print(out)
150
+ 5559060566555523
151
+ sage: err
152
+ ''
153
+ sage: ret
154
+ 0
155
+
156
+ sage: # long time
157
+ sage: (out, err, ret) = test_executable([
158
+ ....: "sage", "--min", "-c", "print(3^33)"])
159
+ sage: print(out)
160
+ 5559060566555523
161
+ sage: err
162
+ ''
163
+ sage: ret
164
+ 0
165
+
166
+ sage: # long time
167
+ sage: (out, err, ret) = test_executable([
168
+ ....: "sage", "--startuptime"])
169
+ sage: out.find("Slowest module import") >= 0
170
+ True
171
+ sage: err
172
+ ''
173
+ sage: ret
174
+ 0
175
+
176
+ Test help::
177
+
178
+ sage: (out, err, ret) = test_executable(["sage", "-h"])
179
+ sage: out.find("evaluate cmd as sage") >= 0
180
+ True
181
+ sage: err
182
+ ''
183
+ sage: ret
184
+ 0
185
+
186
+ sage: (out, err, ret) = test_executable(["sage", "--help"])
187
+ sage: out.find("evaluate cmd as sage") >= 0
188
+ True
189
+ sage: err
190
+ ''
191
+ sage: ret
192
+ 0
193
+
194
+ sage: (out, err, ret) = test_executable(["sage", "--advanced"])
195
+ sage: out.find("run the Sage cleaner.") >= 0
196
+ True
197
+ sage: err
198
+ ''
199
+ sage: ret
200
+ 0
201
+ sage: out.find("print the Sage root directory") >= 0 # optional - sage_spkg
202
+ True
203
+ sage: out.find("regular expression search through the Sage") >= 0 # optional - sage_spkg
204
+ True
205
+
206
+ Basic information about the Sage installation::
207
+
208
+ sage: (out, err, ret) = test_executable(["sage", "-v"])
209
+ sage: out.find(version()) >= 0
210
+ True
211
+ sage: err
212
+ ''
213
+ sage: ret
214
+ 0
215
+
216
+ sage: # optional - sage_spkg
217
+ sage: (out, err, ret) = test_executable(["sage", "--root"])
218
+ sage: len(out) >= 2
219
+ True
220
+ sage: err
221
+ ''
222
+ sage: ret
223
+ 0
224
+
225
+ Test ``sage --info [packages]``::
226
+
227
+ sage: # optional - sage_spkg
228
+ sage: out, err, ret = test_executable(["sage", "--info", "sqlite"])
229
+ sage: print(out)
230
+ sqlite...
231
+ SQLite is a software library that implements a self-contained,
232
+ serverless, zero-configuration, transactional SQL database engine.
233
+ ...
234
+ sage: err
235
+ ''
236
+ sage: ret
237
+ 0
238
+
239
+ Test ``sage-run`` on a Python file, both with an absolute and with a relative path::
240
+
241
+ sage: import tempfile
242
+ sage: with tempfile.TemporaryDirectory() as dir:
243
+ ....: name = 'python_test_file.py'
244
+ ....: fullname = os.path.join(dir, name)
245
+ ....: with open(fullname, 'w') as F:
246
+ ....: _ = F.write("print(3^33)\n")
247
+ ....: test_executable(["sage", fullname])
248
+ ....: test_executable(["sage", name], cwd=dir)
249
+ ('34\n', '', 0)
250
+ ('34\n', '', 0)
251
+
252
+ The same as above, but now with a ``.sage`` file. This indirectly
253
+ also tests the preparser::
254
+
255
+ sage: import tempfile
256
+ sage: with tempfile.TemporaryDirectory() as dir: # long time
257
+ ....: name = 'sage_test_file.sage'
258
+ ....: fullname = os.path.join(dir, name)
259
+ ....: with open(fullname, 'w') as F:
260
+ ....: _ = F.write("k.<a> = GF(5^3); print(a^124)\n")
261
+ ....: test_executable(["sage", fullname])
262
+ ....: test_executable(["sage", name], cwd=dir)
263
+ ('1\n', '', 0)
264
+ ('1\n', '', 0)
265
+
266
+ Test running a ``.spyx`` file::
267
+
268
+ sage: import tempfile
269
+ sage: with tempfile.TemporaryDirectory() as dir: # long time
270
+ ....: name = 'sage_test_file.spyx'
271
+ ....: fullname = os.path.join(dir, name)
272
+ ....: with open(fullname, 'w') as F:
273
+ ....: _ = F.write("from cysignals.signals cimport *\n")
274
+ ....: _ = F.write("from sage.rings.integer cimport Integer\n")
275
+ ....: _ = F.write("cdef long i, s = 0\n")
276
+ ....: _ = F.write("sig_on()\n")
277
+ ....: _ = F.write("for i in range(5): s += i\n")
278
+ ....: _ = F.write("sig_off()\n")
279
+ ....: _ = F.write("print(Integer(s))")
280
+ ....: test_executable(["sage", fullname], pydebug_ignore_warnings=True)
281
+ ....: test_executable(["sage", name], cwd=dir, pydebug_ignore_warnings=True)
282
+ ('10\n', 'Compiling .../sage_test_file.spyx...\n', 0)
283
+ ('10\n', 'Compiling sage_test_file.spyx...\n', 0)
284
+
285
+ Testing ``sage --preparse FILE`` and ``sage -t FILE``. First create
286
+ a file and preparse it::
287
+
288
+ sage: s = "# -*- coding: utf-8 -*-\n'''This is a test file.\nAnd I am its doctest'''\ndef my_add(a):\n '''\n Add 2 to a.\n\n EXAMPLES::\n\n sage: my_add(2)\n 4\n '''\n return a + 2\n"
289
+ sage: script = os.path.join(tmp_dir(), 'my_script.sage')
290
+ sage: script_py = script + '.py'
291
+ sage: F = open(script, 'w')
292
+ sage: _ = F.write(s)
293
+ sage: F.close()
294
+ sage: (out, err, ret) = test_executable(["sage", "--preparse", script])
295
+ sage: ret
296
+ 0
297
+ sage: os.path.isfile(script_py)
298
+ True
299
+
300
+ Now test my_script.sage and the preparsed version my_script.sage.py::
301
+
302
+ sage: # long time
303
+ sage: (out, err, ret) = test_executable([
304
+ ....: "sage", "-t", "--optional=sage", script])
305
+ sage: ret
306
+ 0
307
+ sage: out.find("All tests passed!") >= 0
308
+ True
309
+ sage: (out, err, ret) = test_executable([
310
+ ....: "sage", "-t", "--optional=sage", script_py])
311
+ sage: ret
312
+ 0
313
+ sage: out.find("All tests passed!") >= 0
314
+ True
315
+
316
+ Test that the coding line and doctest are preserved::
317
+
318
+ sage: Fpy = open(script_py, "r")
319
+ sage: Fpy.readline()
320
+ '# -*- coding: utf-8 -*-\n'
321
+ sage: Fpy.readline()
322
+ "'''This is a test file.\n"
323
+ sage: Fpy.readline()
324
+ "And I am its doctest'''\n"
325
+
326
+ Now for a file which should fail tests::
327
+
328
+ sage: s = s.replace('4', '5') # (2+2 != 5)
329
+ sage: F = open(script, 'w')
330
+ sage: _ = F.write(s)
331
+ sage: F.close()
332
+ sage: (out, err, ret) = test_executable([ # long time
333
+ ....: "sage", "-t", "--optional=sage", script])
334
+ sage: ret # long time
335
+ 1
336
+ sage: out.find("1 item had failures:") >= 0 # long time
337
+ True
338
+
339
+ Test ``sage -t --debug -p 2`` on a ReST file, the ``-p 2`` should
340
+ be ignored. In Pdb, we run the ``help`` command::
341
+
342
+ sage: s = "::\n\n sage: assert True is False\n sage: 2 + 2\n 5"
343
+ sage: script = tmp_filename(ext='.rst')
344
+ sage: F = open(script, 'w')
345
+ sage: _ = F.write(s)
346
+ sage: F.close()
347
+ sage: (out, err, ret) = test_executable([ # long time
348
+ ....: "sage", "-t", "--optional=sage", "--debug",
349
+ ....: "-p", "2", "--warn-long", "0", script], "help")
350
+ sage: print(out) # long time
351
+ Debugging requires single-threaded operation, setting number of threads to 1.
352
+ Running doctests with ID...
353
+ Doctesting 1 file.
354
+ sage -t ...
355
+ **********************************************************************
356
+ File "...", line 3, in ...
357
+ Failed example:
358
+ assert True is False
359
+ Exception raised:
360
+ Traceback (most recent call last):
361
+ ...
362
+ AssertionError
363
+ > <doctest ...>(1)<module>()
364
+ -> assert True is False
365
+ (Pdb)
366
+ Documented commands (type help <topic>):
367
+ ========================================
368
+ ...
369
+ **********************************************************************
370
+ File "...", line 4, in ...
371
+ Failed example:
372
+ 2 + 2
373
+ Expected:
374
+ 5
375
+ Got:
376
+ 4
377
+ **********************************************************************
378
+ Previously executed commands:
379
+ s...: assert True is False
380
+ sage:
381
+ <BLANKLINE>
382
+ Returning to doctests...
383
+ **********************************************************************
384
+ 1 item had failures:
385
+ 2 of 3 in ...
386
+ [2 tests, 2 failures, ...]
387
+ ...
388
+ sage: ret # long time
389
+ 1
390
+
391
+ Now run a test for the fixdoctests script and, in particular, check that the
392
+ issues raised in :issue:`10589` are fixed. We have to go to slightly silly
393
+ lengths to doctest the output.::
394
+
395
+ sage: test='r\"\"\"Add a doc-test for the fixdoctest command line option and, in particular, check that\n:issue:`10589` is fixed.\n\nEXAMPLES::\n\n sage: 1+1 # incorrect output\n 3\n sage: m=matrix(ZZ,3) # output when none is expected\n [0 0 0]\n [0 0 0]\n [1 0 0]\n sage: (2/3)*m # no output when it is expected\n sage: mu=PartitionTuple([[4,4],[3,3,2,1],[1,1]]) # output when none is expected\n [4, 4, 3, 3, 2, 1, 1]\n sage: mu.pp() # uneven indentation\n ****\n ****\n sage: PartitionTuples.options(convention="French")\n sage: mu.pp() # fix doctest with uneven indentation\n sage: PartitionTuples.options._reset()\n\"\"\"\n'
396
+ sage: test_file = os.path.join(tmp_dir(), 'test_file.py')
397
+ sage: F = open(test_file, 'w')
398
+ sage: _ = F.write(test)
399
+ sage: F.close()
400
+ sage: (out, err, ret) = test_executable(["sage", "--fixdoctests", test_file]) # long time
401
+ sage: with open(test_file, 'r') as f: # long time
402
+ ....: fixed_test = f.read()
403
+ sage: import difflib # long time
404
+ sage: list(difflib.unified_diff(test.splitlines(), fixed_test.splitlines()))[2:-1] # long time
405
+ ['@@ -4,18 +4,23 @@\n',
406
+ ' EXAMPLES::',
407
+ ' ',
408
+ ' sage: 1+1 # incorrect output',
409
+ '- 3',
410
+ '+ 2',
411
+ ' sage: m=matrix(ZZ,3) # output when none is expected',
412
+ '+ sage: (2/3)*m # no output when it is expected',
413
+ ' [0 0 0]',
414
+ ' [0 0 0]',
415
+ '- [1 0 0]',
416
+ '- sage: (2/3)*m # no output when it is expected',
417
+ '+ [0 0 0]',
418
+ ' sage: mu=PartitionTuple([[4,4],[3,3,2,1],[1,1]]) # output when none is expected',
419
+ '- [4, 4, 3, 3, 2, 1, 1]',
420
+ ' sage: mu.pp() # uneven indentation',
421
+ '- ****',
422
+ '- ****',
423
+ '+ **** *** *',
424
+ '+ **** *** *',
425
+ '+ **',
426
+ '+ *',
427
+ ' sage: PartitionTuples.options(convention="French")',
428
+ ' sage: mu.pp() # fix doctest with uneven indentation',
429
+ '+ *',
430
+ '+ **',
431
+ '+ **** *** *',
432
+ '+ **** *** *',
433
+ ' sage: PartitionTuples.options._reset()']
434
+
435
+ Test external programs being called by Sage::
436
+
437
+ sage: (out, err, ret) = test_executable(["sage", "--sh"], "echo Hello World\nexit 42\n")
438
+ sage: out.find("Hello World\n") >= 0
439
+ True
440
+ sage: ret
441
+ 42
442
+
443
+ sage: (out, err, ret) = test_executable(["sage", "--sh", "-c", "echo Hello World; exit 42"])
444
+ sage: out.find("Hello World\n") >= 0
445
+ True
446
+ sage: ret
447
+ 42
448
+
449
+ sage: # long time
450
+ sage: (out, err, ret) = test_executable([
451
+ ....: "sage", "--ipython"], "\n3**33\n", pydebug_ignore_warnings=True)
452
+ sage: out.find("5559060566555523") >= 0
453
+ True
454
+ sage: err
455
+ ''
456
+ sage: ret
457
+ 0
458
+
459
+ sage: (out, err, ret) = test_executable(["sage", "--python"], "print(3^33)\n")
460
+ sage: out
461
+ '34\n'
462
+ sage: err
463
+ ''
464
+ sage: ret
465
+ 0
466
+
467
+ sage: (out, err, ret) = test_executable(["sage", "--python3"], "print(3^33)\n")
468
+ sage: out
469
+ '34\n'
470
+ sage: err
471
+ ''
472
+ sage: ret
473
+ 0
474
+
475
+ sage: (out, err, ret) = test_executable(["sage", "--cython"])
476
+ sage: print(err)
477
+ ...
478
+ cython: error: cython: Need at least one source file
479
+
480
+ sage: # needs sage.symbolic
481
+ sage: def has_tty():
482
+ ....: try:
483
+ ....: os.open(os.ctermid(), os.O_RDONLY)
484
+ ....: return True
485
+ ....: except OSError:
486
+ ....: return False
487
+ sage: (out, err, ret) = test_executable(["sage", "--ecl"], "(* 12345 54321)\n")
488
+ sage: out.find("Embeddable Common-Lisp") >= 0
489
+ True
490
+ sage: out.find("670592745") >= 0
491
+ True
492
+ sage: err
493
+ ''
494
+ sage: ret
495
+ 0
496
+
497
+ sage: # needs sage.symbolic
498
+ sage: (out, err, ret) = test_executable(["sage", "--lisp"], "(* 12345 54321)\n")
499
+ sage: out.find("Embeddable Common-Lisp") >= 0
500
+ True
501
+ sage: out.find("670592745") >= 0
502
+ True
503
+ sage: err
504
+ ''
505
+ sage: ret
506
+ 0
507
+
508
+ sage: # needs sage.libs.gap
509
+ sage: # long time
510
+ sage: (out, err, ret) = test_executable([
511
+ ....: "sage", "--gap", "-q"], "Size(SymmetricGroup(5));\n")
512
+ sage: out
513
+ '120\n'
514
+ sage: err.replace('gap: halving pool size.', '').strip()
515
+ ''
516
+ sage: ret
517
+ 0
518
+
519
+ sage: (out, err, ret) = test_executable([ # long time # optional - gdb
520
+ ....: "sage", "--gdb"], 'quit\n')
521
+ sage: out.find('(gdb) ') >= 0 # long time # optional - gdb
522
+ True
523
+ sage: ret # long time # optional - gdb
524
+ 0
525
+
526
+ sage: # needs sage.libs.eclib
527
+ sage: (out, err, ret) = test_executable(["sage", "--mwrank", "-v0", "-q"], "0 0 0 0 1\n")
528
+ sage: out
529
+ 'Curve [0,0,0,0,1] :\tRank = 0\n\n'
530
+ sage: err
531
+ ''
532
+ sage: ret
533
+ 0
534
+
535
+ sage: # needs sage.libs.singular
536
+ sage: (out, err, ret) = test_executable(["sage", "--singular"], "12345*54321;\n")
537
+ sage: out.find("A Computer Algebra System for Polynomial Computations") >= 0
538
+ True
539
+ sage: out.find("670592745") >= 0
540
+ True
541
+ sage: err
542
+ ''
543
+ sage: ret
544
+ 0
545
+
546
+ Test GP using the ``-f`` option which prevents the reading of a ``.gprc``
547
+ configuration file::
548
+
549
+ sage: # needs sage.libs.pari
550
+ sage: (out, err, ret) = test_executable(["sage", "--gp", "-f"], "3^33\nquit(42)\n")
551
+ sage: out.find("PARI/GP") >= 0
552
+ True
553
+ sage: out.find("5559060566555523") >= 0
554
+ True
555
+ sage: err
556
+ ''
557
+ sage: ret
558
+ 42
559
+
560
+ Some programs of which we check functionality using only ``--version``::
561
+
562
+ sage: # needs sage.symbolic
563
+ sage: (out, err, ret) = test_executable(["sage", "--maxima", "--version"])
564
+ sage: out.find("Maxima ") >= 0
565
+ True
566
+ sage: err
567
+ ''
568
+ sage: ret
569
+ 0
570
+
571
+ sage: # optional - r
572
+ sage: (out, err, ret) = test_executable(["sage", "--R", "--version"])
573
+ sage: out.find("R version ") >= 0
574
+ True
575
+ sage: err
576
+ ''
577
+ sage: ret
578
+ 0
579
+
580
+ sage: (out, err, ret) = test_executable(["sage", "--sqlite3", "--version"])
581
+ sage: out.startswith("3.")
582
+ True
583
+ sage: err
584
+ ''
585
+ sage: ret
586
+ 0
587
+
588
+ Check some things requiring an internet connection::
589
+
590
+ sage: # optional - internet
591
+ sage: (out, err, ret) = test_executable(["sage", "--standard"])
592
+ sage: out.find("cython") >= 0
593
+ True
594
+ sage: err
595
+ ''
596
+ sage: ret
597
+ 0
598
+
599
+ sage: # optional - internet
600
+ sage: (out, err, ret) = test_executable(["sage", "--optional"])
601
+ sage: out.find("database_cremona_ellcurve") >= 0
602
+ True
603
+ sage: err
604
+ ''
605
+ sage: ret
606
+ 0
607
+
608
+ sage: # optional - internet
609
+ sage: (out, err, ret) = test_executable(["sage", "--experimental"])
610
+ sage: out.find("valgrind") >= 0
611
+ True
612
+ sage: err
613
+ ''
614
+ sage: ret
615
+ 0
616
+
617
+ Check an illegal command line option. This outputs an error to stdout,
618
+ but we allow stderr in case this changes in the future::
619
+
620
+ sage: (out, err, ret) = test_executable(["sage", "--zzfoobar"])
621
+ sage: (out+err).find("unknown option: --zzfoobar") >= 0
622
+ True
623
+ sage: ret > 0
624
+ True
625
+
626
+ Test ``sage --rst2ipynb file.rst`` on a ReST file::
627
+
628
+ sage: s = "::\n\n sage: 2^10\n 1024\n sage: 2 + 2\n 4"
629
+ sage: input = tmp_filename(ext='.rst')
630
+ sage: with open(input, 'w') as F:
631
+ ....: _ = F.write(s)
632
+ sage: L = ["sage", "--rst2ipynb", input]
633
+ sage: (out, err, ret) = test_executable(L) # optional - rst2ipynb
634
+ sage: err # optional - rst2ipynb
635
+ ''
636
+ sage: ret # optional - rst2ipynb
637
+ 0
638
+ sage: from json import loads # optional - rst2ipynb
639
+ sage: d = loads(out) # optional - rst2ipynb
640
+ sage: sorted(d.keys()) # optional - rst2ipynb
641
+ ['cells', 'metadata', 'nbformat', 'nbformat_minor']
642
+ sage: d['cells'][1]['source'] # optional - rst2ipynb
643
+ ['2^10']
644
+ sage: d['cells'][2]['source'] # optional - rst2ipynb
645
+ ['2 + 2']
646
+
647
+ Test ``sage --rst2ipynb file.rst file.ipynb`` on a ReST file::
648
+
649
+ sage: s = "::\n\n sage: 2^10\n 1024\n sage: 2 + 2\n 4"
650
+ sage: input = tmp_filename(ext='.rst')
651
+ sage: output = tmp_filename(ext='.ipynb')
652
+ sage: with open(input, 'w') as F:
653
+ ....: _ = F.write(s)
654
+ sage: L = ["sage", "--rst2ipynb", input, output]
655
+ sage: test_executable(L) # optional - rst2ipynb
656
+ ('', '', 0)
657
+ sage: import json # optional - rst2ipynb
658
+ sage: d = json.load(open(output,'r')) # optional - rst2ipynb
659
+ sage: type(d) # optional - rst2ipynb
660
+ <class 'dict'>
661
+ sage: sorted(d.keys()) # optional - rst2ipynb
662
+ ['cells', 'metadata', 'nbformat', 'nbformat_minor']
663
+ sage: d['metadata'] # optional - rst2ipynb
664
+ {'kernelspec': {'display_name': 'sagemath', 'name': 'sagemath'}}
665
+ sage: d['cells'][1]['cell_type'] # optional - rst2ipynb
666
+ 'code'
667
+
668
+ Test ``sage --ipynb2rst file.ipynb file.rst`` on a ipynb file::
669
+
670
+ sage: s = r'''{
671
+ ....: "cells": [
672
+ ....: {
673
+ ....: "cell_type": "code",
674
+ ....: "execution_count": 1,
675
+ ....: "metadata": {},
676
+ ....: "outputs": [
677
+ ....: {
678
+ ....: "data": {
679
+ ....: "text/plain": [
680
+ ....: "2"
681
+ ....: ]
682
+ ....: },
683
+ ....: "execution_count": 1,
684
+ ....: "metadata": {},
685
+ ....: "output_type": "execute_result"
686
+ ....: }
687
+ ....: ],
688
+ ....: "source": [
689
+ ....: "1+1"
690
+ ....: ]
691
+ ....: },
692
+ ....: {
693
+ ....: "cell_type": "code",
694
+ ....: "execution_count": null,
695
+ ....: "metadata": {},
696
+ ....: "outputs": [],
697
+ ....: "source": []
698
+ ....: }
699
+ ....: ],
700
+ ....: "metadata": {
701
+ ....: "kernelspec": {
702
+ ....: "display_name": "SageMath 8.3.beta4",
703
+ ....: "language": "",
704
+ ....: "name": "sagemath"
705
+ ....: },
706
+ ....: "language_info": {
707
+ ....: "codemirror_mode": {
708
+ ....: "name": "ipython",
709
+ ....: "version": 2
710
+ ....: },
711
+ ....: "file_extension": ".py",
712
+ ....: "mimetype": "text/x-python",
713
+ ....: "name": "python",
714
+ ....: "nbconvert_exporter": "python",
715
+ ....: "pygments_lexer": "ipython2",
716
+ ....: "version": "2.7.15"
717
+ ....: }
718
+ ....: },
719
+ ....: "nbformat": 4,
720
+ ....: "nbformat_minor": 2
721
+ ....: }
722
+ ....: '''
723
+ sage: t = '.. escape-backslashes\n.. default-role:: math\n\n\n::\n\n sage: 1+1\n 2\n\n\n\n\n'
724
+ sage: input = tmp_filename(ext='.ipynb')
725
+ sage: output = tmp_filename(ext='.rst')
726
+ sage: with open(input, 'w') as F:
727
+ ....: _ = F.write(s)
728
+ sage: L = ["sage", "--ipynb2rst", input, output]
729
+ sage: _ = test_executable(L) # long time # optional - pandoc
730
+ sage: print(open(output, 'r').read() == t) # long time # optional - pandoc # known bug #32697
731
+ True
732
+ """
733
+ pexpect_env = dict(os.environ)
734
+ try:
735
+ del pexpect_env["TERM"]
736
+ except KeyError:
737
+ pass
738
+
739
+ __with_pydebug = hasattr(sys, 'gettotalrefcount') # This is a Python debug build (--with-pydebug)
740
+ if __with_pydebug and pydebug_ignore_warnings:
741
+ pexpect_env['PYTHONWARNINGS'] = ','.join([
742
+ 'ignore::DeprecationWarning',
743
+ ])
744
+
745
+ kwds['encoding'] = kwds.pop('encoding', 'utf-8')
746
+
747
+ p = Popen(args, stdin=PIPE, stdout=PIPE, stderr=PIPE, env=pexpect_env,
748
+ **kwds)
749
+ if input:
750
+ p.stdin.write(input)
751
+
752
+ p.stdin.close()
753
+ fdout = p.stdout.fileno()
754
+ fderr = p.stderr.fileno()
755
+ out = []
756
+ err = []
757
+
758
+ while True:
759
+ # Try reading from fdout and fderr
760
+ rfd = []
761
+ if fdout:
762
+ rfd.append(fdout)
763
+ if fderr:
764
+ rfd.append(fderr)
765
+ if len(rfd) == 0:
766
+ break
767
+ timeout = float(timeout)
768
+ rlist = select.select(rfd, [], [], timeout)[0]
769
+
770
+ if len(rlist) == 0:
771
+ # Timeout!
772
+ p.terminate()
773
+ raise RuntimeError("timeout in test_executable()")
774
+ if fdout in rlist:
775
+ s = p.stdout.read(1024)
776
+ if not s:
777
+ fdout = None # EOF
778
+ p.stdout.close()
779
+ out.append(s)
780
+ if fderr in rlist:
781
+ s = p.stderr.read(1024)
782
+ if not s:
783
+ fderr = None # EOF
784
+ p.stderr.close()
785
+ err.append(s)
786
+
787
+ # In case out or err contains a quoted string, force the use of
788
+ # double quotes so that the output is enclosed in single
789
+ # quotes. This avoids some doctest failures with some versions of
790
+ # OS X and Xcode.
791
+ out = ''.join(out)
792
+ out = out.replace("'", '"')
793
+ err = ''.join(err)
794
+ err = err.replace("'", '"')
795
+
796
+ return (out, err, p.wait())