forked from hacs/integration
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_fs_util.py
67 lines (50 loc) · 2.38 KB
/
test_fs_util.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
"""Test fs_util."""
import pytest
from custom_components.hacs.utils.file_system import (
async_exists,
async_remove,
async_remove_directory,
)
async def test_async_exists(hass, tmpdir):
"""Test async_exists."""
assert not await async_exists(hass, tmpdir / "tmptmp")
open(tmpdir / "tmptmp", "w").close()
assert await async_exists(hass, tmpdir / "tmptmp")
async def test_async_remove(hass, tmpdir):
"""Test async_remove."""
assert not await async_exists(hass, tmpdir / "tmptmp")
with pytest.raises(FileNotFoundError):
await async_remove(hass, tmpdir / "tmptmp")
with pytest.raises(FileNotFoundError):
await async_remove(hass, tmpdir / "tmptmp", missing_ok=False)
await async_remove(hass, tmpdir / "tmptmp", missing_ok=True)
open(tmpdir / "tmptmp", "w").close()
await async_remove(hass, tmpdir / "tmptmp")
assert not await async_exists(hass, tmpdir / "tmptmp")
open(tmpdir / "tmptmp", "w").close()
await async_remove(hass, tmpdir / "tmptmp", missing_ok=False)
assert not await async_exists(hass, tmpdir / "tmptmp")
open(tmpdir / "tmptmp", "w").close()
await async_remove(hass, tmpdir / "tmptmp", missing_ok=True)
assert not await async_exists(hass, tmpdir / "tmptmp")
async def test_async_remove_directory(hass, tmpdir):
"""Test async_remove_directory."""
assert not await async_exists(hass, tmpdir / "tmptmp")
with pytest.raises(FileNotFoundError):
await async_remove_directory(hass, tmpdir / "tmptmp")
with pytest.raises(FileNotFoundError):
await async_remove_directory(hass, tmpdir / "tmptmp", missing_ok=False)
assert not await async_exists(hass, tmpdir / "tmptmp")
await async_remove_directory(hass, tmpdir / "tmptmp", missing_ok=True)
(tmpdir / "tmptmp").mkdir()
assert await async_exists(hass, tmpdir / "tmptmp")
await async_remove_directory(hass, tmpdir / "tmptmp")
assert not await async_exists(hass, tmpdir / "tmptmp")
(tmpdir / "tmptmp").mkdir()
assert await async_exists(hass, tmpdir / "tmptmp")
await async_remove_directory(hass, tmpdir / "tmptmp", missing_ok=False)
assert not await async_exists(hass, tmpdir / "tmptmp")
(tmpdir / "tmptmp").mkdir()
assert await async_exists(hass, tmpdir / "tmptmp")
await async_remove_directory(hass, tmpdir / "tmptmp", missing_ok=True)
assert not await async_exists(hass, tmpdir / "tmptmp")