paula.testing: WIP
[paula.git] / paula.app.testing / src / paula / app / testing / interact.py
blob19f0f1606db560b5fb4b0617560cc5571a234302
2 # Copyright 2008, BlueDynamics Alliance, Austria - http://bluedynamics.com
4 # GNU General Public Licence Version 2 or later - see LICENCE.GPL
6 __author__ = """Jens Klein <jens@bluedynamics.com>"""
7 __docformat__ = 'plaintext'
9 import code
10 import sys
12 def interact(locals=None):
13 """Provides an interactive shell aka console inside your testcase.
15 It looks exact like in a doctestcase and you can copy and paste
16 code from the shell into your doctest. The locals in the testcase are
17 available, because you are _in_ the testcase.
19 In your testcase or doctest you can invoke the shell at any point by
20 calling::
22 >>> interact( locals() )
24 locals -- passed to InteractiveInterpreter.__init__()
25 """
26 savestdout = sys.stdout
27 sys.stdout = sys.stderr
28 sys.stderr.write('\n'+'='*75)
29 console = code.InteractiveConsole(locals)
30 console.interact("""
31 DocTest Interactive Console - (c) BlueDynamics Alliance, Austria, 2006-2008
32 Note: You have the same locals available as in your test-case.
33 Ctrl-D ends session and continues testing.
34 """)
35 sys.stdout.write('\nend of DocTest Interactive Console session\n')
36 sys.stdout.write('='*75+'\n')
37 sys.stdout = savestdout