test_config_validation.py 文件源码

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

项目:homeassistant 作者: NAStools 项目源码 文件源码
def test_isfile():
    """Validate that the value is an existing file."""
    schema = vol.Schema(cv.isfile)

    fake_file = 'this-file-does-not.exist'
    assert not os.path.isfile(fake_file)

    for value in ('invalid', None, -1, 0, 80000, fake_file):
        with pytest.raises(vol.Invalid):
            schema(value)

    # patching methods that allow us to fake a file existing
    # with write access
    with patch('os.path.isfile', Mock(return_value=True)), \
            patch('os.access', Mock(return_value=True)):
        schema('test.txt')
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号