def test_pylab_import_all_disabled(self): "Verify that plot is not available when pylab_import_all = False" source = """ from IPython.config.application import Application app = Application.instance() app.pylab_import_all = False pylab ip=get_ipython() 'plot' in ip.user_ns """ output = """ In \[1\]: from IPython\.config\.application import Application In \[2\]: app = Application\.instance\(\) In \[3\]: app\.pylab_import_all = False In \[4\]: pylab ^Welcome to pylab, a matplotlib-based Python environment For more information, type 'help\(pylab\)'\. In \[5\]: ip=get_ipython\(\) In \[6\]: \'plot\' in ip\.user_ns Out\[6\]: False """ runner = irunner.IPythonRunner(out=self.out) self._test_runner(runner, source, output)
def test_pylab_import_all_enabled(self): "Verify that plot is available when pylab_import_all = True" source = """ from IPython.config.application import Application app = Application.instance() app.pylab_import_all = True pylab ip=get_ipython() 'plot' in ip.user_ns """ output = """ In \[1\]: from IPython\.config\.application import Application In \[2\]: app = Application\.instance\(\) In \[3\]: app\.pylab_import_all = True In \[4\]: pylab ^Using matplotlib backend: Populating the interactive namespace from numpy and matplotlib In \[5\]: ip=get_ipython\(\) In \[6\]: \'plot\' in ip\.user_ns Out\[6\]: True """ runner = irunner.IPythonRunner(out=self.out) self._test_runner(runner,source,output)
def testIPython(self): """Test the IPython runner.""" source = """ print 'hello, this is python' # some more code x=1;y=2 x+y**2 # An example of autocall functionality from math import * autocall 1 cos pi autocall 0 cos pi cos(pi) for i in range(5): print i, print "that's all folks!" %Exit """ output = """\ In [1]: print 'hello, this is python' hello, this is python # some more code In [2]: x=1;y=2 In [3]: x+y**2 Out[3]: 5 # An example of autocall functionality In [4]: from math import * In [5]: autocall 1 Automatic calling is: Smart In [6]: cos pi ------> cos(pi) Out[6]: -1.0 In [7]: autocall 0 Automatic calling is: OFF In [8]: cos pi File "<ipython console>", line 1 cos pi ^ SyntaxError: invalid syntax In [9]: cos(pi) Out[9]: -1.0 In [10]: for i in range(5): ....: print i, ....: 0 1 2 3 4 In [11]: print "that's all folks!" that's all folks! In [12]: %Exit """ runner = irunner.IPythonRunner(out=self.out) self._test_runner(runner, source, output)