Skip to content

Commit a087347

Browse files
committed
Test appending to file
1 parent c35fa79 commit a087347

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

tests/test_watch.py

Lines changed: 32 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,34 @@ 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+
121+
async def test_watch_directory(tmp_path: Path):
122+
stop_event = asyncio.Event()
123+
124+
async def stop_soon():
125+
await asyncio.sleep(0.4)
126+
stop_event.set()
127+
128+
async def change_dir():
129+
await asyncio.sleep(0.1)
130+
(tmp_path / 'file0').write_text('foo')
131+
await asyncio.sleep(0.1)
132+
with open(tmp_path / 'file0', 'a') as f:
133+
f.write(' bar')
134+
await asyncio.sleep(0.1)
135+
(tmp_path / 'file0').unlink()
136+
137+
tasks = [asyncio.create_task(stop_soon()), asyncio.create_task(change_dir())]
138+
139+
changes = []
140+
async for change in awatch(tmp_path, stop_event=stop_event, step=1):
141+
changes.append(change)
142+
143+
assert changes == [
144+
{(Change.added, str(tmp_path / 'file0'))},
145+
{(Change.modified, str(tmp_path / 'file0'))},
146+
{(Change.deleted, str(tmp_path / 'file0'))},
147+
]
148+
149+
await asyncio.gather(*tasks)

0 commit comments

Comments
 (0)