##// END OF EJS Templates
Merge with upstream
Merge with upstream

File last commit:

r1505:ab84d206
r1507:2d65d859 merge
Show More
test_prefilterfrontend.py
157 lines | 4.2 KiB | text/x-python | PythonLexer
/ IPython / frontend / tests / test_prefilterfrontend.py
Gael Varoquaux
More tests of the frontend. Improve the ease of testing.
r1458 # encoding: utf-8
"""
Test process execution and IO redirection.
"""
__docformat__ = "restructuredtext en"
#-------------------------------------------------------------------------------
# Copyright (C) 2008 The IPython Development Team
#
# Distributed under the terms of the BSD License. The full license is
# in the file COPYING, distributed as part of this software.
#-------------------------------------------------------------------------------
from cStringIO import StringIO
import string
Gael Varoquaux
Fix tests when ipdoctest nose plugin is enable (Grrr, no isolation at...
r1505
Gael Varoquaux
Make the prefilterfrontend take an optional ipython0 instance as the...
r1504 from IPython.ipapi import get as get_ipython0
Gael Varoquaux
Fix tests when ipdoctest nose plugin is enable (Grrr, no isolation at...
r1505 from IPython.frontend.prefilterfrontend import PrefilterFrontEnd
Gael Varoquaux
More tests of the frontend. Improve the ease of testing.
r1458
class TestPrefilterFrontEnd(PrefilterFrontEnd):
input_prompt_template = string.Template('')
output_prompt_template = string.Template('')
Gael Varoquaux
Fix tests when ipdoctest nose plugin is enable (Grrr, no isolation at...
r1505 banner = ''
Gael Varoquaux
More tests of the frontend. Improve the ease of testing.
r1458
gvaroquaux
More tests....
r1460 def __init__(self):
Gael Varoquaux
Fix tests when ipdoctest nose plugin is enable (Grrr, no isolation at...
r1505 ipython0 = get_ipython0().IP
Gael Varoquaux
More tests of the frontend. Improve the ease of testing.
r1458 self.out = StringIO()
Gael Varoquaux
Make the prefilterfrontend take an optional ipython0 instance as the...
r1504 PrefilterFrontEnd.__init__(self, ipython0=ipython0)
Gael Varoquaux
Fix tests when ipdoctest nose plugin is enable (Grrr, no isolation at...
r1505 # Clean up the namespace for isolation between tests
user_ns = self.ipython0.user_ns
# We need to keep references to things so that they don't
# get garbage collected (this stinks).
self.shadow_ns = dict()
for i in self.ipython0.magic_who_ls():
self.shadow_ns[i] = user_ns.pop(i)
# Some more code for isolation (yeah, crazy)
self._on_enter()
self.out.flush()
self.out.reset()
self.out.truncate()
def write(self, string, *args, **kwargs):
Gael Varoquaux
More tests of the frontend. Improve the ease of testing.
r1458 self.out.write(string)
def _on_enter(self):
gvaroquaux
More code reuse between GUI-independant frontend and Wx frontend: getting...
r1462 self.input_buffer += '\n'
Gael Varoquaux
More tests of the frontend. Improve the ease of testing.
r1458 PrefilterFrontEnd._on_enter(self)
def test_execution():
""" Test execution of a command.
"""
gvaroquaux
More tests....
r1460 f = TestPrefilterFrontEnd()
Gael Varoquaux
Fix tests when ipdoctest nose plugin is enable (Grrr, no isolation at...
r1505 f.input_buffer = 'print 1'
Gael Varoquaux
More tests of the frontend. Improve the ease of testing.
r1458 f._on_enter()
Gael Varoquaux
Fix tests when ipdoctest nose plugin is enable (Grrr, no isolation at...
r1505 out_value = f.out.getvalue()
assert out_value == '1\n'
Gael Varoquaux
More tests of the frontend. Improve the ease of testing.
r1458
def test_multiline():
""" Test execution of a multiline command.
"""
gvaroquaux
More tests....
r1460 f = TestPrefilterFrontEnd()
gvaroquaux
More code reuse between GUI-independant frontend and Wx frontend: getting...
r1462 f.input_buffer = 'if True:'
Gael Varoquaux
More tests of the frontend. Improve the ease of testing.
r1458 f._on_enter()
gvaroquaux
More code reuse between GUI-independant frontend and Wx frontend: getting...
r1462 f.input_buffer += 'print 1'
Gael Varoquaux
More tests of the frontend. Improve the ease of testing.
r1458 f._on_enter()
Gael Varoquaux
Fix tests when ipdoctest nose plugin is enable (Grrr, no isolation at...
r1505 out_value = f.out.getvalue()
assert out_value == ''
Gael Varoquaux
More tests of the frontend. Improve the ease of testing.
r1458 f._on_enter()
Gael Varoquaux
Fix tests when ipdoctest nose plugin is enable (Grrr, no isolation at...
r1505 out_value = f.out.getvalue()
assert out_value == '1\n'
gvaroquaux
More tests....
r1460 f = TestPrefilterFrontEnd()
gvaroquaux
More code reuse between GUI-independant frontend and Wx frontend: getting...
r1462 f.input_buffer='(1 +'
Gael Varoquaux
More tests of the frontend. Improve the ease of testing.
r1458 f._on_enter()
gvaroquaux
More code reuse between GUI-independant frontend and Wx frontend: getting...
r1462 f.input_buffer += '0)'
Gael Varoquaux
More tests of the frontend. Improve the ease of testing.
r1458 f._on_enter()
Gael Varoquaux
Fix tests when ipdoctest nose plugin is enable (Grrr, no isolation at...
r1505 out_value = f.out.getvalue()
assert out_value == ''
Gael Varoquaux
More tests of the frontend. Improve the ease of testing.
r1458 f._on_enter()
Gael Varoquaux
Fix tests when ipdoctest nose plugin is enable (Grrr, no isolation at...
r1505 out_value = f.out.getvalue()
assert out_value == '1\n'
Gael Varoquaux
More tests of the frontend. Improve the ease of testing.
r1458
def test_capture():
""" Test the capture of output in different channels.
"""
gvaroquaux
More tests....
r1460 # Test on the OS-level stdout, stderr.
f = TestPrefilterFrontEnd()
gvaroquaux
More code reuse between GUI-independant frontend and Wx frontend: getting...
r1462 f.input_buffer = \
'import os; out=os.fdopen(1, "w"); out.write("1") ; out.flush()'
Gael Varoquaux
More tests of the frontend. Improve the ease of testing.
r1458 f._on_enter()
Gael Varoquaux
Fix tests when ipdoctest nose plugin is enable (Grrr, no isolation at...
r1505 out_value = f.out.getvalue()
assert out_value == '1'
gvaroquaux
More tests....
r1460 f = TestPrefilterFrontEnd()
gvaroquaux
More code reuse between GUI-independant frontend and Wx frontend: getting...
r1462 f.input_buffer = \
'import os; out=os.fdopen(2, "w"); out.write("1") ; out.flush()'
Gael Varoquaux
More tests of the frontend. Improve the ease of testing.
r1458 f._on_enter()
Gael Varoquaux
Fix tests when ipdoctest nose plugin is enable (Grrr, no isolation at...
r1505 out_value = f.out.getvalue()
assert out_value == '1'
gvaroquaux
More tests....
r1460
Gael Varoquaux
More tests of the frontend. Improve the ease of testing.
r1458
gvaroquaux
More tests....
r1460 def test_magic():
""" Test the magic expansion and history.
This test is fairly fragile and will break when magics change.
"""
f = TestPrefilterFrontEnd()
Gael Varoquaux
Fix tests when ipdoctest nose plugin is enable (Grrr, no isolation at...
r1505 f.input_buffer += '%who'
gvaroquaux
More tests....
r1460 f._on_enter()
Gael Varoquaux
Fix tests when ipdoctest nose plugin is enable (Grrr, no isolation at...
r1505 out_value = f.out.getvalue()
assert out_value == 'Interactive namespace is empty.\n'
gvaroquaux
More frontend tests.
r1461
def test_help():
""" Test object inspection.
"""
f = TestPrefilterFrontEnd()
gvaroquaux
More code reuse between GUI-independant frontend and Wx frontend: getting...
r1462 f.input_buffer += "def f():"
gvaroquaux
More tests....
r1460 f._on_enter()
gvaroquaux
More code reuse between GUI-independant frontend and Wx frontend: getting...
r1462 f.input_buffer += "'foobar'"
gvaroquaux
More frontend tests.
r1461 f._on_enter()
gvaroquaux
More code reuse between GUI-independant frontend and Wx frontend: getting...
r1462 f.input_buffer += "pass"
gvaroquaux
More frontend tests.
r1461 f._on_enter()
f._on_enter()
gvaroquaux
More code reuse between GUI-independant frontend and Wx frontend: getting...
r1462 f.input_buffer += "f?"
gvaroquaux
More frontend tests.
r1461 f._on_enter()
Gael Varoquaux
Fix tests when ipdoctest nose plugin is enable (Grrr, no isolation at...
r1505 assert 'traceback' not in f.last_result
## XXX: ipython doctest magic breaks this. I have no clue why
#out_value = f.out.getvalue()
#assert out_value.split()[-1] == 'foobar'
gvaroquaux
More frontend tests.
r1461
gvaroquaux
More code reuse between GUI-independant frontend and Wx frontend: getting...
r1462
gvaroquaux
More frontend tests.
r1461 def test_completion():
""" Test command-line completion.
"""
f = TestPrefilterFrontEnd()
gvaroquaux
More code reuse between GUI-independant frontend and Wx frontend: getting...
r1462 f.input_buffer = 'zzza = 1'
gvaroquaux
More frontend tests.
r1461 f._on_enter()
gvaroquaux
More code reuse between GUI-independant frontend and Wx frontend: getting...
r1462 f.input_buffer = 'zzzb = 2'
gvaroquaux
More frontend tests.
r1461 f._on_enter()
gvaroquaux
More code reuse between GUI-independant frontend and Wx frontend: getting...
r1462 f.input_buffer = 'zz'
gvaroquaux
Test completion.
r1464 f.complete_current_input()
Gael Varoquaux
Fix tests when ipdoctest nose plugin is enable (Grrr, no isolation at...
r1505 out_value = f.out.getvalue()
assert out_value == '\nzzza zzzb '
gvaroquaux
Test completion.
r1464 assert f.input_buffer == 'zzz'
gvaroquaux
More frontend tests.
r1461
Gael Varoquaux
More tests of the frontend. Improve the ease of testing.
r1458
if __name__ == '__main__':
gvaroquaux
More frontend tests.
r1461 test_magic()
test_help()
Gael Varoquaux
More tests of the frontend. Improve the ease of testing.
r1458 test_execution()
test_multiline()
test_capture()
gvaroquaux
Test completion.
r1464 test_completion()