##// END OF EJS Templates
Close #147
fperez -
Show More

The requested changes are too big and content was truncated. Show full diff

1 NO CONTENT: modified file
The requested commit or file is too big and content was truncated. Show full diff
@@ -1,156 +1,168 b''
1 1 #!/usr/bin/env python
2 2 """Test suite for the irunner module.
3 3
4 4 Not the most elegant or fine-grained, but it does cover at least the bulk
5 5 functionality."""
6 6
7 7 # Global to make tests extra verbose and help debugging
8 8 VERBOSE = True
9 9
10 10 # stdlib imports
11 11 import cStringIO as StringIO
12 import sys
12 13 import unittest
13 14
14 15 # IPython imports
15 16 from IPython import irunner
16 from IPython.OutputTrap import OutputTrap
17 17
18 18 # Testing code begins
19 19 class RunnerTestCase(unittest.TestCase):
20 20
21 def setUp(self):
22 self.out = StringIO.StringIO()
23 #self.out = sys.stdout
24
21 25 def _test_runner(self,runner,source,output):
22 26 """Test that a given runner's input/output match."""
23 27
24 log = OutputTrap(out_head='',quiet_out=True)
25 log.trap_out()
26 28 runner.run_source(source)
27 log.release_out()
28 out = log.summary_out()
29 out = self.out.getvalue()
30 #out = ''
29 31 # this output contains nasty \r\n lineends, and the initial ipython
30 32 # banner. clean it up for comparison
31 33 output_l = output.split()
32 34 out_l = out.split()
33 35 mismatch = 0
36 #if len(output_l) != len(out_l):
37 # self.fail('mismatch in number of lines')
34 38 for n in range(len(output_l)):
39 # Do a line-by-line comparison
35 40 ol1 = output_l[n].strip()
36 41 ol2 = out_l[n].strip()
37 42 if ol1 != ol2:
38 43 mismatch += 1
39 44 if VERBOSE:
40 45 print '<<< line %s does not match:' % n
41 46 print repr(ol1)
42 47 print repr(ol2)
43 48 print '>>>'
44 49 self.assert_(mismatch==0,'Number of mismatched lines: %s' %
45 50 mismatch)
46 51
47 52 def testIPython(self):
48 53 """Test the IPython runner."""
49 54 source = """
50 55 print 'hello, this is python'
51 56
52 57 # some more code
53 58 x=1;y=2
54 59 x+y**2
55 60
56 61 # An example of autocall functionality
57 62 from math import *
58 63 autocall 1
59 64 cos pi
60 65 autocall 0
61 66 cos pi
62 67 cos(pi)
63 68
64 69 for i in range(5):
65 70 print i,
66 71
67 72 print "that's all folks!"
68 73
69 74 %Exit
70 75 """
71 76 output = """\
72 77 In [1]: print 'hello, this is python'
73 78 hello, this is python
74 79
75 In [2]: # some more code
76 80
77 In [3]: x=1;y=2
81 # some more code
82 In [2]: x=1;y=2
78 83
79 In [4]: x+y**2
80 Out[4]: 5
84 In [3]: x+y**2
85 Out[3]: 5
81 86
82 In [5]: # An example of autocall functionality
83 87
84 In [6]: from math import *
88 # An example of autocall functionality
89 In [4]: from math import *
85 90
86 In [7]: autocall 1
91 In [5]: autocall 1
87 92 Automatic calling is: Smart
88 93
89 In [8]: cos pi
94 In [6]: cos pi
90 95 ------> cos(pi)
91 Out[8]: -1.0
96 Out[6]: -1.0
92 97
93 In [9]: autocall 0
98 In [7]: autocall 0
94 99 Automatic calling is: OFF
95 100
96 In [10]: cos pi
101 In [8]: cos pi
97 102 ------------------------------------------------------------
98 103 File "<ipython console>", line 1
99 104 cos pi
100 105 ^
101 SyntaxError: invalid syntax
106 <type 'exceptions.SyntaxError'>: invalid syntax
107
102 108
109 In [9]: cos(pi)
110 Out[9]: -1.0
103 111
104 In [11]: cos(pi)
105 Out[11]: -1.0
106 112
107 In [12]: for i in range(5):
108 ....: print i,
109 ....:
113 In [10]: for i in range(5):
114 ....: print i,
115 ....:
110 116 0 1 2 3 4
111 117
112 In [13]: print "that's all folks!"
118 In [11]: print "that's all folks!"
113 119 that's all folks!
114 120
115 In [14]: %Exit"""
116 runner = irunner.IPythonRunner()
121
122 In [12]: %Exit
123 """
124 runner = irunner.IPythonRunner(out=self.out)
117 125 self._test_runner(runner,source,output)
118 126
119 127 def testPython(self):
120 128 """Test the Python runner."""
121 runner = irunner.PythonRunner()
129 runner = irunner.PythonRunner(out=self.out)
122 130 source = """
123 131 print 'hello, this is python'
124 132
125 133 # some more code
126 134 x=1;y=2
127 135 x+y**2
128 136
129 137 from math import *
130 138 cos(pi)
131 139
132 140 for i in range(5):
133 141 print i,
134 142
135 143 print "that's all folks!"
136 144 """
137 145 output = """\
138 146 >>> print 'hello, this is python'
139 147 hello, this is python
140 >>> # some more code
141 ... x=1;y=2
148
149 # some more code
150 >>> x=1;y=2
142 151 >>> x+y**2
143 152 5
153
144 154 >>> from math import *
145 155 >>> cos(pi)
146 156 -1.0
157
147 158 >>> for i in range(5):
148 159 ... print i,
149 160 ...
150 161 0 1 2 3 4
151 162 >>> print "that's all folks!"
152 that's all folks!"""
163 that's all folks!
164 """
153 165 self._test_runner(runner,source,output)
154 166
155 167 if __name__ == '__main__':
156 168 unittest.main()
General Comments 0
You need to be logged in to leave comments. Login now