Ticket #12719: trac_12719-preparse-doctest.patch

File trac_12719-preparse-doctest.patch, 1.4 KB (added by jhpalmieri, 9 years ago)
  • sage/misc/sage_extension.py

    # HG changeset patch
    # User J. H. Palmieri <palmieri@math.washington.edu>
    # Date 1351024956 25200
    # Node ID d946ca7a4114cbd6b4e0431cbf11f12753dfb1e0
    # Parent  e669e8774fe13af66d738e8d765b42ea4ad43c8f
    Doctest that "%runfile blah" is not preparsed, but "%time blah" is.
    
    diff --git a/sage/misc/sage_extension.py b/sage/misc/sage_extension.py
    a b A Sage extension which adds sage-specifi 
    1111* running init.sage
    1212* changing prompt to Sage prompt
    1313* Display hook
     14
     15TESTS:
     16
     17We test that preparsing is off for ``%runfile``, on for ``%time``::
     18
     19    sage: import os, re
     20    sage: from sage.misc.interpreter import get_test_shell
     21    sage: from sage.misc.misc import tmp_dir
     22    sage: shell = get_test_shell()
     23    sage: TMP = tmp_dir()
     24
     25The temporary directory should have a name of the form
     26``.../12345/...``, to demonstrate that file names are not
     27preparsed when calling ``%runfile``. ::
     28
     29    sage: bool(re.search('/[0-9]+/', TMP))
     30    True
     31    sage: tmp = os.path.join(TMP, 'run_cell.py')
     32    sage: f = open(tmp, 'w'); f.write('a = 2\n'); f.close()
     33    sage: shell.run_cell('%runfile '+tmp)
     34    sage: shell.run_cell('a')
     35    2
     36
     37In contrast, input to the ``%time`` magic command is preparsed::
     38
     39    sage: shell.run_cell('%time 594.factor()')
     40    CPU times: user ...
     41    Wall time: ...
     42    2 * 3^3 * 11
    1443"""
    1544
    1645from IPython.core.hooks import TryNext