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