From b90053b0471de06bf58a5b35a0e5c27eb1ec49e6 Mon Sep 17 00:00:00 2001 From: David Brochart Date: Fri, 8 Apr 2022 12:10:51 +0200 Subject: [PATCH] Symplify test --- tests/services/contents/test_fileio.py | 25 ++++++------------------- 1 file changed, 6 insertions(+), 19 deletions(-) diff --git a/tests/services/contents/test_fileio.py b/tests/services/contents/test_fileio.py index 1f519968fd..758568ee61 100644 --- a/tests/services/contents/test_fileio.py +++ b/tests/services/contents/test_fileio.py @@ -127,29 +127,16 @@ def test_atomic_writing_newlines(tmp_path): async def test_watch_directory(tmp_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") + (tmp_path / "file.txt").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() + stop_event.set() - tasks = [asyncio.create_task(stop_soon()), asyncio.create_task(change_dir())] + task = asyncio.create_task(change_dir()) - changes = [] - async for change in awatch(tmp_path, stop_event=stop_event, step=1): - changes.append(change) + changes = [change async for change in awatch(tmp_path, stop_event=stop_event, step=1)] - assert changes == [ - {(Change.added, str(tmp_path / "file0"))}, - {(Change.modified, str(tmp_path / "file0"))}, - {(Change.deleted, str(tmp_path / "file0"))}, - ] + assert changes == [{(Change.added, str(tmp_path / "file.txt"))}] - await asyncio.gather(*tasks) + await task