##// END OF EJS Templates
Merging -r 1177 from lp:ipython with fixes and resolutions....
Brian Granger -
r2124:4a54d9d3 merge
parent child Browse files
Show More
@@ -25,14 +25,14 b' def test_rehashx():'
25 25 _ip.magic('rehashx')
26 26 # Practically ALL ipython development systems will have more than 10 aliases
27 27
28 assert len(_ip.IP.alias_table) > 10
28 yield (nt.assert_true, len(_ip.IP.alias_table) > 10)
29 29 for key, val in _ip.IP.alias_table.items():
30 30 # we must strip dots from alias names
31 assert '.' not in key
31 nt.assert_true('.' not in key)
32 32
33 33 # rehashx must fill up syscmdlist
34 34 scoms = _ip.db['syscmdlist']
35 assert len(scoms) > 10
35 yield (nt.assert_true, len(scoms) > 10)
36 36
37 37
38 38 def doctest_hist_f():
@@ -42,7 +42,8 b' def doctest_hist_f():'
42 42
43 43 In [10]: tfile = tempfile.mktemp('.py','tmp-ipython-')
44 44
45 In [11]: %history -n -f $tfile 3
45 In [11]: %hist -n -f $tfile 3
46
46 47 """
47 48
48 49
@@ -51,9 +52,12 b' def doctest_hist_r():'
51 52
52 53 XXX - This test is not recording the output correctly. Not sure why...
53 54
55 In [20]: 'hist' in _ip.IP.lsmagic()
56 Out[20]: True
57
54 58 In [6]: x=1
55 59
56 In [7]: hist -n -r 2
60 In [7]: %hist -n -r 2
57 61 x=1 # random
58 62 hist -n -r 2 # random
59 63 """
@@ -94,12 +98,13 b' def test_shist():'
94 98
95 99 @dec.skipif_not_numpy
96 100 def test_numpy_clear_array_undec():
101 from IPython.extensions import clearcmd
102
97 103 _ip.ex('import numpy as np')
98 104 _ip.ex('a = np.empty(2)')
99
100 yield nt.assert_true,'a' in _ip.user_ns
105 yield (nt.assert_true, 'a' in _ip.user_ns)
101 106 _ip.magic('clear array')
102 yield nt.assert_false,'a' in _ip.user_ns
107 yield (nt.assert_false, 'a' in _ip.user_ns)
103 108
104 109
105 110 @dec.skip()
@@ -91,7 +91,7 b' from inspect import getsourcefile, getfile, getmodule,\\'
91 91 # IPython's own modules
92 92 # Modified pdb which doesn't damage IPython's readline handling
93 93 from IPython.utils import PyColorize
94 from IPython.core import debugger
94 from IPython.core import debugger, ipapi
95 95 from IPython.utils.ipstruct import Struct
96 96 from IPython.core.excolors import exception_colors
97 97 from IPython.utils.genutils import Term,uniq_stable,error,info
@@ -268,10 +268,12 b' def _formatTracebackLines(lnum, index, lines, Colors, lvals=None,scheme=None):'
268 268
269 269 # This lets us get fully syntax-highlighted tracebacks.
270 270 if scheme is None:
271 try:
272 scheme = __IPYTHON__.rc.colors
273 except:
271 ipinst = ipapi.get()
272 if ipinst is not None:
273 scheme = ipinst.IP.rc.colors
274 else:
274 275 scheme = DEFAULT_SCHEME
276
275 277 _line_format = _parser.format2
276 278
277 279 for line in lines:
@@ -490,7 +492,9 b' class ListTB(TBTools):'
490 492
491 493 # vds:>>
492 494 if have_filedata:
493 __IPYTHON__.hooks.synchronize_with_editor(filename, lineno, 0)
495 ipinst = ipapi.get()
496 if ipinst is not None:
497 ipinst.IP.hooks.synchronize_with_editor(filename, lineno, 0)
494 498 # vds:<<
495 499
496 500 return list
@@ -810,7 +814,9 b' class VerboseTB(TBTools):'
810 814 filepath, lnum = records[-1][1:3]
811 815 #print "file:", str(file), "linenb", str(lnum) # dbg
812 816 filepath = os.path.abspath(filepath)
813 __IPYTHON__.hooks.synchronize_with_editor(filepath, lnum, 0)
817 ipinst = ipapi.get()
818 if ipinst is not None:
819 ipinst.IP.hooks.synchronize_with_editor(filepath, lnum, 0)
814 820 # vds: <<
815 821
816 822 # return all our info assembled as a single string
@@ -15,6 +15,7 b' __docformat__ = "restructuredtext en"'
15 15 from copy import copy, deepcopy
16 16 from cStringIO import StringIO
17 17 import string
18 import sys
18 19
19 20 from nose.tools import assert_equal
20 21
@@ -23,22 +24,6 b' from IPython.core.ipapi import get as get_ipython0'
23 24 from IPython.testing.plugin.ipdoctest import default_argv
24 25
25 26
26 def safe_deepcopy(d):
27 """ Deep copy every key of the given dict, when possible. Elsewhere
28 do a copy.
29 """
30 copied_d = dict()
31 for key, value in d.iteritems():
32 try:
33 copied_d[key] = deepcopy(value)
34 except:
35 try:
36 copied_d[key] = copy(value)
37 except:
38 copied_d[key] = value
39 return copied_d
40
41
42 27 class TestPrefilterFrontEnd(PrefilterFrontEnd):
43 28
44 29 input_prompt_template = string.Template('')
@@ -72,17 +57,34 b' def isolate_ipython0(func):'
72 57 with arguments.
73 58 """
74 59 def my_func():
75 iplib = get_ipython0()
76 if iplib is None:
60 ip0 = get_ipython0()
61 if ip0 is None:
77 62 return func()
78 ipython0 = iplib.IP
79 global_ns = safe_deepcopy(ipython0.user_global_ns)
80 user_ns = safe_deepcopy(ipython0.user_ns)
63 # We have a real ipython running...
64 user_ns = ip0.IP.user_ns
65 user_global_ns = ip0.IP.user_global_ns
66
67 # Previously the isolation was attempted with a deep copy of the user
68 # dicts, but we found cases where this didn't work correctly. I'm not
69 # quite sure why, but basically it did damage the user namespace, such
70 # that later tests stopped working correctly. Instead we use a simpler
71 # approach, just computing the list of added keys to the namespace and
72 # eliminating those afterwards. Existing keys that may have been
73 # modified remain modified. So far this has proven to be robust.
74
75 # Compute set of old local/global keys
76 old_locals = set(user_ns.keys())
77 old_globals = set(user_global_ns.keys())
81 78 try:
82 79 out = func()
83 80 finally:
84 ipython0.user_ns = user_ns
85 ipython0.user_global_ns = global_ns
81 # Find new keys, and if any, remove them
82 new_locals = set(user_ns.keys()) - old_locals
83 new_globals = set(user_global_ns.keys()) - old_globals
84 for k in new_locals:
85 del user_ns[k]
86 for k in new_globals:
87 del user_global_ns[k]
86 88 # Undo the hack at creation of PrefilterFrontEnd
87 89 from IPython.core import iplib
88 90 iplib.InteractiveShell.isthreaded = False
@@ -97,7 +99,7 b' def test_execution():'
97 99 """ Test execution of a command.
98 100 """
99 101 f = TestPrefilterFrontEnd()
100 f.input_buffer = 'print 1'
102 f.input_buffer = 'print(1)'
101 103 f._on_enter()
102 104 out_value = f.out.getvalue()
103 105 assert_equal(out_value, '1\n')
@@ -228,7 +230,14 b' def test_completion_indexing():'
228 230 f._on_enter()
229 231 f.input_buffer = 'a[0].'
230 232 f.complete_current_input()
231 assert_equal(f.input_buffer, 'a[0].__')
233
234 if sys.version_info[:2] >= (2,6):
235 # In Python 2.6, ints picked up a few non __ methods, so now there are
236 # no completions.
237 assert_equal(f.input_buffer, 'a[0].')
238 else:
239 # Right answer for 2.4/2.5
240 assert_equal(f.input_buffer, 'a[0].__')
232 241
233 242
234 243 @isolate_ipython0
@@ -238,8 +247,13 b' def test_completion_equal():'
238 247 f = TestPrefilterFrontEnd()
239 248 f.input_buffer = 'a=1.'
240 249 f.complete_current_input()
241 assert_equal(f.input_buffer, 'a=1.__')
242
250 if sys.version_info[:2] >= (2,6):
251 # In Python 2.6, ints picked up a few non __ methods, so now there are
252 # no completions.
253 assert_equal(f.input_buffer, 'a=1.')
254 else:
255 # Right answer for 2.4/2.5
256 assert_equal(f.input_buffer, 'a=1.__')
243 257
244 258
245 259 if __name__ == '__main__':
@@ -26,7 +26,7 b' import sys'
26 26
27 27 from twisted.internet.error import ConnectionRefusedError
28 28
29 from IPython.ultraTB import _fixed_getinnerframes, findsource
29 from IPython.core.ultratb import _fixed_getinnerframes, findsource
30 30 from IPython.core import ipapi
31 31
32 32 from IPython.kernel import error
@@ -29,7 +29,7 b' import sys'
29 29 import traceback
30 30
31 31 # Local imports.
32 from IPython.kernel.core import ultraTB
32 from IPython.core import ultratb
33 33 from IPython.kernel.core.display_trap import DisplayTrap
34 34 from IPython.kernel.core.macro import Macro
35 35 from IPython.kernel.core.prompts import CachedOutput
@@ -167,9 +167,9 b' class Interpreter(object):'
167 167 formatters=self.traceback_formatters)
168 168
169 169 # This is used temporarily for reformating exceptions in certain
170 # cases. It will go away once the ultraTB stuff is ported
170 # cases. It will go away once the ultratb stuff is ported
171 171 # to ipython1
172 self.tbHandler = ultraTB.FormattedTB(color_scheme='NoColor',
172 self.tbHandler = ultratb.FormattedTB(color_scheme='NoColor',
173 173 mode='Context',
174 174 tb_offset=2)
175 175
@@ -50,6 +50,7 b' def test_for(mod):'
50 50
51 51 have_curses = test_for('_curses')
52 52 have_wx = test_for('wx')
53 have_wx_aui = test_for('wx.aui')
53 54 have_zi = test_for('zope.interface')
54 55 have_twisted = test_for('twisted')
55 56 have_foolscap = test_for('foolscap')
@@ -67,8 +68,9 b' def make_exclude():'
67 68 pjoin('IPython', 'frontend', 'process', 'winprocess.py'),
68 69 pjoin('IPython_doctest_plugin'),
69 70 pjoin('IPython', 'extensions', 'ipy_'),
70 pjoin('IPython', 'extensions', 'clearcmd'),
71 pjoin('IPython', 'extensions', 'PhysicalQInput'),
71 72 pjoin('IPython', 'extensions', 'PhysicalQInteractive'),
73 pjoin('IPython', 'extensions', 'InterpreterPasteInput'),
72 74 pjoin('IPython', 'extensions', 'scitedirector'),
73 75 pjoin('IPython', 'extensions', 'numeric_formats'),
74 76 pjoin('IPython', 'testing', 'attic'),
@@ -81,6 +83,9 b' def make_exclude():'
81 83 EXCLUDE.append(pjoin('IPython', 'gui'))
82 84 EXCLUDE.append(pjoin('IPython', 'frontend', 'wx'))
83 85
86 if not have_wx_aui:
87 EXCLUDE.append(pjoin('IPython', 'gui', 'wx', 'wxIPython'))
88
84 89 if not have_objc:
85 90 EXCLUDE.append(pjoin('IPython', 'frontend', 'cocoa'))
86 91
@@ -111,6 +116,7 b' def make_exclude():'
111 116
112 117 return EXCLUDE
113 118
119
114 120 #-----------------------------------------------------------------------------
115 121 # Functions and classes
116 122 #-----------------------------------------------------------------------------
@@ -237,7 +243,7 b' def run_iptestall():'
237 243 t_start = time.time()
238 244 for name,runner in runners.iteritems():
239 245 print '*'*77
240 print 'IPython test set:', name
246 print 'IPython test group:',name
241 247 res = runner.run()
242 248 if res:
243 249 failed[name] = res
@@ -248,14 +254,14 b' def run_iptestall():'
248 254 # summarize results
249 255 print
250 256 print '*'*77
251 print 'Ran %s test sets in %.3fs' % (nrunners, t_tests)
257 print 'Ran %s test groups in %.3fs' % (nrunners, t_tests)
252 258 print
253 259 if not failed:
254 260 print 'OK'
255 261 else:
256 262 # If anything went wrong, point out what command to rerun manually to
257 263 # see the actual errors and individual summary
258 print 'ERROR - %s out of %s test sets failed.' % (nfail, nrunners)
264 print 'ERROR - %s out of %s test groups failed.' % (nfail, nrunners)
259 265 for name in failed:
260 266 failed_runner = runners[name]
261 267 print '-'*40
@@ -276,4 +282,4 b' def main():'
276 282
277 283
278 284 if __name__ == '__main__':
279 main() No newline at end of file
285 main()
@@ -208,6 +208,15 b' def start_ipython():'
208 208 _ip.IP.magic_run_ori = _ip.IP.magic_run
209 209 _ip.IP.magic_run = im
210 210
211 # XXX - For some very bizarre reason, the loading of %history by default is
212 # failing. This needs to be fixed later, but for now at least this ensures
213 # that tests that use %hist run to completion.
214 from IPython.core import history
215 history.init_ipython(_ip)
216 if not hasattr(_ip.IP,'magic_history'):
217 raise RuntimeError("Can't load magics, aborting")
218
219
211 220 # The start call MUST be made here. I'm not sure yet why it doesn't work if
212 221 # it is made later, at plugin initialization time, but in all my tests, that's
213 222 # the case.
@@ -881,7 +881,7 b' def doctest_reload():'
881 881
882 882 This routine:
883 883
884 - reloads doctest
884 - imports doctest but does NOT reload it (see below).
885 885
886 886 - resets its global 'master' attribute to None, so that multiple uses of
887 887 the module interactively don't produce cumulative reports.
@@ -890,20 +890,20 b' def doctest_reload():'
890 890 modified displayhook. Doctest expects the default displayhook behavior
891 891 deep down, so our modification breaks it completely. For this reason, a
892 892 hard monkeypatch seems like a reasonable solution rather than asking
893 users to manually use a different doctest runner when under IPython."""
893 users to manually use a different doctest runner when under IPython.
894 894
895 import doctest
896 reload(doctest)
897 doctest.master=None
895 Note
896 ----
898 897
899 try:
900 doctest.DocTestRunner
901 except AttributeError:
902 # This is only for python 2.3 compatibility, remove once we move to
903 # 2.4 only.
904 pass
905 else:
906 doctest.DocTestRunner.run = dhook_wrap(doctest.DocTestRunner.run)
898 This function *used to* reload doctest, but this has been disabled because
899 reloading doctest unconditionally can cause massive breakage of other
900 doctest-dependent modules already in memory, such as those for IPython's
901 own testing system. The name wasn't changed to avoid breaking people's
902 code, but the reload call isn't actually made anymore."""
903
904 import doctest
905 doctest.master = None
906 doctest.DocTestRunner.run = dhook_wrap(doctest.DocTestRunner.run)
907 907
908 908 #----------------------------------------------------------------------------
909 909 class HomeDirError(Error):
@@ -3,6 +3,8 b''
3 3
4 4 from IPython.kernel import client
5 5 import time
6 import sys
7 flush = sys.stdout.flush
6 8
7 9 tc = client.TaskClient()
8 10 mec = client.MultiEngineClient()
@@ -16,6 +18,7 b' for i in range(6):'
16 18 time.sleep(1.0)
17 19 print "Queue status (vebose=False)"
18 20 print tc.queue_status()
21 flush()
19 22
20 23 for i in range(24):
21 24 tc.run(client.StringTask('time.sleep(1)'))
@@ -24,12 +27,14 b' for i in range(6):'
24 27 time.sleep(1.0)
25 28 print "Queue status (vebose=True)"
26 29 print tc.queue_status(True)
30 flush()
27 31
28 32 for i in range(12):
29 33 tc.run(client.StringTask('time.sleep(2)'))
30 34
31 35 print "Queue status (vebose=True)"
32 36 print tc.queue_status(True)
37 flush()
33 38
34 39 qs = tc.queue_status(True)
35 40 sched = qs['scheduled']
@@ -41,4 +46,5 b' for i in range(6):'
41 46 time.sleep(1.0)
42 47 print "Queue status (vebose=True)"
43 48 print tc.queue_status(True)
49 flush()
44 50
@@ -1329,8 +1329,9 b' For stand-alone use of the feature in your programs which do not use'
1329 1329 IPython at all, put the following lines toward the top of your 'main'
1330 1330 routine::
1331 1331
1332 import sys,IPython.ultraTB
1333 sys.excepthook = IPython.ultraTB.FormattedTB(mode='Verbose',
1332 import sys
1333 from IPython.core import ultratb
1334 sys.excepthook = ultratb.FormattedTB(mode='Verbose',
1334 1335 color_scheme='Linux', call_pdb=1)
1335 1336
1336 1337 The mode keyword can be either 'Verbose' or 'Plain', giving either very
1 NO CONTENT: file was removed
This diff has been collapsed as it changes many lines, (1067 lines changed) Show them Hide them
General Comments 0
You need to be logged in to leave comments. Login now