通过消息传递协议测试jupyter内核的机器。
jupyter_kernel_test的Python项目详细描述
jupyter_kernel_test是测试Jupyter内核的工具。它测试内核是否成功执行代码,以及是否符合Jupyter Messaging Protocol(当前为5.0)。
安装
用pip安装(需要python3.4或更高版本):
pip3 install jupyter_kernel_test
用法
要使用它,您需要用相关语言编写一个(python)unittest文件,其中包含测试消息传递协议各个部分的代码示例。下面给出了一个简短的示例,否则您可以查阅test_ipykernel.py和test_irkernel.py文件以获得完整的示例。
消息传递协议的某些部分仅与基于浏览器的笔记本(富显示)或控制台界面(代码完整性、历史搜索)相关。只测试规范中提供代码示例的部分。
直接使用python运行这个文件,或者使用nosetests或py.test查找并运行它。
示例
importunittestimportjupyter_kernel_testclassMyKernelTests(jupyter_kernel_test.KernelTests):# Required --------------------------------------# The name identifying an installed kernel to run the tests againstkernel_name="mykernel"# language_info.name in a kernel_info_reply should match thislanguage_name="mylanguage"# Optional --------------------------------------# Code in the kernel's language to write "hello, world" to stdoutcode_hello_world="print 'hello, world'"# Pager: code that should display something (anything) in the pagercode_page_something="help(something)"# Samples of code which generate a result value (ie, some text# displayed as Out[n])code_execute_result=[{'code':'6*7','result':'42'}]# Samples of code which should generate a rich display output, and# the expected MIME typecode_display_data=[{'code':'show_image()','mime':'image/png'}]# You can also write extra tests. We recommend putting your kernel name# in the method name, to avoid clashing with any tests that# jupyter_kernel_test adds in the future.deftest_mykernel_stderr(self):reply,output_msgs=self.execute_helper(code='print_err "oops"')self.assertEqual(output_msgs[0]['msg_type'],'stream')self.assertEqual(output_msgs[0]['content']['name'],'stderr')self.assertEqual(output_msgs[0]['content']['text'],'oops\n')if__name__=='__main__':unittest.main()
覆盖范围
消息传递协议的以下方面未经明确测试:
- 小部件通信:comm_open,comm_msg,comm_close
- 标准输入:^{TT10}$,^{TT11}$
- 显示数据元数据
- 关机/重启:shutdown_request,shutdown_reply
- 历史:并非涵盖所有选项组合
- 检查:多级
- 执行有效载荷(已弃用但仍在使用):有效载荷load,edit,ask_exit
- 用户表达式
- 执行:组合silent、store_history和stop_on_error