changeset 118:418050704a42

fix tests
author drewp@bigasterisk.com
date Tue, 23 May 2023 19:43:57 -0700
parents e5195c05fe5a
children 6443cb265a2f
files pdm.lock pyproject.toml pytest.ini rdfdb/syncedgraph/autodepgraphapi.py rdfdb/syncedgraph/currentstategraphapi_test.py rdfdb/watched_files.py rdfdb/watched_graphs_test.py
diffstat 7 files changed, 30 insertions(+), 27 deletions(-) [+]
line wrap: on
line diff
--- a/pdm.lock	Tue May 23 16:49:41 2023 -0700
+++ b/pdm.lock	Tue May 23 19:43:57 2023 -0700
@@ -281,7 +281,6 @@
 summary = "The little ASGI library that shines."
 dependencies = [
     "anyio<5,>=3.4.0",
-    "typing-extensions>=3.10.0; python_version < \"3.10\"",
 ]
 
 [[package]]
@@ -311,12 +310,6 @@
 summary = "Compatibility API between asyncio/Twisted/Trollius"
 
 [[package]]
-name = "typing-extensions"
-version = "4.6.0"
-requires_python = ">=3.7"
-summary = "Backported and Experimental Type Hints for Python 3.7+"
-
-[[package]]
 name = "watchdog"
 version = "3.0.0"
 requires_python = ">=3.7"
@@ -342,7 +335,7 @@
 
 [metadata]
 lock_version = "4.1"
-content_hash = "sha256:b3bc2e6406e415151d6e765f6bb07d29ec3b7ecb89b957d308a79569ae383f45"
+content_hash = "sha256:991124f9c237628c3968de5991f054f986c3c7a6e3ea8d165812ddb3fd39f682"
 
 [metadata.files]
 "aiohttp 3.8.4" = [
@@ -889,10 +882,6 @@
     {url = "https://files.pythonhosted.org/packages/51/91/bc9fd5aa84703f874dea27313b11fde505d343f3ef3ad702bddbe20bfd6e/txaio-23.1.1.tar.gz", hash = "sha256:f9a9216e976e5e3246dfd112ad7ad55ca915606b60b84a757ac769bd404ff704"},
     {url = "https://files.pythonhosted.org/packages/7d/6c/a53cc9a97c2da76d9cd83c03f377468599a28f2d4ad9fc71c3b99640e71e/txaio-23.1.1-py2.py3-none-any.whl", hash = "sha256:aaea42f8aad50e0ecfb976130ada140797e9dcb85fad2cf72b0f37f8cefcb490"},
 ]
-"typing-extensions 4.6.0" = [
-    {url = "https://files.pythonhosted.org/packages/85/d2/949d324c348014f0fd2e8e6d8efd3c0adefdcecd28990d4144f2cfc8105e/typing_extensions-4.6.0-py3-none-any.whl", hash = "sha256:6ad00b63f849b7dcc313b70b6b304ed67b2b2963b3098a33efe18056b1a9a223"},
-    {url = "https://files.pythonhosted.org/packages/e4/03/4670b4c206e1dc869f2f0120c3d0a2b17d42526ab2b5a8f66d4cd8642ef3/typing_extensions-4.6.0.tar.gz", hash = "sha256:ff6b238610c747e44c268aa4bb23c8c735d665a63726df3f9431ce707f2aa768"},
-]
 "watchdog 3.0.0" = [
     {url = "https://files.pythonhosted.org/packages/00/9e/a9711f35f1ad6571e92dc2e955e7de9dfac21a1b33e9cd212f066a60a387/watchdog-3.0.0-cp311-cp311-macosx_10_9_universal2.whl", hash = "sha256:2b57a1e730af3156d13b7fdddfc23dea6487fceca29fc75c5a868beed29177ae"},
     {url = "https://files.pythonhosted.org/packages/06/fd/58b82550ebe4883bb2a5e1b6c14d8702b5ce0f36c58470bba51dc777df46/watchdog-3.0.0-cp310-cp310-macosx_10_9_universal2.whl", hash = "sha256:336adfc6f5cc4e037d52db31194f7581ff744b67382eb6021c868322e32eef41"},
--- a/pyproject.toml	Tue May 23 16:49:41 2023 -0700
+++ b/pyproject.toml	Tue May 23 19:43:57 2023 -0700
@@ -6,13 +6,13 @@
 license = "MIT"
 dependencies = [
     'rdflib',
-    'autobahn',
+    'autobahn>=23.1.2',
     "prometheus-client>=0.13.1",
     "starlette-exporter>=0.12.0",
-    "asyncinotify>=2.0.2",
+    "asyncinotify>=4.0.2",
     "aiohttp>=3.8.1",
 ]
-requires-python = ">=3.9"
+requires-python = ">=3.10"
 
 [project.urls]
 Homepage = ""
@@ -29,7 +29,7 @@
     "pytest>=7.1.1",
     "pytest-watcher>=0.2.3",
     "mock",
-    "pytest-asyncio>=0.18.3",
+    "pytest-asyncio>=0.21.0",
     "pydeps>=1.10.18",
 ]
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/pytest.ini	Tue May 23 19:43:57 2023 -0700
@@ -0,0 +1,3 @@
+[pytest]
+testpaths = rdfdb
+pythonpath = __pypackages__/3.10/lib
\ No newline at end of file
--- a/rdfdb/syncedgraph/autodepgraphapi.py	Tue May 23 16:49:41 2023 -0700
+++ b/rdfdb/syncedgraph/autodepgraphapi.py	Tue May 23 19:43:57 2023 -0700
@@ -1,3 +1,7 @@
+# having trouble with bad behavior from this code, nested watchers, etc? check out 
+# https://dev.to/ryansolid/building-a-reactive-library-from-scratch-1i0p
+# https://www.solidjs.com/guides/reactivity#how-it-works
+
 import logging
 from typing import Callable, Coroutine, Dict, List, Set, Tuple, Union
 
