Skip to content

Commit 5097b65

Browse files
committed
Test appending to file
1 parent c35fa79 commit 5097b65

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

tests/test_watch.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import asyncio
12
import sys
23
import threading
34
from contextlib import contextmanager
@@ -115,3 +116,33 @@ async def test_awatch_no_yield(mock_rust_notify: 'MockRustType', caplog):
115116
assert changes == {(Change.added, 'spam.py')}
116117
assert mock.watch_count == 2
117118
assert caplog.text == "watchfiles.main DEBUG: 1 change detected: {(<Change.added: 1>, 'spam.py')}\n"
119+
120+
async def test_watch_directory(tmp_path: Path):
121+
stop_event = asyncio.Event()
122+
123+
async def stop_soon():
124+
await asyncio.sleep(0.4)
125+
stop_event.set()
126+
127+
async def change_dir():
128+
await asyncio.sleep(0.1)
129+
(tmp_path / "file0").write_text("foo")
130+
await asyncio.sleep(0.1)
131+
with open(tmp_path / "file0", "a") as f:
132+
f.write(" bar")
133+
await asyncio.sleep(0.1)
134+
(tmp_path / "file0").unlink()
135+
136+
tasks = [asyncio.create_task(stop_soon()), asyncio.create_task(change_dir())]
137+
138+
changes = []
139+
async for change in awatch(tmp_path, stop_event=stop_event, step=1):
140+
changes.append(change)
141+
142+
assert changes == [
143+
{(Change.added, str(tmp_path / "file0"))},
144+
{(Change.modified, str(tmp_path / "file0"))},
145+
{(Change.deleted, str(tmp_path / "file0"))},
146+
]
147+
148+
await asyncio.gather(*tasks)

0 commit comments

Comments
 (0)