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