diff --git a/apidemo/__init__.py b/apidemo/__init__.py new file mode 100644 index 0000000..80cbae4 --- /dev/null +++ b/apidemo/__init__.py @@ -0,0 +1 @@ +# py-scopes: apidemo diff --git a/demo/__init__.py b/demo/__init__.py new file mode 100644 index 0000000..c326fba --- /dev/null +++ b/demo/__init__.py @@ -0,0 +1,2 @@ +# py-scopes: demo + diff --git a/scopes/core/__init__.py b/scopes/core/__init__.py index 1d165e4..b7b6e4b 100644 --- a/scopes/core/__init__.py +++ b/scopes/core/__init__.py @@ -1 +1,4 @@ """package scopes.core""" + +from .core import * + diff --git a/scopes/core/actor.py b/scopes/core/actor.py index 32c02dd..091e96c 100644 --- a/scopes/core/actor.py +++ b/scopes/core/actor.py @@ -14,7 +14,7 @@ async def loop(q, bhv): def create(bhv, group=None): q = asyncio.Queue() if group is None: - return q, asyncio.create_task(loop(q, bhv)) + asyncio.create_task(loop(q, bhv)) else: group.create_task(loop(q, bhv)) return q diff --git a/scopes/core/core.py b/scopes/core/core.py new file mode 100644 index 0000000..50affe8 --- /dev/null +++ b/scopes/core/core.py @@ -0,0 +1,22 @@ +# scopes.core.core + +"""The scopes.core package""" + +import asyncio +from dataclasses import dataclass +from types import CoroutineType, FunctionType +from typing import Any + +from scopes.util import keywords as k, Symbol + +@dataclass +class Scope: + + value: Any = 0 + categ: tuple[Symbol, Symbol] = (k.csys, k.c00) + stage: Symbol = k.initial + proc: CoroutineType | None = None + program: dict[tuple[Symbol, Symbol], CoroutineType] = {} + syns: list[FunctionType] = [] + environ: asyncio.Queue | None = None + diff --git a/scopes/shape.py b/scopes/shape.py index 5e198ac..8642955 100644 --- a/scopes/shape.py +++ b/scopes/shape.py @@ -6,8 +6,8 @@ from scopes.util import keywords as k class Record: - headFields = () # to be defined by subclass - headFieldsAsKeywords = set() + headFields: tuple = () # to be defined by subclass + headFieldsAsKeywords: set[str] = set() defaultHeadValue = '' def __init__(self, *headValues, data=None, **kw): diff --git a/scopes/testing.py b/scopes/testing.py index 1bbe686..53d4cb3 100644 --- a/scopes/testing.py +++ b/scopes/testing.py @@ -1,6 +1,7 @@ # scopes.testing """Common stuff (config, fixtures, ...) for testing""" + import os, sys sys.path = [os.path.dirname(__file__)] + sys.path diff --git a/tests/test_actor.py b/tests/test_core.py similarity index 67% rename from tests/test_actor.py rename to tests/test_core.py index c544bf7..37fbc58 100644 --- a/tests/test_actor.py +++ b/tests/test_core.py @@ -1,10 +1,11 @@ -# py-scopes: tests.test_actor +# py-scopes: tests.test_core -""" Tests for scopes.core.actor""" +""" Tests for scopes.core modules, including e.g. actor, message""" import asyncio import pytest +from scopes import core from scopes.core import actor, message from scopes.util import keywords as k @@ -13,6 +14,7 @@ collector = [] def show(msg): collector.append(msg) + async def handle_basic(msg): match msg: case k.show: show(msg) @@ -38,8 +40,20 @@ async def test_actor(): await q2.put(k.show) await q1.put(k.quit) await q2.put(k.quit) - #await asyncio.wait([t1, t2]) - print(collector) + #print(collector) assert len(collector) == 6 assert collector[-1] == 'actor 1: Goodbye' + +def test_message(): + msg = message.Message(k.test, k.data, 'person', '4711', + data=dict(firstName='Bob', lastName='Miller')) + assert msg.head['class'] is k.person + assert msg.addr() == (k.test, k.person, '4711') + assert msg.categ() == (k.test, k.person) + + +def test_core(): + sc = core.Scope() + assert sc.value == 0 + diff --git a/tests/test_message.py b/tests/test_message.py deleted file mode 100644 index fb6b7cf..0000000 --- a/tests/test_message.py +++ /dev/null @@ -1,16 +0,0 @@ -# py-scopes: tests.test_message - -"""Tests for messages and related stuff""" - -import pytest - -from scopes.util import keywords as k - -def test_message(): - from scopes.core.message import Message - msg = Message(k.test, k.data, 'person', '4711', - data=dict(firstName='Bob', lastName='Miller')) - assert msg.head['class'] is k.person - assert msg.addr() == (k.test, k.person, '4711') - assert msg.categ() == (k.test, k.person) -