Enhanced ExecutionContext to keep track of the execution flow
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import pytest
|
||||
|
||||
from core.builtin_concepts import BuiltinConcepts
|
||||
from core.concept import Concept
|
||||
from core.sheerka import ExecutionContext
|
||||
@@ -18,9 +20,14 @@ def test_id_is_incremented_by_event_digest():
|
||||
assert e.id == 1
|
||||
|
||||
|
||||
def test_some_properties_are_given_to_the_child():
|
||||
a = ExecutionContext("foo", Event("event_1"), "fake_sheerka",
|
||||
desc="some description",
|
||||
def test_i_can_use_with_statement():
|
||||
with ExecutionContext("who_", Event("event"), "fake_sheerka") as e:
|
||||
pass
|
||||
assert e.elapsed > 0
|
||||
|
||||
|
||||
def test_i_can_push():
|
||||
a = ExecutionContext("foo", Event("event_1"), "fake_sheerka", "some description",
|
||||
obj=Concept("foo"),
|
||||
step=BuiltinConcepts.EVALUATION,
|
||||
iteration=15,
|
||||
@@ -30,10 +37,11 @@ def test_some_properties_are_given_to_the_child():
|
||||
|
||||
b = a.push()
|
||||
|
||||
assert b._parent == a
|
||||
assert b.who == a.who
|
||||
assert b.event == a.event
|
||||
assert b.sheerka == a.sheerka
|
||||
assert b.desc == ""
|
||||
assert b.desc is None
|
||||
assert b.obj == a.obj
|
||||
assert b.step == a.step
|
||||
assert b.iteration == a.iteration
|
||||
@@ -41,3 +49,24 @@ def test_some_properties_are_given_to_the_child():
|
||||
assert b.id == a.id + 1
|
||||
assert b._tab == a._tab + " "
|
||||
assert b.preprocess == a.preprocess
|
||||
|
||||
|
||||
def test_children_i_created_when_i_push():
|
||||
e = ExecutionContext("who_", Event("event"), "fake_sheerka")
|
||||
e.push("a", desc="I do something")
|
||||
e.push("b", desc="oups! I did a again")
|
||||
e.push("c", desc="I do something else")
|
||||
|
||||
assert len(e.children) == 3
|
||||
assert e.children[0].who, e.children[0].who == ("a", "I do something")
|
||||
assert e.children[1].who, e.children[1].who == ("b", "oups! I did a again")
|
||||
assert e.children[2].who, e.children[2].who == ("c", "I do something else")
|
||||
|
||||
|
||||
def test_i_can_add_variable_when_i_push():
|
||||
e = ExecutionContext("who_", Event("event"), "fake_sheerka")
|
||||
sub_e = e.push("a", my_new_var="new var value")
|
||||
|
||||
assert sub_e.my_new_var == "new var value"
|
||||
with pytest.raises(AttributeError):
|
||||
assert e.my_new_var == "" # my_new_var does not exist in parent
|
||||
|
||||
Reference in New Issue
Block a user