##// END OF EJS Templates
Do not update the unders if they are user defined...
Do not update the unders if they are user defined Closes jupyter/notebook#1628 (once there are tests). Still shift the internal reference to self._,__,___ but do not assign it in user ns. I would expect this to be a change of behavior and have the (slight) side effect that if any of the _, __, or __ are defined, then none of these are updated. We could update the logic to do the right think on leapfrog _, __ or __ if user-set, but is it worth it. If _ is in builtins, then _ will not update the history and _ will be the builtins, unless user set it explicitly in which case it takes precedence. Summary if user have set _ _ == value set by the user elif _ in builtins: _ == value in builtins._ else: _ == previous result. Note that this logic may fall down if the use set _ to a specific value, and have this save value returned while _ is also in builtin: In [1]: import gettext ; gettext.install('foo') In [2]: _ = 'Example' In [3]: _ Out[3]: 'Example' In [4]: _ Out[4]: 'Example' In [5]: _ Out[5]: <bound method NullTranslations.gettext of <...>>

File last commit:

r22838:138b3a4a
r22838:138b3a4a
Show More
test_displayhook.py
55 lines | 1.6 KiB | text/x-python | PythonLexer
from IPython.testing.tools import AssertPrints, AssertNotPrints
ip = get_ipython()
def test_output_displayed():
"""Checking to make sure that output is displayed"""
with AssertPrints('2'):
ip.run_cell('1+1', store_history=True)
with AssertPrints('2'):
ip.run_cell('1+1 # comment with a semicolon;', store_history=True)
with AssertPrints('2'):
ip.run_cell('1+1\n#commented_out_function();', store_history=True)
def test_output_quiet():
"""Checking to make sure that output is quiet"""
with AssertNotPrints('2'):
ip.run_cell('1+1;', store_history=True)
with AssertNotPrints('2'):
ip.run_cell('1+1; # comment with a semicolon', store_history=True)
with AssertNotPrints('2'):
ip.run_cell('1+1;\n#commented_out_function()', store_history=True)
def test_underscore_no_overrite_user():
ip.run_cell('_ = 42', store_history=True)
ip.run_cell('1+1', store_history=True)
with AssertPrints('42'):
ip.run_cell('print(_)', store_history=True)
ip.run_cell('del _', store_history=True)
ip.run_cell('6+6', store_history=True)
with AssertPrints('12'):
ip.run_cell('_', store_history=True)
def test_underscore_no_overrite_builtins():
ip.run_cell("import gettext ; gettext.install('foo')", store_history=True)
ip.run_cell('3+3', store_history=True)
with AssertPrints('gettext'):
ip.run_cell('print(_)', store_history=True)
ip.run_cell('_ = "userset"', store_history=True)
with AssertPrints('userset'):
ip.run_cell('print(_)', store_history=True)
ip.run_cell('import builtins; del builtins._')