• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python utils.get_kernel函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: test_plot_magic_format

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


示例17: test_html_magic

def test_html_magic():
    kernel = get_kernel(EvalKernel)
    kernel.do_execute("""%%html

<b>bold</b>
""")
    text = get_log_text(kernel)
    assert "Display Data" in text, text
开发者ID:Calysto,项目名称:metakernel,代码行数:8,代码来源:test_html_magic.py


示例18: test_javascript_magic

def test_javascript_magic():
    kernel = get_kernel(EvalKernel)
    kernel.do_execute("""%%javascript

console.log("Hello from Javascript");
""")
    text = get_log_text(kernel)
    assert "Display Data" in text, text
开发者ID:Calysto,项目名称:metakernel,代码行数:8,代码来源:test_javascript_magic.py


示例19: test_bad_prompt

def test_bad_prompt():
    kernel = get_kernel(GnuplotKernel)
    # Anything other than 'gnuplot> '
    # is a bad prompt
    code = 'set multiplot'
    kernel.do_execute(code)
    text = get_log_text(kernel)
    assert_true('warning' in text.lower())
开发者ID:Naereen,项目名称:gnuplot_kernel,代码行数:8,代码来源:test_kernel.py


示例20: test_gnuplot_error_message

def test_gnuplot_error_message():
    kernel = get_kernel(GnuplotKernel)

    # The error messages gets to the kernel
    code = 'plot [1,2][] sin(x)'
    kernel.do_execute(code)
    text = get_log_text(kernel)
    assert_true(' ^' in text)
开发者ID:Naereen,项目名称:gnuplot_kernel,代码行数:8,代码来源:test_kernel.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python utils.get_log_text函数代码示例发布时间:2022-05-27
下一篇:
Python metainfo.info函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap