Skip to content
This repository

store_history=False default for run_cell #878

Merged
merged 3 commits into from over 2 years ago

2 participants

Thomas Kluyver Fernando Perez
Thomas Kluyver
Collaborator

We should only call run_cell with store_history=True as part of the main user interaction loop (and in the test suite), so this makes the default False.

I've also fixed #865 (following @minrk's suggestion). That meant the tests for %cpaste had to be changed, because errors from pasted code are caught before they reach the test code. We now check that the traceback is printed, although that's a more brittle check.

Fernando Perez fperez merged commit cdfc2e6 into from October 14, 2011
Fernando Perez fperez closed this October 14, 2011
Fernando Perez fperez referenced this pull request from a commit January 10, 2012
Commit has since been removed from the repository and is no longer available.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 3 unique commits by 1 author.

Oct 15, 2011
Thomas Kluyver Change run_cell to not store history by default. 3ac262c
Thomas Kluyver Use run_cell for %paste, instead of plain exec.
Closes gh-865, but introduces test failures for %cpaste
9281c5b
Thomas Kluyver Fix tests for cpaste which no longer get error raised to them.
Less elegant than before, because we now look for the traceback being printed.
4d338ff
This page is out of date. Refresh to see the latest.
2  IPython/core/interactiveshell.py
@@ -2252,7 +2252,7 @@ def safe_execfile_ipy(self, fname):
2252 2252
                 self.showtraceback()
2253 2253
                 warn('Unknown failure executing file: <%s>' % fname)
2254 2254
 
2255  
-    def run_cell(self, raw_cell, store_history=True):
  2255
+    def run_cell(self, raw_cell, store_history=False):
2256 2256
         """Run a complete IPython cell.
2257 2257
 
2258 2258
         Parameters
2  IPython/core/magic.py
@@ -3246,7 +3246,7 @@ def _execute_block(self, block, par):
3246 3246
         if not par:
3247 3247
             b = textwrap.dedent(block)
3248 3248
             self.user_ns['pasted_block'] = b
3249  
-            exec b in self.user_ns
  3249
+            self.run_cell(b)
3250 3250
         else:
3251 3251
             self.user_ns[par] = SList(block.splitlines())
3252 3252
             print "Block assigned to '%s'" % par
6  IPython/core/tests/test_history.py
@@ -112,10 +112,10 @@ def test_extract_hist_ranges():
112 112
 def test_magic_rerun():
113 113
     """Simple test for %rerun (no args -> rerun last line)"""
114 114
     ip = get_ipython()
115  
-    ip.run_cell("a = 10")
116  
-    ip.run_cell("a += 1")
  115
+    ip.run_cell("a = 10", store_history=True)
  116
+    ip.run_cell("a += 1", store_history=True)
117 117
     nt.assert_equal(ip.user_ns["a"], 11)
118  
-    ip.run_cell("%rerun")
  118
+    ip.run_cell("%rerun", store_history=True)
119 119
     nt.assert_equal(ip.user_ns["a"], 12)
120 120
 
121 121
 def test_timestamp_type():
6  IPython/core/tests/test_interactiveshell.py
@@ -73,11 +73,11 @@ def test_dont_cache_with_semicolon(self):
73 73
         "Ending a line with semicolon should not cache the returned object (GH-307)"
74 74
         ip = get_ipython()
75 75
         oldlen = len(ip.user_ns['Out'])
76  
-        a = ip.run_cell('1;')
  76
+        a = ip.run_cell('1;', store_history=True)
77 77
         newlen = len(ip.user_ns['Out'])
78 78
         self.assertEquals(oldlen, newlen)
79 79
         #also test the default caching behavior
80  
-        ip.run_cell('1')
  80
+        ip.run_cell('1', store_history=True)
81 81
         newlen = len(ip.user_ns['Out'])
82 82
         self.assertEquals(oldlen+1, newlen)
83 83
 
@@ -85,7 +85,7 @@ def test_In_variable(self):
85 85
         "Verify that In variable grows with user input (GH-284)"
86 86
         ip = get_ipython()
87 87
         oldlen = len(ip.user_ns['In'])
88  
-        ip.run_cell('1;')
  88
+        ip.run_cell('1;', store_history=True)
89 89
         newlen = len(ip.user_ns['In'])
90 90
         self.assertEquals(oldlen+1, newlen)
91 91
         self.assertEquals(ip.user_ns['In'][-1],'1;')
16  IPython/core/tests/test_magic.py
@@ -171,7 +171,7 @@ def test_macro_run():
171 171
     cmds = ["a=10", "a+=1", py3compat.doctest_refactor_print("print a"),
172 172
                                                             "%macro test 2-3"]
173 173
     for cmd in cmds:
174  
-        ip.run_cell(cmd)
  174
+        ip.run_cell(cmd, store_history=True)
175 175
     nt.assert_equal(ip.user_ns["test"].value,
176 176
                             py3compat.doctest_refactor_print("a+=1\nprint a\n"))
177 177
     with tt.AssertPrints("12"):
@@ -316,6 +316,7 @@ def check_cpaste(code, should_fail=False):
316 316
     _ip.user_ns['code_ran'] = False
317 317
 
318 318
     src = StringIO()
  319
+    src.encoding = None   # IPython expects stdin to have an encoding attribute
319 320
     src.write('\n')
320 321
     src.write(code)
321 322
     src.write('\n--\n')
@@ -325,15 +326,12 @@ def check_cpaste(code, should_fail=False):
325 326
     sys.stdin = src
326 327
     
327 328
     try:
328  
-        _ip.magic('cpaste')
329  
-    except:
  329
+        context = tt.AssertPrints if should_fail else tt.AssertNotPrints
  330
+        with context("Traceback (most recent call last)"):
  331
+                _ip.magic('cpaste')
  332
+        
330 333
         if not should_fail:
331  
-            raise AssertionError("Failure not expected : '%s'" %
332  
-                                 code)
333  
-    else:
334  
-        assert _ip.user_ns['code_ran']
335  
-        if should_fail:
336  
-            raise AssertionError("Failure expected : '%s'" % code)
  334
+            assert _ip.user_ns['code_ran']
337 335
     finally:
338 336
         sys.stdin = stdin_save
339 337
 
2  IPython/frontend/terminal/interactiveshell.py
@@ -309,7 +309,7 @@ def interact(self, display_banner=None):
309 309
                     self.edit_syntax_error()
310 310
                 if not more:
311 311
                     source_raw = self.input_splitter.source_raw_reset()[1]
312  
-                    self.run_cell(source_raw)
  312
+                    self.run_cell(source_raw, store_history=True)
313 313
 
314 314
         # We are off again...
315 315
         __builtin__.__dict__['__IPYTHON__active'] -= 1
2  IPython/zmq/ipkernel.py
@@ -250,7 +250,7 @@ def execute_request(self, ident, parent):
250 250
                 shell.run_code(code)
251 251
             else:
252 252
                 # FIXME: the shell calls the exception handler itself.
253  
-                shell.run_cell(code)
  253
+                shell.run_cell(code, store_history=True)
254 254
         except:
255 255
             status = u'error'
256 256
             # FIXME: this code right now isn't being used yet by default,
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.