当前位置: 首页>>代码示例>>Python>>正文


Python utils.get_kernel函数代码示例

本文整理汇总了Python中metakernel.tests.utils.get_kernel函数的典型用法代码示例。如果您正苦于以下问题:Python get_kernel函数的具体用法?Python get_kernel怎么用?Python get_kernel使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了get_kernel函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_python_magic3

def test_python_magic3():
    kernel = get_kernel()
    kernel.do_execute('%%python -e\n1 + 2', None)
    magic = kernel.get_magic('%%python')
    assert magic.retval is None

    kernel = get_kernel()
    kernel.do_execute('%%python\n1 + 2', None)
    magic = kernel.get_magic('%%python')
    assert magic.retval == 3
开发者ID:Calysto,项目名称:metakernel,代码行数:10,代码来源:test_python_magic.py

示例2: test_option

def test_option():
    kernel = get_kernel()
    d = Dummy(kernel)
    assert 'Options:' in d.line_dummy.__doc__
    assert '--size' in d.line_dummy.__doc__

    ret = d.call_magic('line', 'dummy', '', 'hey -s400,200')
    assert ret == d
    assert d.foo == 'hey', d.foo
    assert d.size == (400, 200)

    ret = d.call_magic('line', 'dummy', '', 'hey there')
    assert d.foo == 'hey there'

    ret = d.call_magic('line', 'dummy', '', 'range(1, 10)')
    assert d.foo == range(1, 10)

    ret = d.call_magic('line', 'dummy', '', '[1, 2, 3]')
    assert d.foo == [1, 2, 3]

    ret = d.call_magic('line', 'dummy', '', 'hey -l -s400,200')
    assert d.size == (400, 200)
    assert d.foo == "hey -l"

    ret = d.call_magic('line', 'dummy', '', 'hey -s -- -s400,200')
    assert d.size == (400, 200)
    assert d.foo == "hey -s"
开发者ID:Foucl,项目名称:metakernel,代码行数:27,代码来源:test_magic.py

示例3: test_help_magic

def test_help_magic():
    kernel = get_kernel()
    kernel.do_execute('?%magic', None)
    text = get_log_text(kernel)
    assert '%magic - show installed magics' in text, repr(text)

    kernel.do_execute('%lsmagic??', None)
    text = get_log_text(kernel)
    assert 'class LSMagicMagic' in text

    kernel.do_execute('?', None)
    text = get_log_text(kernel)
    assert 'This is a usage statement.' in text

    kernel.do_execute('?%', None)
    text = get_log_text(kernel)
    assert 'This is a usage statement.' in text

    kernel.do_execute('?%whatwhat', None)
    text = get_log_text(kernel)
    assert "No such line magic 'whatwhat'" in text

    clear_log_text(kernel)

    kernel.do_execute('%%help %magic', None)
    text = get_log_text(kernel)
    assert 'MagicMagic' in text

    kernel.do_execute('%%help\n%python', None)
    text = get_log_text(kernel)
    assert 'PythonMagic' in text
开发者ID:Calysto,项目名称:metakernel,代码行数:31,代码来源:test_help_magic.py

示例4: test_cd_magic

def test_cd_magic():
    kernel = get_kernel()
    kernel.do_execute("%cd ~")
    assert os.getcwd() == os.path.expanduser('~'), os.getcwd()
    clear_log_text(kernel)
    kernel.do_execute('%cd')
    assert os.getcwd() in get_log_text(kernel)
开发者ID:Calysto,项目名称:metakernel,代码行数:7,代码来源:test_cd_magic.py

示例5: test_reload_magics_magic

def test_reload_magics_magic():
    kernel = get_kernel()
    kernel.do_execute("%reload_magics")
    text = get_log_text(kernel)

    for item in "%cd %connect_info %download %edit %help %html %install_magic %javascript %kernel %kx %latex %load %lsmagic %magic %parallel %plot %pmap %px %python %reload_magics %restart %run %shell %spell %%debug %%file %%help %%html %%javascript %%kx %%latex %%processing %%px %%python %%shell %%show %%spell %%time".split():
        assert item in text, ("load_magic didn't list '%s'" % item)
