儿童测试库。
kids.test的Python项目详细描述
kids.test是一个python库,在编写测试时提供帮助程序 在Python中。这是“孩子”图书馆的一部分。
成熟度
这是阿尔法释放。它只是一个有一些食谱的仓库 兴趣很少。将来可能会更加一致。
它缺乏任何合理的文档,其核心没有任何突破性进展。
功能
使用kids.test:
- 可以使用替换的unittest类来确保 python3添加项,如assertContains或assertRegex。
- 您可以使用BaseTmpDirTest在 执行测试,并在最后将其删除。
安装
您不需要下载git版本的代码,因为kids.testis PYPI上有。所以您应该能够运行:
pip install kids.test
如果您下载了git源代码,那么可以添加install 当前版本通过传统:
python setup.py install
如果你没有git的来源但是想得到最新的 github的master或branch,您也可以:
pip install git+https://github.com/0k/kids.test
或者甚至选择特定的修订(分支/标记/提交):
pip install git+https://github.com/0k/kids.test@master
用法
测试
Test是kids.*框架中所有unittest的基类。它提供了 python 2缺少.assert*()方法:
>>> from kids.test import Test, run >>> class MyTest(Test): ... def test_foo(self): ... self.assertRegex('foo', 'fo+') ... self.assertContains('bar foo hop', 'foo') ... self.assertNotContains('bar fou hop', 'foo') ... def test_failing_regex(self): ... self.assertRegex('foo', 'xfo+') ... def test_failing_contains(self): ... self.assertContains('bar fou hop', 'foo') ... def test_failing_not_contains(self): ... self.assertNotContains('bar foo hop', 'foo') >>> run(MyTest) FFF. ... AssertionError: ...'bar fou hop' should contain 'foo'. ... AssertionError: ...'bar foo hop' should not contain 'foo'. ... AssertionError: ...'foo' should match regex 'xfo+'. ... Ran 4 tests in ...s <BLANKLINE> FAILED (failures=3) <BLANKLINE>
基特莫迪斯特
这个unittest类将确保 正在执行测试,是一个空的临时目录。它将确保这个目录 将在结尾处删除:
>>> from kids.test import BaseTmpDirTest, run >>> class MyTest(BaseTmpDirTest): ... def test_foo(self): ... import glob ... self.assertEqual(len(glob.glob('*')), 0) >>> run(MyTest) . ---------------------------------------------------------------------- Ran 1 test in ...s <BLANKLINE> OK <BLANKLINE>
下面是在现场发生的事情,让我们使用minimock来显示 创建和删除目录:
>>> import minimock >>> import tempfile, shutil, os >>> minimock.mock('tempfile.mkdtemp', returns='/tmp/tempdir') >>> minimock.mock('os.chdir', returns='/tmp/tempdir') >>> minimock.mock('shutil.rmtree') >>> class MyTest(BaseTmpDirTest): ... def test_foo(self): ... print("running test") ... self.assertTrue(True) >>> run(MyTest) Called tempfile.mkdtemp() Called os.chdir('/tmp/tempdir') running test Called os.chdir('...') Called shutil.rmtree('/tmp/tempdir') . ---------------------------------------------------------------------- Ran 1 test in ...s <BLANKLINE> OK <BLANKLINE> >>> minimock.restore()
贡献
欢迎提出任何建议或问题。非常欢迎推送请求, 请查看指南。
推送请求指南
你可以发送任何代码。我会自己研究并整合它 代码库,留下你作为作者。这个过程可能需要时间和 如果遵循以下指导原则,所需时间将更少:
- 用pep8或pylint检查代码。尽量坚持80列宽。
- 把你的承诺分开。
- 每次提交都应通过测试(以方便平分)
- 每个功能/错误修复提交都应该包含代码、测试, 还有医生。
- 先前的次要提交与排版或代码外观更改是 非常欢迎。它们应该在提交摘要中标记为 !minor。
- 提交消息应该遵循gitchangelog规则(检查git 登录以获取示例)
- 如果提交修复了问题或完成了 功能,请在摘要中提及。
如果你对指导方针有一些问题,这里没有回答, 请检查当前的git log,您可能会发现以前的提交 会告诉你如何处理你的问题。
更改日志
0.0.1(2015-02-04)
- 第一次进口。[瓦伦丁实验室]