feat: Data and client framework

This commit is contained in:
2026-05-31 05:05:01 +10:00
parent 19da69b3e8
commit b188abcad0
18 changed files with 643 additions and 313 deletions
+52 -4
View File
@@ -1,11 +1,13 @@
from parsimonious.grammar import Grammar
from customcmd.parser import Execuitor, ExecContext
from customcmd.client import ExecClient
from customcmd.parser import Execuitor
from customcmd.context import ExecContext
import pytest
import asyncio
# from customcmd.parser.context import ExecScope
@pytest.fixture
def grammar():
@@ -21,7 +23,8 @@ def executor():
@pytest.fixture
def context():
ctx = ExecContext(
alias="test_cmd", args=["testarg1", "testarg2"], content="Base content"
alias='test_cmd',
args=["testarg1", "testarg2"], content="Base content"
)
return ctx
@@ -148,7 +151,7 @@ class TestGrammar:
@pytest.mark.asyncio
async def test_basic_obj(self, grammar, executor, context):
context.scope["obj"] = TestObject()
context.this_scope["obj"] = TestObject()
expected_results = [
("${obj}", "Testing Object"),
@@ -225,3 +228,48 @@ class TestClient:
async def test_command_2(self, client, context):
actual = await client.run_command(context, "A test ${2} of the client ${$2}")
assert actual == "A test 2 of the client testarg2"
class LaterTestScope:
def test_scope_toplevel(self):
scope = ExecScope()
scope['key'] = 'value'
assert scope['key'] == 'value'
def test_scope_stack(self):
scope = ExecScope()
scope['key'] = 'value1'
scope.enter_scope()
assert scope['key'] == 'value1'
scope['key'] = 'value12'
assert scope['key'] == 'value12'
scope['key2'] = 'value2'
assert scope['key2'] == 'value2'
scope.leave_scope()
assert scope.get('key2') is None
assert scope['key'] == 'value'
def test_scope_enter_init(self):
scope = ExecScope(key="value1")
assert scope['key'] == 'value1'
scope.enter_scope(key2="value2")
assert scope['key2'] == 'value2'
scope.leave_scope()
assert scope.get('key2') is None
assert scope.get('key') == 'value1'