##// END OF EJS Templates
Fix exception color problems in win32....
Fix exception color problems in win32. In all the recent work to have the test suite play nice with doctest of full ipython sessions, I inadvertedly started sending exceptions directly to sys.stderr. On windows we MUST go via Term.cerr, which uses pyreadline to handle color escapes, while sys.stderr just shows garbage on screen. As of this revision, the test suite passes fully on win32 and linux, and interactive use also seems OK on all fronts. We're getting closer to RC status...

File last commit:

r1061:58bebece
r2459:e687d797
Show More
test_embed.py
47 lines | 1.3 KiB | text/x-python | PythonLexer
Ville M. Vainio
more crlf
r1033 """ An example of one way to embed IPython in your own application
This basically means starting up IPython with some of your programs objects visible in the IPython
user namespace.
"""
import sys
Ville M. Vainio
ipapi: allow specifying shell class in launch_new_instance & make_new instance. Use this in test_embed.py
r1060 sys.path.insert(1,'..')
Ville M. Vainio
more crlf
r1033
import IPython.ipapi
Ville M. Vainio
ipapi: allow specifying shell class in launch_new_instance & make_new instance. Use this in test_embed.py
r1060 def test_session(shellclass):
print "*****************\nLaunch shell for",shellclass
my_ns = dict(a=10)
Ville M. Vainio
test_embed: actually CALL the specified shell class
r1061 ses = IPython.ipapi.make_session(my_ns, shellclass=shellclass)
Ville M. Vainio
ipapi: allow specifying shell class in launch_new_instance & make_new instance. Use this in test_embed.py
r1060
# Now get the ipapi instance, to be stored somewhere in your program for manipulation of the running
# IPython session. See http://ipython.scipy.org/moin/IpythonExtensionApi
ip = ses.IP.getapi()
# let's play with the ipapi a bit, creating a magic function for a soon-to-be-started IPython
def mymagic_f(self,s):
print "mymagic says",s
ip.expose_magic("mymagic",mymagic_f)
# And finally, start the IPython interaction! This will block until you say Exit.
ses.mainloop()
print "IPython session for shell ",shellclass," finished! namespace content:"
for k,v in my_ns.items():
print k,':',str(v)[:80].rstrip()
import IPython.Shell
Ville M. Vainio
test_embed: actually CALL the specified shell class
r1061 def do_test(arg_line):
test_session(IPython.Shell._select_shell(arg_line.split()))
do_test('')
do_test('ipython -gthread')
do_test('ipython -q4thread')
do_test('ipython -pylab')
do_test('ipython -pylab -gthread')