Show More
@@ -1,57 +1,64 | |||||
1 | """Tests for the key interactiveshell module. |
|
1 | """Tests for the key interactiveshell module. | |
2 |
|
2 | |||
3 | Historically the main classes in interactiveshell have been under-tested. This |
|
3 | Historically the main classes in interactiveshell have been under-tested. This | |
4 | module should grow as many single-method tests as possible to trap many of the |
|
4 | module should grow as many single-method tests as possible to trap many of the | |
5 | recurring bugs we seem to encounter with high-level interaction. |
|
5 | recurring bugs we seem to encounter with high-level interaction. | |
6 |
|
6 | |||
7 | Authors |
|
7 | Authors | |
8 | ------- |
|
8 | ------- | |
9 | * Fernando Perez |
|
9 | * Fernando Perez | |
10 | """ |
|
10 | """ | |
11 | #----------------------------------------------------------------------------- |
|
11 | #----------------------------------------------------------------------------- | |
12 | # Copyright (C) 2011 The IPython Development Team |
|
12 | # Copyright (C) 2011 The IPython Development Team | |
13 | # |
|
13 | # | |
14 | # Distributed under the terms of the BSD License. The full license is in |
|
14 | # Distributed under the terms of the BSD License. The full license is in | |
15 | # the file COPYING, distributed as part of this software. |
|
15 | # the file COPYING, distributed as part of this software. | |
16 | #----------------------------------------------------------------------------- |
|
16 | #----------------------------------------------------------------------------- | |
17 |
|
17 | |||
18 | #----------------------------------------------------------------------------- |
|
18 | #----------------------------------------------------------------------------- | |
19 | # Imports |
|
19 | # Imports | |
20 | #----------------------------------------------------------------------------- |
|
20 | #----------------------------------------------------------------------------- | |
21 | # stdlib |
|
21 | # stdlib | |
22 | import unittest |
|
22 | import unittest | |
23 |
|
23 | |||
24 | #----------------------------------------------------------------------------- |
|
24 | #----------------------------------------------------------------------------- | |
25 | # Tests |
|
25 | # Tests | |
26 | #----------------------------------------------------------------------------- |
|
26 | #----------------------------------------------------------------------------- | |
27 |
|
27 | |||
28 | class InteractiveShellTestCase(unittest.TestCase): |
|
28 | class InteractiveShellTestCase(unittest.TestCase): | |
29 | def test_naked_string_cells(self): |
|
29 | def test_naked_string_cells(self): | |
30 | """Test that cells with only naked strings are fully executed""" |
|
30 | """Test that cells with only naked strings are fully executed""" | |
31 | ip = get_ipython() |
|
31 | ip = get_ipython() | |
32 | # First, single-line inputs |
|
32 | # First, single-line inputs | |
33 | ip.run_cell('"a"\n') |
|
33 | ip.run_cell('"a"\n') | |
34 | self.assertEquals(ip.user_ns['_'], 'a') |
|
34 | self.assertEquals(ip.user_ns['_'], 'a') | |
35 | # And also multi-line cells |
|
35 | # And also multi-line cells | |
36 | ip.run_cell('"""a\nb"""\n') |
|
36 | ip.run_cell('"""a\nb"""\n') | |
37 | self.assertEquals(ip.user_ns['_'], 'a\nb') |
|
37 | self.assertEquals(ip.user_ns['_'], 'a\nb') | |
38 |
|
38 | |||
39 | def test_run_empty_cell(self): |
|
39 | def test_run_empty_cell(self): | |
40 | """Just make sure we don't get a horrible error with a blank |
|
40 | """Just make sure we don't get a horrible error with a blank | |
41 | cell of input. Yes, I did overlook that.""" |
|
41 | cell of input. Yes, I did overlook that.""" | |
42 | ip = get_ipython() |
|
42 | ip = get_ipython() | |
43 | ip.run_cell('') |
|
43 | ip.run_cell('') | |
44 |
|
44 | |||
45 | def test_run_cell_multilne(self): |
|
45 | def test_run_cell_multiline(self): | |
46 | """Multi-block, multi-line cells must execute correctly. |
|
46 | """Multi-block, multi-line cells must execute correctly. | |
47 | """ |
|
47 | """ | |
48 | ip = get_ipython() |
|
48 | ip = get_ipython() | |
49 | src = '\n'.join(["x=1", |
|
49 | src = '\n'.join(["x=1", | |
50 | "y=2", |
|
50 | "y=2", | |
51 | "if 1:", |
|
51 | "if 1:", | |
52 | " x += 1", |
|
52 | " x += 1", | |
53 | " y += 1",]) |
|
53 | " y += 1",]) | |
54 | ip.run_cell(src) |
|
54 | ip.run_cell(src) | |
55 | self.assertEquals(ip.user_ns['x'], 2) |
|
55 | self.assertEquals(ip.user_ns['x'], 2) | |
56 | self.assertEquals(ip.user_ns['y'], 3) |
|
56 | self.assertEquals(ip.user_ns['y'], 3) | |
57 |
|
57 | |||
|
58 | def test_multiline_string_cells(self): | |||
|
59 | """Code sprinkled with multiline strings should execute (GH-306)""" | |||
|
60 | ip = get_ipython() | |||
|
61 | ip.run_cell('tmp=0') | |||
|
62 | self.assertEquals(ip.user_ns['tmp'], 0) | |||
|
63 | ip.run_cell('tmp=1;"""a\nb"""\n') | |||
|
64 | self.assertEquals(ip.user_ns['tmp'], 1) |
General Comments 0
You need to be logged in to leave comments.
Login now