简单的测试装置。
fix的Python项目详细描述
Author: | Zero Piraeus |
---|---|
Contact: | z@etiol.net |
fix是一个简单的库,可以帮助创建用于测试的fixture 函数、方法等。它提供一个修饰符with_fixture,该修饰符 允许您将setup()和teardown()函数附加到修饰的 可调用,并从测试中访问fixture中定义的信息 功能。
fix是为与nose一起使用而编写的,但并不依赖于它,而且还可能 证明对其他测试框架有用。
示例
下面是一个基本的安装示例,但没有拆卸:
from fix import with_fixture def setup_only(context): def setup(): """Add something to the context.""" assert context == {} context.squee = "kapow" return setup @with_fixture(setup_only) def case(context): assert context == {"squee": "kapow"}
…这里有一个更复杂的文件,它创建一些临时文件 使用,然后在拆卸过程中删除它们:
import os import shutil import tempfile from fix import with_fixture def external(context, files=3): def setup(): context.temp_dir = tempfile.mkdtemp() context.filenames = ["file_%03d" % i for i in range(files)] for filename in context.filenames: with open(os.path.join(context.temp_dir, filename), "w") as f: f.write("This is the file %r.\n" % filename) def teardown(): shutil.rmtree(context.temp_dir) return setup, teardown @with_fixture(external, files=5) def check_files(context): present = 0 absent = 0 for filename in context.filenames: if os.path.exists(os.path.join(context.temp_dir, filename)): present += 1 else: absent += 1 return context.temp_dir, present, absent temp_dir, present, absent = check_files() assert not os.path.exists(temp_dir) assert present == 5 assert absent == 0
安装
这应该可以做到:
pip install fix
许可证
fix在GNU通用公共许可证(版本3或更高版本)下发布, 此分发版包含在文件copying中的副本。