73 lines
2.2 KiB
Python
73 lines
2.2 KiB
Python
import pytest
|
|
|
|
from core.builtin_concepts import BuiltinConcepts
|
|
from core.concept import Concept
|
|
from core.sheerka.Sheerka import ExecutionContext
|
|
from sdp.sheerkaDataProvider import Event
|
|
|
|
|
|
def test_id_is_incremented_by_event_digest():
|
|
a = ExecutionContext("foo", Event("event_1"), None)
|
|
b = ExecutionContext("foo", Event("event_1"), None)
|
|
c = ExecutionContext("foo", Event("event_2"), None)
|
|
d = b.push()
|
|
e = c.push()
|
|
|
|
assert a.id == 0
|
|
assert b.id == 1
|
|
assert c.id == 0
|
|
assert d.id == 2
|
|
assert e.id == 1
|
|
|
|
|
|
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,
|
|
concepts={"bar": Concept("bar")})
|
|
a.preprocess = set()
|
|
a.preprocess.add("preprocess")
|
|
|
|
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 is None
|
|
assert b.obj == a.obj
|
|
assert b.step == a.step
|
|
assert b.iteration == a.iteration
|
|
assert b.concepts == a.concepts
|
|
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
|