##// END OF EJS Templates
Test for magic names in multiline strings.
Thomas Kluyver -
Show More
@@ -1,88 +1,93 b''
1 1 """Tests for the key interactiveshell module.
2 2
3 3 Historically the main classes in interactiveshell have been under-tested. This
4 4 module should grow as many single-method tests as possible to trap many of the
5 5 recurring bugs we seem to encounter with high-level interaction.
6 6
7 7 Authors
8 8 -------
9 9 * Fernando Perez
10 10 """
11 11 #-----------------------------------------------------------------------------
12 12 # Copyright (C) 2011 The IPython Development Team
13 13 #
14 14 # Distributed under the terms of the BSD License. The full license is in
15 15 # the file COPYING, distributed as part of this software.
16 16 #-----------------------------------------------------------------------------
17 17
18 18 #-----------------------------------------------------------------------------
19 19 # Imports
20 20 #-----------------------------------------------------------------------------
21 21 # stdlib
22 22 import unittest
23 23 from IPython.testing import decorators as dec
24 24
25 25 #-----------------------------------------------------------------------------
26 26 # Tests
27 27 #-----------------------------------------------------------------------------
28 28
29 29 class InteractiveShellTestCase(unittest.TestCase):
30 30 def test_naked_string_cells(self):
31 31 """Test that cells with only naked strings are fully executed"""
32 32 ip = get_ipython()
33 33 # First, single-line inputs
34 34 ip.run_cell('"a"\n')
35 35 self.assertEquals(ip.user_ns['_'], 'a')
36 36 # And also multi-line cells
37 37 ip.run_cell('"""a\nb"""\n')
38 38 self.assertEquals(ip.user_ns['_'], 'a\nb')
39 39
40 40 def test_run_empty_cell(self):
41 41 """Just make sure we don't get a horrible error with a blank
42 42 cell of input. Yes, I did overlook that."""
43 43 ip = get_ipython()
44 44 old_xc = ip.execution_count
45 45 ip.run_cell('')
46 46 self.assertEquals(ip.execution_count, old_xc)
47 47
48 48 def test_run_cell_multiline(self):
49 49 """Multi-block, multi-line cells must execute correctly.
50 50 """
51 51 ip = get_ipython()
52 52 src = '\n'.join(["x=1",
53 53 "y=2",
54 54 "if 1:",
55 55 " x += 1",
56 56 " y += 1",])
57 57 ip.run_cell(src)
58 58 self.assertEquals(ip.user_ns['x'], 2)
59 59 self.assertEquals(ip.user_ns['y'], 3)
60 60
61 61 def test_multiline_string_cells(self):
62 62 "Code sprinkled with multiline strings should execute (GH-306)"
63 63 ip = get_ipython()
64 64 ip.run_cell('tmp=0')
65 65 self.assertEquals(ip.user_ns['tmp'], 0)
66 66 ip.run_cell('tmp=1;"""a\nb"""\n')
67 67 self.assertEquals(ip.user_ns['tmp'], 1)
68 68
69 69 def test_dont_cache_with_semicolon(self):
70 70 "Ending a line with semicolon should not cache the returned object (GH-307)"
71 71 ip = get_ipython()
72 72 oldlen = len(ip.user_ns['Out'])
73 73 a = ip.run_cell('1;')
74 74 newlen = len(ip.user_ns['Out'])
75 75 self.assertEquals(oldlen, newlen)
76 76 #also test the default caching behavior
77 77 ip.run_cell('1')
78 78 newlen = len(ip.user_ns['Out'])
79 79 self.assertEquals(oldlen+1, newlen)
80 80
81 81 def test_In_variable(self):
82 82 "Verify that In variable grows with user input (GH-284)"
83 83 ip = get_ipython()
84 84 oldlen = len(ip.user_ns['In'])
85 85 ip.run_cell('1;')
86 86 newlen = len(ip.user_ns['In'])
87 87 self.assertEquals(oldlen+1, newlen)
88 88 self.assertEquals(ip.user_ns['In'][-1],'1;')
89
90 def test_magic_names_in_string(self):
91 ip = get_ipython()
92 ip.run_cell('"""\n%exit\n"""')
93 self.assertEquals(ip.user_ns['In'][-1], '\n%exit\n')
General Comments 0
You need to be logged in to leave comments. Login now