针对崇高文本的测试和断言框架的基本层
sublime_plugin_tests_base的Python项目详细描述
Sublime插件测试库
针对Sublime Text测试和断言框架的基本层
这是sublime-plugin-tests项目的一部分,是Sublime Text的完整测试框架
有关支持的版本和常见问题解答,请参阅sublime-plugin-tests。
折旧通知
我们决定不赞成sublime-plugin-tests-base,而赞成randy3k/UnitTesting。
它有更大的平台支持,并且为本地开发设计的脆弱性更小。
https://github.com/randy3k/UnitTesting
开始
使用pip install sublime_plugin_tests_base
安装模块然后,编写测试:
# Load in unittest and test basefromunittestimportTestCasefromsublime_plugin_tests_baseimportBase# Define a TestCaseclassTestLeftDelete(TestCase):deftest_left_delete_single(self):# Each test function *must* return Python with a `run` function# `run` will be run inside Sublime Text. Perform your assertions etc there.# Run a testbase=Base()result=base.run_test(""" # Use ScratchView utility provided by `sublime_plugin_tests` from utils.scratch_view import ScratchView def run(): # Generate new scratch file scratch_view = ScratchView() try: # Update the content and selection `ab|c` scratch_view.set_content('abc') scratch_view.set_sel([(2, 2)]) # Delete one character to the left `a|c scratch_view.run_command('left_delete') # Assert the current content assert scratch_view.get_content() == 'ac' finally: # No matter what happens, close the view scratch_view.destroy() """)# Assert the test passed as expectedself.assertEqual(result['success'],True)
$ # Run tests via nosetests $ nosetests . ---------------------------------------------------------------------- Ran 1test in 0.076s OK
我们通过travis ci支持崇高文本2和3。
文件
sublime-plugin-tests-base由两部分组成:测试框架代码(升华文本外部)和测试帮助程序(升华文本内部)。
测试框架代码在正常的开发环境中运行(例如,nosetestslives所在的环境)。测试助手生活在崇高的文本,使您的测试生活更容易。
测试框架
基地(自动杀戮=假)
在Sublime中运行封闭测试的类。它处理捕获和返回错误。
- 自动终止升华Boolean-如果为真,测试完成时将自动关闭升华文本。
- 这对于使用同步升华文本(如升华文本2)的无头环境非常有用。
基本目录
运行测试的文件夹。这可用于写入相对导入的文件。
运行测试(action str)
在升华文本的上下文中运行代码。这将捕获发生的任何synchronous错误。为了澄清,如果使用sublime.set_timeout,则无法报告错误。
- 动作str String-在升华文本上下文中运行的代码。这应该是对视图进行断言,因为数据在result中不可用。
返回:
- 结果Dictionary-结果容器
- 成功Boolean-如果没有错误,True。否则,False。
- 发生的错误的元信息String格式的回溯。
基地(自动杀戮=假)
在Sublime中运行封闭测试的类。它处理捕获和返回错误。
- 自动终止升华Boolean-如果为真,测试完成时将自动关闭升华文本。
- 这对于使用同步升华文本(如升华文本2)的无头环境非常有用。
基本目录
运行测试的文件夹。这可用于写入相对导入的文件。
运行测试(action str)
在升华文本的上下文中运行代码。这将捕获发生的任何synchronous错误。为了澄清,如果使用sublime.set_timeout,则无法报告错误。
- 动作str String-在升华文本上下文中运行的代码。这应该是对视图进行断言,因为数据在result中不可用。
返回:
- 结果Dictionary-结果容器
- 成功Boolean-如果没有错误,True。否则,False。
- 发生的错误的元信息String格式的回溯。
测试助手
utils.scratch视图.scratch view
这有助于创建/分解/操作视图。
有关最新信息,请咨询sublime-plugin-tests#utilsscratch_viewscratchview。
架构
请查阅sublime-plugin-tests#architecture以获取最新信息。
贡献
代替正式的形式指南,注意保持现有的编码风格。为任何新的或更改的功能添加单元测试。通过./test.sh进行测试。
如果您希望无头运行测试,则此存储库可以与Vagrant一起使用。
Currently, it is only configured for Sublime Text 3.
$ vagrant up [default] Importing base box 'precise64'... ... $ vagrant ssh st2 # Sublime Text 3 $ # Use `st3` for Sublime Text 2 vagrant@precise64:~$ cd /vagrant vagrant@precise64:/vagrant$ ./test.sh .. ---------------------------------------------------------------------- Ran 2 tests in 2.957s OK