Kids测试库。
项目描述
kids.test 是一个Python库,提供在Python中编写测试时的一些辅助功能。它是“Kids”(用于保持简单)库的一部分。
成熟度
这是一个alpha版本。它只是一个包含少量菜谱的仓库,兴趣不大。它可能在未来更加一致。
它缺少任何合理的文档,其核心也没有任何突破性的内容。
功能
使用 kids.test
您可以使用一个替代的 unittest 类,该类确保您有一些python3的添加功能,如 assertContains 或 assertRegex。
您可以使用 BaseTmpDirTest,它在执行测试之前创建一个临时目录,并在结束时删除它。
安装
由于 kids.test 在PyPI上可用,因此您不需要下载代码的GIT版本。因此,您应该能够运行
pip install kids.test
如果您已经下载了GIT源代码,那么您也可以通过传统方式安装当前版本
python setup.py install
如果您没有GIT源代码,但想从github获取最新的master或分支,您也可以
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>
BaseTmpDirTest
此单元测试类将确保在执行测试之前,当前工作目录(CWD)是一个空的临时目录。并且将确保在结束时删除此目录。
>>> 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日志,您可能会找到以前的提交,这些提交会向您展示如何处理您的问题。
许可证
版权(c)2015 Valentin Lab。
在BSD许可下发布。
变更日志
0.0.1 (2015-02-04)
首次导入。[Valentin Lab]
项目详细信息
kids.test-0.0.1.tar.gz的散列
算法 | 散列摘要 | |
---|---|---|
SHA256 | a1237f537ee72a4354dca428ad92911d105d3f755a182bbda0b5969523ccf2bb |
|
MD5 | d4a8923d20824d17d67530ab5c98de4a |
|
BLAKE2b-256 | c96c8a20919e1fe11a9e502d9b764c150a8349daffbdd77db26da7e6481d3865 |