mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 12:59:34 +00:00
improve isfile validation check (#3101)
This commit is contained in:
committed by
Paulus Schoutsen
parent
87e332c777
commit
5036bb0bc6
@@ -1,4 +1,6 @@
|
||||
from datetime import timedelta
|
||||
import os
|
||||
import tempfile
|
||||
|
||||
import pytest
|
||||
import voluptuous as vol
|
||||
@@ -59,6 +61,24 @@ def test_port():
|
||||
schema(value)
|
||||
|
||||
|
||||
def test_isfile():
|
||||
"""Validate that the value is an existing file."""
|
||||
schema = vol.Schema(cv.isfile)
|
||||
|
||||
with tempfile.NamedTemporaryFile() as fp:
|
||||
pass
|
||||
|
||||
for value in ('invalid', None, -1, 0, 80000, fp.name):
|
||||
with pytest.raises(vol.Invalid):
|
||||
schema(value)
|
||||
|
||||
with tempfile.TemporaryDirectory() as tmp_path:
|
||||
tmp_file = os.path.join(tmp_path, "test.txt")
|
||||
with open(tmp_file, "w") as tmp_handl:
|
||||
tmp_handl.write("test file")
|
||||
schema(tmp_file)
|
||||
|
||||
|
||||
def test_url():
|
||||
"""Test URL."""
|
||||
schema = vol.Schema(cv.url)
|
||||
|
||||
Reference in New Issue
Block a user