##// END OF EJS Templates
Close #147
fperez -
Show More
@@ -1,3 +1,7 b''
1 2007-05-02 Fernando Perez <Fernando.Perez@colorado.edu>
2
3 * test/test_irunner.py (RunnerTestCase._test_runner): Close #147.
4
1 2007-04-30 Ville Vainio <vivainio@gmail.com>
5 2007-04-30 Ville Vainio <vivainio@gmail.com>
2
6
3 * iplib.py: (pre_config_initialization) Catch UnicodeDecodeError if the
7 * iplib.py: (pre_config_initialization) Catch UnicodeDecodeError if the
@@ -9,29 +9,34 b' 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:
@@ -72,53 +77,56 b' print "that\'s all folks!"'
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
@@ -137,19 +145,23 b' print "that\'s all folks!"'
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__':
General Comments 0
You need to be logged in to leave comments. Login now