未提供项目描述
项目描述
安装
使用pip安装(需要python3.4或更高版本)
pip3 install jupyter_kernel_test
使用方法
要使用它,您需要编写一个包含相关语言代码样本的(python)unittest文件,以测试消息协议的各个部分。下面提供了一个简短的示例,您还可以参考test_ipykernel.py和test_irkernel.py文件以获取完整的示例。
消息协议的一些部分仅与基于浏览器的笔记本(富显示)或控制台界面(代码完整性、历史搜索)相关。仅测试您提供的代码样本的部分规范。
直接使用Python运行此文件,或使用nosetests或py.test来查找和运行它。
示例
import unittest
import jupyter_kernel_test
class MyKernelTests(jupyter_kernel_test.KernelTests):
# Required --------------------------------------
# The name identifying an installed kernel to run the tests against
kernel_name = "mykernel"
# language_info.name in a kernel_info_reply should match this
language_name = "mylanguage"
# Optional --------------------------------------
# Code in the kernel's language to write "hello, world" to stdout
code_hello_world = "print 'hello, world'"
# Pager: code that should display something (anything) in the pager
code_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 type
code_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.
def test_mykernel_stderr(self):
self.flush_channels()
reply, output_msgs = self.execute_helper(code='print_err "oops"')
self.assertEqual(output_msgs[0]["header"]["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
stdin:input_request,input_reply
display_data元数据
关闭/重启:shutdown_request,shutdown_reply
历史:并非所有选项组合都得到覆盖
检查:多个级别
执行有效载荷(已弃用但仍在使用):有效载荷load,edit,ask_exit
用户表达式
执行:silent,store_history和stop_on_error的组合