Skip to content

Test appending to file #118

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions tests/test_watch.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import asyncio
import sys
import threading
from contextlib import contextmanager
Expand Down Expand Up @@ -115,3 +116,34 @@ async def test_awatch_no_yield(mock_rust_notify: 'MockRustType', caplog):
assert changes == {(Change.added, 'spam.py')}
assert mock.watch_count == 2
assert caplog.text == "watchfiles.main DEBUG: 1 change detected: {(<Change.added: 1>, 'spam.py')}\n"


async def test_watch_directory(tmp_path: Path):
stop_event = asyncio.Event()

async def stop_soon():
await asyncio.sleep(0.4)
stop_event.set()

async def change_dir():
await asyncio.sleep(0.1)
(tmp_path / 'file0').write_text('foo')
await asyncio.sleep(0.1)
with open(tmp_path / 'file0', 'a') as f:
f.write(' bar')
await asyncio.sleep(0.1)
(tmp_path / 'file0').unlink()

tasks = [asyncio.create_task(stop_soon()), asyncio.create_task(change_dir())]

changes = []
async for change in awatch(tmp_path, stop_event=stop_event, step=1):
changes.append(change)

assert changes == [
{(Change.added, str(tmp_path / 'file0'))},
{(Change.modified, str(tmp_path / 'file0'))},
{(Change.deleted, str(tmp_path / 'file0'))},
]

await asyncio.gather(*tasks)