Mercurial > code > home > repos > rdfdb
view rdfdb/watched_graphs_test.py @ 121:8a0559bcbe7e
shorthand import
author | drewp@bigasterisk.com |
---|---|
date | Wed, 24 May 2023 12:49:01 -0700 |
parents | 418050704a42 |
children |
line wrap: on
line source
import asyncio import logging from pathlib import Path import pytest from rdflib import Namespace from .watched_graphs import WatchedGraphs log = logging.getLogger() EX = Namespace('http://example.com/') NON_EMPTY_N3_CONTENT = """ @prefix : <http://example.com/> . :a :b :c . """ async def assert_no_events_coming(q: asyncio.Queue): """ see if inotify makes an event or stays quiet """ inotify_max_wait_secs = 0.1 with pytest.raises(asyncio.TimeoutError): # no events from the empty dir ev = await asyncio.wait_for(q.get(), timeout=inotify_max_wait_secs) log.error(f'expected no events; got {ev}', stacklevel=2) @pytest.mark.asyncio async def test_make_graph_from_file(tmpdir): root = Path(tmpdir.mkdir("root")) someFile = root / 'hello.n3' someFile.write_text(NON_EMPTY_N3_CONTENT) wg = WatchedGraphs({root: EX}, addlPrefixes={}) ev = await asyncio.wait_for(wg.graphEditEvents.get(), timeout=1.0) assert ev.uri == EX['hello'] assert list(ev.content) == [(EX.a, EX.b, EX.c)] await assert_no_events_coming(wg.graphEditEvents) # see https://stackoverflow.com/questions/40897428/please-explain-task-was-destroyed-but-it-is-pending-after-cancelling-tasks # for why this makes so much noise upon success.