def run_iptest(): """Run the IPython test suite using nose. This function is called when this script is **not** called with the form `iptest all`. It simply calls nose with appropriate command line flags and accepts all of the standard nose arguments. """ # Apply our monkeypatch to Xunit if '--with-xunit' in sys.argv and not hasattr(Xunit, 'orig_addError'): monkeypatch_xunit() warnings.filterwarnings( 'ignore', 'This will be removed soon. Use IPython.testing.util instead') argv = sys.argv + [ '--detailed-errors', # extra info in tracebacks '--with-ipdoctest', '--ipdoctest-tests', '--ipdoctest-extension=txt', # We add --exe because of setuptools' imbecility (it # blindly does chmod +x on ALL files). Nose does the # right thing and it tries to avoid executables, # setuptools unfortunately forces our hand here. This # has been discussed on the distutils list and the # setuptools devs refuse to fix this problem! '--exe', ] if '-a' not in argv and '-A' not in argv: argv = argv + ['-a', '!crash'] if nose.__version__ >= '0.11': # I don't fully understand why we need this one, but depending on what # directory the test suite is run from, if we don't give it, 0 tests # get run. Specifically, if the test suite is run from the source dir # with an argument (like 'iptest.py IPython.core', 0 tests are run, # even if the same call done in this directory works fine). It appears # that if the requested package is in the current dir, nose bails early # by default. Since it's otherwise harmless, leave it in by default # for nose >= 0.11, though unfortunately nose 0.10 doesn't support it. argv.append('--traverse-namespace') # use our plugin for doctesting. It will remove the standard doctest plugin # if it finds it enabled plugins = [IPythonDoctest(make_exclude()), KnownFailure()] # We need a global ipython running in this process, but the special # in-process group spawns its own IPython kernels, so for *that* group we # must avoid also opening the global one (otherwise there's a conflict of # singletons). Ultimately the solution to this problem is to refactor our # assumptions about what needs to be a singleton and what doesn't (app # objects should, individual shells shouldn't). But for now, this # workaround allows the test suite for the inprocess module to complete. if not 'IPython.kernel.inprocess' in sys.argv: globalipapp.start_ipython() # Now nose can run TestProgram(argv=argv, addplugins=plugins)
def run_iptest(): """Run the IPython test suite using nose. This function is called when this script is **not** called with the form `iptest all`. It simply calls nose with appropriate command line flags and accepts all of the standard nose arguments. """ # Apply our monkeypatch to Xunit if '--with-xunit' in sys.argv and not hasattr(Xunit, 'orig_addError'): monkeypatch_xunit() warnings.filterwarnings('ignore', 'This will be removed soon. Use IPython.testing.util instead') argv = sys.argv + [ '--detailed-errors', # extra info in tracebacks '--with-ipdoctest', '--ipdoctest-tests','--ipdoctest-extension=txt', # We add --exe because of setuptools' imbecility (it # blindly does chmod +x on ALL files). Nose does the # right thing and it tries to avoid executables, # setuptools unfortunately forces our hand here. This # has been discussed on the distutils list and the # setuptools devs refuse to fix this problem! '--exe', ] if '-a' not in argv and '-A' not in argv: argv = argv + ['-a', '!crash'] if nose.__version__ >= '0.11': # I don't fully understand why we need this one, but depending on what # directory the test suite is run from, if we don't give it, 0 tests # get run. Specifically, if the test suite is run from the source dir # with an argument (like 'iptest.py IPython.core', 0 tests are run, # even if the same call done in this directory works fine). It appears # that if the requested package is in the current dir, nose bails early # by default. Since it's otherwise harmless, leave it in by default # for nose >= 0.11, though unfortunately nose 0.10 doesn't support it. argv.append('--traverse-namespace') # use our plugin for doctesting. It will remove the standard doctest plugin # if it finds it enabled plugins = [IPythonDoctest(make_exclude()), KnownFailure()] # We need a global ipython running in this process, but the special # in-process group spawns its own IPython kernels, so for *that* group we # must avoid also opening the global one (otherwise there's a conflict of # singletons). Ultimately the solution to this problem is to refactor our # assumptions about what needs to be a singleton and what doesn't (app # objects should, individual shells shouldn't). But for now, this # workaround allows the test suite for the inprocess module to complete. if not 'IPython.kernel.inprocess' in sys.argv: globalipapp.start_ipython() # Now nose can run TestProgram(argv=argv, addplugins=plugins)
def run_iptest(): """Run the IPython test suite using nose. This function is called when this script is **not** called with the form `iptest all`. It simply calls nose with appropriate command line flags and accepts all of the standard nose arguments. """ warnings.filterwarnings( 'ignore', 'This will be removed soon. Use IPython.testing.util instead') argv = sys.argv + [ '--detailed-errors', # extra info in tracebacks # Loading ipdoctest causes problems with Twisted, but # our test suite runner now separates things and runs # all Twisted tests with trial. '--with-ipdoctest', '--ipdoctest-tests', '--ipdoctest-extension=txt', # We add --exe because of setuptools' imbecility (it # blindly does chmod +x on ALL files). Nose does the # right thing and it tries to avoid executables, # setuptools unfortunately forces our hand here. This # has been discussed on the distutils list and the # setuptools devs refuse to fix this problem! '--exe', ] if nose.__version__ >= '0.11': # I don't fully understand why we need this one, but depending on what # directory the test suite is run from, if we don't give it, 0 tests # get run. Specifically, if the test suite is run from the source dir # with an argument (like 'iptest.py IPython.core', 0 tests are run, # even if the same call done in this directory works fine). It appears # that if the requested package is in the current dir, nose bails early # by default. Since it's otherwise harmless, leave it in by default # for nose >= 0.11, though unfortunately nose 0.10 doesn't support it. argv.append('--traverse-namespace') # Construct list of plugins, omitting the existing doctest plugin, which # ours replaces (and extends). plugins = [IPythonDoctest(make_exclude()), KnownFailure()] for p in nose.plugins.builtin.plugins: plug = p() if plug.name == 'doctest': continue plugins.append(plug) # We need a global ipython running in this process globalipapp.start_ipython() # Now nose can run TestProgram(argv=argv, plugins=plugins)
def run_iptest(): """Run the IPython test suite using nose. This function is called when this script is **not** called with the form `iptest all`. It simply calls nose with appropriate command line flags and accepts all of the standard nose arguments. """ warnings.filterwarnings('ignore', 'This will be removed soon. Use IPython.testing.util instead') argv = sys.argv + [ '--detailed-errors', # extra info in tracebacks # Loading ipdoctest causes problems with Twisted, but # our test suite runner now separates things and runs # all Twisted tests with trial. '--with-ipdoctest', '--ipdoctest-tests','--ipdoctest-extension=txt', # We add --exe because of setuptools' imbecility (it # blindly does chmod +x on ALL files). Nose does the # right thing and it tries to avoid executables, # setuptools unfortunately forces our hand here. This # has been discussed on the distutils list and the # setuptools devs refuse to fix this problem! '--exe', ] if nose.__version__ >= '0.11': # I don't fully understand why we need this one, but depending on what # directory the test suite is run from, if we don't give it, 0 tests # get run. Specifically, if the test suite is run from the source dir # with an argument (like 'iptest.py IPython.core', 0 tests are run, # even if the same call done in this directory works fine). It appears # that if the requested package is in the current dir, nose bails early # by default. Since it's otherwise harmless, leave it in by default # for nose >= 0.11, though unfortunately nose 0.10 doesn't support it. argv.append('--traverse-namespace') # Construct list of plugins, omitting the existing doctest plugin, which # ours replaces (and extends). plugins = [IPythonDoctest(make_exclude()), KnownFailure()] for p in nose.plugins.builtin.plugins: plug = p() if plug.name == 'doctest': continue plugins.append(plug) # We need a global ipython running in this process globalipapp.start_ipython() # Now nose can run TestProgram(argv=argv, plugins=plugins)
def session_ip(): try: from IPython.testing.globalipapp import start_ipython return start_ipython() except ImportError: return None
def _init_shell(cls): """Initialize the shell.""" ip = start_ipython() ip.run_cell(raw_cell='from picatrix import notebook_init') ip.run_cell(raw_cell='notebook_init.init()') cls._shell = ip
def run_iptest(): """Run the IPython test suite using nose. This function is called when this script is **not** called with the form `iptest all`. It simply calls nose with appropriate command line flags and accepts all of the standard nose arguments. """ # Apply our monkeypatch to Xunit if "--with-xunit" in sys.argv and not hasattr(Xunit, "orig_addError"): monkeypatch_xunit() arg1 = sys.argv[1] if arg1.startswith("IPython/"): if arg1.endswith(".py"): arg1 = arg1[:-3] sys.argv[1] = arg1.replace("/", ".") arg1 = sys.argv[1] if arg1 in test_sections: section = test_sections[arg1] sys.argv[1:2] = section.includes elif arg1.startswith("IPython.") and arg1[8:] in test_sections: section = test_sections[arg1[8:]] sys.argv[1:2] = section.includes else: section = TestSection(arg1, includes=[arg1]) argv = sys.argv + [ "--detailed-errors", # extra info in tracebacks # We add --exe because of setuptools' imbecility (it # blindly does chmod +x on ALL files). Nose does the # right thing and it tries to avoid executables, # setuptools unfortunately forces our hand here. This # has been discussed on the distutils list and the # setuptools devs refuse to fix this problem! "--exe", ] if "-a" not in argv and "-A" not in argv: argv = argv + ["-a", "!crash"] if nose.__version__ >= "0.11": # I don't fully understand why we need this one, but depending on what # directory the test suite is run from, if we don't give it, 0 tests # get run. Specifically, if the test suite is run from the source dir # with an argument (like 'iptest.py IPython.core', 0 tests are run, # even if the same call done in this directory works fine). It appears # that if the requested package is in the current dir, nose bails early # by default. Since it's otherwise harmless, leave it in by default # for nose >= 0.11, though unfortunately nose 0.10 doesn't support it. argv.append("--traverse-namespace") plugins = [ ExclusionPlugin(section.excludes), KnownFailure(), SubprocessStreamCapturePlugin(), ] # we still have some vestigial doctests in core if section.name.startswith(("core", "IPython.core", "IPython.utils")): plugins.append(IPythonDoctest()) argv.extend([ "--with-ipdoctest", "--ipdoctest-tests", "--ipdoctest-extension=txt" ]) # Use working directory set by parent process (see iptestcontroller) if "IPTEST_WORKING_DIR" in os.environ: os.chdir(os.environ["IPTEST_WORKING_DIR"]) # We need a global ipython running in this process, but the special # in-process group spawns its own IPython kernels, so for *that* group we # must avoid also opening the global one (otherwise there's a conflict of # singletons). Ultimately the solution to this problem is to refactor our # assumptions about what needs to be a singleton and what doesn't (app # objects should, individual shells shouldn't). But for now, this # workaround allows the test suite for the inprocess module to complete. if "kernel.inprocess" not in section.name: from IPython.testing import globalipapp globalipapp.start_ipython() # Now nose can run TestProgram(argv=argv, addplugins=plugins)
def session_ip(): return start_ipython()
def run_iptest(): """Run the IPython test suite using nose. This function is called when this script is **not** called with the form `iptest all`. It simply calls nose with appropriate command line flags and accepts all of the standard nose arguments. """ # Apply our monkeypatch to Xunit if '--with-xunit' in sys.argv and not hasattr(Xunit, 'orig_addError'): monkeypatch_xunit() arg1 = sys.argv[1] if arg1 in test_sections: section = test_sections[arg1] sys.argv[1:2] = section.includes elif arg1.startswith('IPython.') and arg1[8:] in test_sections: section = test_sections[arg1[8:]] sys.argv[1:2] = section.includes else: section = TestSection(arg1, includes=[arg1]) argv = sys.argv + [ '--detailed-errors', # extra info in tracebacks # We add --exe because of setuptools' imbecility (it # blindly does chmod +x on ALL files). Nose does the # right thing and it tries to avoid executables, # setuptools unfortunately forces our hand here. This # has been discussed on the distutils list and the # setuptools devs refuse to fix this problem! '--exe', ] if '-a' not in argv and '-A' not in argv: argv = argv + ['-a', '!crash'] if nose.__version__ >= '0.11': # I don't fully understand why we need this one, but depending on what # directory the test suite is run from, if we don't give it, 0 tests # get run. Specifically, if the test suite is run from the source dir # with an argument (like 'iptest.py IPython.core', 0 tests are run, # even if the same call done in this directory works fine). It appears # that if the requested package is in the current dir, nose bails early # by default. Since it's otherwise harmless, leave it in by default # for nose >= 0.11, though unfortunately nose 0.10 doesn't support it. argv.append('--traverse-namespace') plugins = [ ExclusionPlugin(section.excludes), KnownFailure(), SubprocessStreamCapturePlugin() ] # we still have some vestigial doctests in core if (section.name.startswith(('core', 'IPython.core', 'IPython.utils'))): plugins.append(IPythonDoctest()) argv.extend([ '--with-ipdoctest', '--ipdoctest-tests', '--ipdoctest-extension=txt', ]) # Use working directory set by parent process (see iptestcontroller) if 'IPTEST_WORKING_DIR' in os.environ: os.chdir(os.environ['IPTEST_WORKING_DIR']) # We need a global ipython running in this process, but the special # in-process group spawns its own IPython kernels, so for *that* group we # must avoid also opening the global one (otherwise there's a conflict of # singletons). Ultimately the solution to this problem is to refactor our # assumptions about what needs to be a singleton and what doesn't (app # objects should, individual shells shouldn't). But for now, this # workaround allows the test suite for the inprocess module to complete. if 'kernel.inprocess' not in section.name: from IPython.testing import globalipapp globalipapp.start_ipython() # Now nose can run TestProgram(argv=argv, addplugins=plugins)
def setUpClass(cls): super().setUpClass() globalipapp.start_ipython()
import nose import sys if sys.version_info.major == 2: from StringIO import StringIO else: from io import StringIO if sys.version_info >= (3, 3): from unittest import mock else: import mock if not IPython.get_ipython(): from IPython.testing import globalipapp globalipapp.start_ipython() ip = IPython.get_ipython() def setup(): ip.extension_manager.load_extension('powershellmagic') def test_powershell_no_flags(): cell = "echo hello" with mock.patch("sys.stdout", StringIO()) as out: ip.run_cell_magic("powershell", "", cell) nose.tools.assert_equal(out.getvalue(), "hello\r\n")
def session_ip(): yield start_ipython()
from IPython.core.error import UsageError import newtabmagic if sys.version_info.major == 2: from StringIO import StringIO else: from io import StringIO if sys.version_info >= (3, 3): from unittest.mock import patch else: from mock import patch if not IPython.get_ipython(): from IPython.testing import globalipapp globalipapp.start_ipython() @contextlib.contextmanager def server_running(newtab): newtab.newtab('--server start') try: yield finally: newtab.newtab('--server stop') def _get_newtabmagic(browser='firefox', port=None): ip = IPython.get_ipython() ip.reset() newtab = newtabmagic.NewTabMagics(ip)
def session_ip(): __initTestMocks() return start_ipython()