Fixed #18 : Parsing and evaluating Python

This commit is contained in:
2023-05-14 12:12:29 +02:00
parent e41094f908
commit 09a0246420
46 changed files with 2084 additions and 165 deletions
+2 -1
View File
@@ -10,7 +10,7 @@ def test_i_can_retrieve_concept_properties():
assert foo.id == "1001"
assert foo.str_id == "c:#1001:"
assert foo.all_attrs() == ('#where#', '#pre#', '#post#', '#body#', '#ret#', 'a', 'b')
assert foo.get_definition_digest() == "3a2cfcda8ffd0d99a7f8c7d2f1ffc4a99fc96162f3be7b9875f30751d3691af6"
assert foo.get_definition_digest() == "13b61f45934a802b5486a1bdd60e404b32378a801408769cd584e3b3b7518cc2"
# sanity check to make sure that 'get_concept' works as expected
assert foo.get_metadata().variables == (("a", NotInit), ("b", NotInit))
@@ -20,6 +20,7 @@ def test_i_can_set_and_get_value():
foo = get_concept("foo", variables=["a"])
foo.set_value("a", "some value")
assert foo.get_value("a") == "some value"
assert foo.a == "some value"
def test_i_can_set_and_get_value_from_bound_attr():
+60 -34
View File
@@ -1,15 +1,15 @@
from core.Event import Event
from core.ExecutionContext import ExecutionContext, ExecutionContextActions
from core.ExecutionContext import ExecutionContext, ContextActions
def test_i_can_create_execution_context(sheerka):
event = Event("myEvent", "fake_userid")
context1 = ExecutionContext("who", event, sheerka, ExecutionContextActions.TESTING, "value1", "my desc")
context1 = ExecutionContext("who", event, sheerka, ContextActions.TESTING, "value1", "my desc")
assert context1.who == "who"
assert context1.event == event
assert context1.sheerka == sheerka
assert context1.action == ExecutionContextActions.TESTING
assert context1.action == ContextActions.TESTING
assert context1.action_context == "value1"
assert context1.desc == "my desc"
assert context1.id == 0
@@ -18,12 +18,12 @@ def test_i_can_create_execution_context(sheerka):
def test_i_can_push(sheerka):
event = Event("test")
context = ExecutionContext("who", event, sheerka, ExecutionContextActions.TESTING, "value")
with context.push("pusher", ExecutionContextActions.PARSING, "action_context", "my desc") as sub_context:
context = ExecutionContext("who", event, sheerka, ContextActions.TESTING, "value")
with context.push("pusher", ContextActions.PARSING, "action_context", "my desc") as sub_context:
assert sub_context.who == "pusher"
assert sub_context.event == event
assert sub_context.sheerka == sheerka
assert sub_context.action == ExecutionContextActions.PARSING
assert sub_context.action == ContextActions.PARSING
assert sub_context.action_context == "action_context"
assert sub_context.desc == "my desc"
assert sub_context.id == context.id + 1
@@ -34,11 +34,11 @@ def test_i_can_increment_ids(sheerka):
# If the event is the same, the id is incremented
event = Event("TEST::myEvent", "fake_userid")
context1 = ExecutionContext("who", event, sheerka, ExecutionContextActions.TESTING, "value")
context2 = context1.push("who1", ExecutionContextActions.TESTING, "value1")
context3 = context2.push("who2", ExecutionContextActions.TESTING, "value2")
context4 = context1.push("who1", ExecutionContextActions.TESTING, "value3")
context5 = ExecutionContext("who", event, sheerka, ExecutionContextActions.TESTING, "value4")
context1 = ExecutionContext("who", event, sheerka, ContextActions.TESTING, "value")
context2 = context1.push("who1", ContextActions.TESTING, "value1")
context3 = context2.push("who2", ContextActions.TESTING, "value2")
context4 = context1.push("who1", ContextActions.TESTING, "value3")
context5 = ExecutionContext("who", event, sheerka, ContextActions.TESTING, "value4")
assert context1.id == 0
assert context2.id == 1
@@ -47,15 +47,15 @@ def test_i_can_increment_ids(sheerka):
assert context5.id == 4
event2 = Event("TEST::myEvent2", "fake_userid")
context6 = ExecutionContext("who", event2, sheerka, ExecutionContextActions.TESTING, "value")
context6 = ExecutionContext("who", event2, sheerka, ContextActions.TESTING, "value")
assert context6.id == 0
def test_i_can_manage_global_hints(context):
context2 = context.push("pusher", ExecutionContextActions.TESTING, None)
context3 = context2.push("pusher", ExecutionContextActions.TESTING, None)
context4 = context3.push("pusher", ExecutionContextActions.TESTING, None)
context5 = context.push("pusher", ExecutionContextActions.TESTING, None)
context2 = context.push("pusher", ContextActions.TESTING, None)
context3 = context2.push("pusher", ContextActions.TESTING, None)
context4 = context3.push("pusher", ContextActions.TESTING, None)
context5 = context.push("pusher", ContextActions.TESTING, None)
context.global_hints.add("new_hint")
assert context.global_hints == {"new_hint"}
@@ -75,11 +75,11 @@ def test_i_can_manage_global_hints(context):
def test_i_can_manage_protected_hint(context):
# Note that protected hint only works if the hint is added BEFORE the creation of the child
context.protected_hints.add("new_hint")
context2 = context.push("pusher", ExecutionContextActions.TESTING, None)
context3 = context2.push("pusher", ExecutionContextActions.TESTING, None)
context2 = context.push("pusher", ContextActions.TESTING, None)
context3 = context2.push("pusher", ContextActions.TESTING, None)
context3.protected_hints.add("another_hint")
context4 = context3.push("pusher", ExecutionContextActions.TESTING, None)
context5 = context.push("pusher", ExecutionContextActions.TESTING, None)
context4 = context3.push("pusher", ContextActions.TESTING, None)
context5 = context.push("pusher", ContextActions.TESTING, None)
assert context.protected_hints == {"new_hint"}
assert context2.protected_hints == {"new_hint"}
@@ -90,11 +90,11 @@ def test_i_can_manage_protected_hint(context):
def test_i_can_manage_private_hints(context):
context.private_hints.add("new_hint")
context2 = context.push("pusher", ExecutionContextActions.TESTING, None)
context3 = context2.push("pusher", ExecutionContextActions.TESTING, None)
context2 = context.push("pusher", ContextActions.TESTING, None)
context3 = context2.push("pusher", ContextActions.TESTING, None)
context3.private_hints.add("another_hint")
context4 = context3.push("pusher", ExecutionContextActions.TESTING, None)
context5 = context.push("pusher", ExecutionContextActions.TESTING, None)
context4 = context3.push("pusher", ContextActions.TESTING, None)
context5 = context.push("pusher", ContextActions.TESTING, None)
assert context.private_hints == {"new_hint"}
assert context2.private_hints == set()
@@ -103,10 +103,24 @@ def test_i_can_manage_private_hints(context):
assert context5.private_hints == set()
def test_i_can_check_if_hints_are_in_context(context):
context.private_hints.add("private_hint")
context.protected_hints.add("protected_hint")
context.global_hints.add("global_hint")
assert context.in_context("private_hint")
assert context.in_context("protected_hint")
assert context.in_context("global_hint")
context2 = context.push("pusher", ContextActions.TESTING, None)
assert not context2.in_context("private_hint")
assert context2.in_context("protected_hint")
assert context2.in_context("global_hint")
def test_i_can_keep_track_of_children(context):
context2 = context.push("pusher", ExecutionContextActions.TESTING, None)
context3 = context.push("pusher", ExecutionContextActions.TESTING, None)
context4 = context2.push("pusher2", ExecutionContextActions.TESTING, None)
context2 = context.push("pusher", ContextActions.TESTING, None)
context3 = context.push("pusher", ContextActions.TESTING, None)
context4 = context2.push("pusher2", ContextActions.TESTING, None)
assert len(context._children) == 2
assert len(context2._children) == 1
@@ -115,13 +129,13 @@ def test_i_can_keep_track_of_children(context):
def test_i_can_get_children(context):
context1 = context.push("child 1", ExecutionContextActions.TESTING, None)
context2 = context.push("child 2", ExecutionContextActions.TESTING, None)
context3 = context.push("child 3", ExecutionContextActions.TESTING, None)
context21 = context2.push("child 21", ExecutionContextActions.TESTING, None)
context22 = context2.push("child 22", ExecutionContextActions.TESTING, None)
context211 = context21.push("child 211", ExecutionContextActions.TESTING, None)
context31 = context3.push("child 31", ExecutionContextActions.TESTING, None)
context1 = context.push("child 1", ContextActions.TESTING, None)
context2 = context.push("child 2", ContextActions.TESTING, None)
context3 = context.push("child 3", ContextActions.TESTING, None)
context21 = context2.push("child 21", ContextActions.TESTING, None)
context22 = context2.push("child 22", ContextActions.TESTING, None)
context211 = context21.push("child 211", ContextActions.TESTING, None)
context31 = context3.push("child 31", ContextActions.TESTING, None)
assert list(context1.get_children()) == []
@@ -149,3 +163,15 @@ def test_i_can_get_children(context):
context3,
context31,
]
def test_i_can_get_parents(context):
context1 = context.push("child 1", ContextActions.TESTING, None)
context2 = context1.push("child 2", ContextActions.TESTING, None)
context3 = context2.push("child 3", ContextActions.TESTING, None)
assert list(context3.get_parents()) == [context2, context1, context]
assert list(context3.get_parents(level=1)) == [context2]
assert list(context3.get_parents(level=2)) == [context2, context1]
assert list(context3.get_parents(level=3)) == [context2, context1, context]
assert list(context3.get_parents(level=4)) == [context2, context1, context]