test_specification.py 文件源码

python
阅读 22 收藏 0 点赞 0 评论 0

项目:json-e 作者: taskcluster 项目源码 文件源码
def test():
    def spec_test(name, spec):
        "Make a test function for a case from specification.yml"
        def test(*args):
            exc, res = None, None
            try:
                res = jsone.render(spec['template'], spec['context'])
            except jsone.JSONTemplateError as e:
                if 'error' not in spec:
                    raise
                exc = e
            if 'error' in spec:
                assert exc, "expected exception"
                expected = spec['error']
                if expected is True:  # no specific expectation
                    return
                eq_(str(exc), expected)
            else:
                assert not exc
                assert res == spec['result'], \
                    '{!r} != {!r}'.format(res, spec['result'])
        return test

    with open(os.path.join(os.path.dirname(__file__), '../specification.yml')) as f:
        with freeze_time('2017-01-19T16:27:20.974Z'):
            for spec in yaml.load_all(f):
                if 'section' in spec:
                    section = spec['section']
                    continue

                name = '{}: {}'.format(section, spec['title'])
                t = spec_test(name, spec)
                yield (t, name)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号