--- a/rdfdb/syncedgraph/currentstategraphapi_test.py	Tue May 23 16:49:41 2023 -0700
+++ b/rdfdb/syncedgraph/currentstategraphapi_test.py	Tue May 23 19:43:57 2023 -0700
@@ -1,12 +1,13 @@
-import unittest
+import pytest
+from rdflib import URIRef
 
 from rdfdb.syncedgraph.syncedgraph import SyncedGraph
-from rdflib import URIRef
 
 
-class TestSequentialUri(unittest.TestCase):
+class TestSequentialUri:
 
-    def test_returnsSequentialUris(self):
+    @pytest.mark.asyncio
+    async def test_returnsSequentialUris(self):
         g = SyncedGraph(URIRef('http://example.com/db/'), label='test')
-        self.assertEqual(g.sequentialUri(URIRef('http://example.com/foo')), URIRef('http://example.com/foo1'))
-        self.assertEqual(g.sequentialUri(URIRef('http://example.com/foo')), URIRef('http://example.com/foo2'))
+        assert g.sequentialUri(URIRef('http://example.com/foo')) == URIRef('http://example.com/foo1')
+        assert g.sequentialUri(URIRef('http://example.com/foo')) == URIRef('http://example.com/foo2')
--- a/rdfdb/watched_files.py	Tue May 23 16:49:41 2023 -0700
+++ b/rdfdb/watched_files.py	Tue May 23 19:43:57 2023 -0700
@@ -46,7 +46,6 @@
         self.fileEditEvents = asyncio.Queue()
 
         log.info("setup watches")
-        print('watchedfiles')
         for p in dirsToWatch:
             self._watchTree(p)
         self._convertEventsTask = asyncio.create_task(self._convertEvents())
@@ -147,7 +146,7 @@
         except FileNotFoundError:
             log.error(f'while making WatchEvent for file {p}')
             raise
-        log.info('--> watchevent with content')
+        log.info(f'--> watchevent on {p.name} with content')
         # todo: i now think this is the point we should realize that the content
         #  is the same as what we 'recently' wrote to the file, and the caller
         #  should not be bothered with an event. What is 'recently'? If the
--- a/rdfdb/watched_graphs_test.py	Tue May 23 16:49:41 2023 -0700
+++ b/rdfdb/watched_graphs_test.py	Tue May 23 19:43:57 2023 -0700
@@ -11,6 +11,11 @@
 
 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):
     """
@@ -27,13 +32,15 @@
 async def test_make_graph_from_file(tmpdir):
     root = Path(tmpdir.mkdir("root"))
     someFile = root / 'hello.n3'
-    someFile.write_text("# some 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) == []
+    assert list(ev.content) == [(EX.a, EX.b, EX.c)]
 
     await assert_no_events_coming(wg.graphEditEvents)
-    wg.cancel()
+
+    # 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.
\ No newline at end of file