开发者ID:a-rodin,项目名称:metakernel,代码行数:7,代码来源:test_reload_magics_magic.py

示例6: test_inline_plots

def test_inline_plots():
    kernel = get_kernel(GnuplotKernel)
    kernel.call_magic('%gnuplot inline')

    # inline plot creates data
    code = """
    plot sin(x)
    """
    kernel.do_execute(code)
    text = get_log_text(kernel)
    assert_true('Display Data' in text)
    clear_log_text(kernel)

    # multiple plot statements data
    code = """
    plot sin(x)
    plot cos(x)
    """
    kernel.do_execute(code)
    text = get_log_text(kernel)
    assert_true(text.count('Display Data') == 2)
    clear_log_text(kernel)

    # svg
    kernel.call_magic('%gnuplot inline svg')
    code = """
    plot tan(x)
    """
    kernel.do_execute(code)
    text = get_log_text(kernel)
    assert_true('Display Data' in text)
    clear_log_text(kernel)
开发者ID:Naereen,项目名称:gnuplot_kernel,代码行数:32,代码来源:test_kernel.py

示例7: test_misc

def test_misc():
    class TestKernel(MetaKernel):
        def do_execute_file(self, filename):
            self.Print("This language does not support running files")

        def do_function_direct(self, f, arg):
            self.Print("%s(%s)" % (f, self.repr(arg)))

        def repr(self, arg):
            return "XXX"

    kernel = get_kernel(TestKernel)
    assert kernel.do_execute_direct('garbage') is None
    kernel.do_execute_file('hello.txt')
    assert "This language does not support" in get_log_text(kernel)

    clear_log_text(kernel)

    kernel.do_function_direct('hello', 'world')
    text = get_log_text(kernel)
    assert "hello(XXX)" in text, text
    kernel.restart_kernel()

    ret = kernel.do_is_complete('hello\n')
    assert ret == {'status': 'complete'}

    assert kernel.do_inspect('hello', 10) is None
开发者ID:dsblank,项目名称:metakernel,代码行数:27,代码来源:test_metakernel.py

示例8: test_edit_magic

def test_edit_magic():
    kernel = get_kernel(EvalKernel)

    results = kernel.do_execute("%%edit %s" % __file__)
    text = results["payload"][0]["text"]
    assert text.startswith('%%file')
    assert 'def test_edit_magic' in text
开发者ID:Calysto,项目名称:metakernel,代码行数:7,代码来源:test_edit_magic.py

示例9: test_history

def test_history():
    kernel = get_kernel()
    kernel.do_execute('!ls', False)
    kernel.do_execute('%cd ~', False)
    kernel.do_shutdown(False)

    with open(kernel.hist_file, 'rb') as fid:
        text = fid.read().decode('utf-8', 'replace')

    assert '!ls' in text
    assert '%cd' in text

    kernel = get_kernel()
    kernel.do_history(None, None, None)
    assert '!ls' in ''.join(kernel.hist_cache)
    assert '%cd ~'
开发者ID:evhub,项目名称:metakernel,代码行数:16,代码来源:test_metakernel.py

示例10: test_cell_magic

def test_cell_magic():
    # To simulate '%load_ext gnuplot_kernel';
    # create a main kernel, a gnuplot kernel and
    # a gnuplot magic that uses the gnuplot kernel.
    # Then manually register the gnuplot magic into
    # the main kernel.
    kernel = get_kernel()
    gkernel = GnuplotKernel()
    gmagic = GnuplotMagic(gkernel)
    gkernel.makeSubkernelTo(kernel, kernel.Display)
    kernel.line_magics['gnuplot'] = gmagic
    kernel.cell_magics['gnuplot'] = gmagic

    # inline output
    code = """%%gnuplot
    plot cos(x)
    """
    kernel.do_execute(code)
    assert_true('Display Data' in get_log_text(kernel))
    clear_log_text(kernel)

    # file output
    kernel.call_magic('%gnuplot pngcairo size 560,420')
    code = """%%gnuplot
    set output 'cosine.png'
    plot cos(x)
    """
    kernel.do_execute(code)
    assert_true(os.path.exists('cosine.png'))
    clear_log_text(kernel)
