简单的测试装置。

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中的副本。

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
AmazonS3查找从S3forJava下载的压缩文件的MIME类型   java如何使用Selenium在<span>中查找具有特定文本的元素   python如何使用OpenIEDemo生成自定义三元组。由stanfordnlp提供的java   java遇到“方法不适用”编译错误   java如何使用Mockito在Looper中运行的验证代码。getMainLooper?   类Java目录错误   java在已知其他泛型信息时使用原始类型   java connect()和disconnect()在哪里实现?   java使用PDF Box库拆分PDF,生成的PDF几乎与源PDF文件大小相同   java PowerMockito返回错误的对象   java如何找到TIBCO集合消息的字节编码?   java Basic音乐播放器下一步和上一步按钮   添加模块描述符时,java没有名为“entityManagerFactory”的bean可用   java为什么我的代码不是线程安全的?   eclipse java。引用项目中的类的lang.NoClassDefFoundError