Show More
@@ -1,64 +1,76 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 | |
|
24 | 24 | #----------------------------------------------------------------------------- |
|
25 | 25 | # Tests |
|
26 | 26 | #----------------------------------------------------------------------------- |
|
27 | 27 | |
|
28 | 28 | class InteractiveShellTestCase(unittest.TestCase): |
|
29 | 29 | def test_naked_string_cells(self): |
|
30 | 30 | """Test that cells with only naked strings are fully executed""" |
|
31 | 31 | ip = get_ipython() |
|
32 | 32 | # First, single-line inputs |
|
33 | 33 | ip.run_cell('"a"\n') |
|
34 | 34 | self.assertEquals(ip.user_ns['_'], 'a') |
|
35 | 35 | # And also multi-line cells |
|
36 | 36 | ip.run_cell('"""a\nb"""\n') |
|
37 | 37 | self.assertEquals(ip.user_ns['_'], 'a\nb') |
|
38 | 38 | |
|
39 | 39 | def test_run_empty_cell(self): |
|
40 | 40 | """Just make sure we don't get a horrible error with a blank |
|
41 | 41 | cell of input. Yes, I did overlook that.""" |
|
42 | 42 | ip = get_ipython() |
|
43 | 43 | ip.run_cell('') |
|
44 | 44 | |
|
45 | 45 | def test_run_cell_multiline(self): |
|
46 | 46 | """Multi-block, multi-line cells must execute correctly. |
|
47 | 47 | """ |
|
48 | 48 | ip = get_ipython() |
|
49 | 49 | src = '\n'.join(["x=1", |
|
50 | 50 | "y=2", |
|
51 | 51 | "if 1:", |
|
52 | 52 | " x += 1", |
|
53 | 53 | " y += 1",]) |
|
54 | 54 | ip.run_cell(src) |
|
55 | 55 | self.assertEquals(ip.user_ns['x'], 2) |
|
56 | 56 | self.assertEquals(ip.user_ns['y'], 3) |
|
57 | 57 | |
|
58 | 58 | def test_multiline_string_cells(self): |
|
59 |
|
|
|
59 | "Code sprinkled with multiline strings should execute (GH-306)" | |
|
60 | 60 | ip = get_ipython() |
|
61 | 61 | ip.run_cell('tmp=0') |
|
62 | 62 | self.assertEquals(ip.user_ns['tmp'], 0) |
|
63 | 63 | ip.run_cell('tmp=1;"""a\nb"""\n') |
|
64 | 64 | self.assertEquals(ip.user_ns['tmp'], 1) |
|
65 | ||
|
66 | def test_dont_cache_with_semicolon(self): | |
|
67 | "Ending a line with semicolon should not cache the returned object (GH-307)" | |
|
68 | ip = get_ipython() | |
|
69 | oldlen = len(ip.user_ns['Out']) | |
|
70 | a = ip.run_cell('1;') | |
|
71 | newlen = len(ip.user_ns['Out']) | |
|
72 | self.assertEquals(oldlen, newlen) | |
|
73 | #also test the default caching behavior | |
|
74 | a = ip.run_cell('1') | |
|
75 | newlen = len(ip.user_ns['Out']) | |
|
76 | self.assertEquals(oldlen+1, newlen) |
General Comments 0
You need to be logged in to leave comments.
Login now