开发者ID:Naereen,项目名称:gnuplot_kernel,代码行数:30,代码来源:test_kernel.py

示例11: test_inspect

def test_inspect():
    kernel = get_kernel()
    kernel.do_inspect('%lsmagic', len('%lsmagic'))
    log_text = get_log_text(kernel)
    assert "list the current line and cell magics" in log_text

    kernel.do_inspect('%lsmagic ', len('%lsmagic') + 1)
开发者ID:evhub,项目名称:metakernel,代码行数:7,代码来源:test_metakernel.py

示例12: test_plot_magic_all

def test_plot_magic_all():
    kernel = get_kernel()
    kernel.do_execute('%plot -b qt5 -f svg -s 400,200')
    assert kernel.plot_settings['width'] == 400
    assert kernel.plot_settings['height'] == 200
    assert kernel.plot_settings['format'] == 'svg', kernel.plot_settings
    assert kernel.plot_settings['backend'] == 'qt5', kernel.plot_settings
开发者ID:Calysto,项目名称:metakernel,代码行数:7,代码来源:test_plot_magic.py

示例13: test_option

def test_option():
    kernel = get_kernel()
    d = Dummy(kernel)
    assert 'Options:' in d.line_dummy.__doc__
    assert '--size' in d.line_dummy.__doc__

    ret = d.call_magic('line', 'dummy', '', 'hey -s400,200')
    assert ret == d
    assert d.foo == 'hey', d.foo
    assert d.size == (400, 200)

    ret = d.call_magic('line', 'dummy', '', 'hey there')
    assert d.foo == 'hey there'

    ret = d.call_magic('line', 'dummy', '', 'range(1, 10)')
    # arg eval no longer evals Python raw code:
    assert d.foo == "range(1, 10)"

    ret = d.call_magic('line', 'dummy', '', '[1, 2, 3]')
    # arg eval does eval Python data structures:
    assert d.foo == [1, 2, 3]

    ret = d.call_magic('line', 'dummy', '', 'hey -l -s400,200')
    assert d.size == (400, 200)
    assert d.foo == "hey -l"

    ret = d.call_magic('line', 'dummy', '', 'hey -s -- -s400,200')
    assert d.size == (400, 200)
    assert d.foo == "hey -s"
开发者ID:Calysto,项目名称:metakernel,代码行数:29,代码来源:test_magic.py

示例14: test_plot_magic_backend

def test_plot_magic_backend():
    kernel = get_kernel()
    kernel.do_execute('%plot qt -f svg -s400,200', None)
    assert kernel.plot_settings['width'] == 400
    assert kernel.plot_settings['height'] == 200
    assert kernel.plot_settings['format'] == 'svg'
    assert kernel.plot_settings['backend'] == 'qt'
开发者ID:Calysto,项目名称:metakernel,代码行数:7,代码来源:test_plot_magic.py

示例15: test_parallel_magic

def test_parallel_magic():
    kernel = get_kernel(EvalKernel)
    # start up an EvalKernel on each node:
    kernel.do_execute("%parallel metakernel_python MetaKernelPython", False)
    # Now, execute something on each one:
    kernel.do_execute("%px cluster_rank", False)
    results = get_log_text(kernel)
    assert "[0, 1, 2]" in results, results
开发者ID:Foucl,项目名称:metakernel,代码行数:8,代码来源:test_parallel_magic.py


注:本文中的metakernel.tests.utils.get_kernel函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。