Implemented SheerkaOntology

This commit is contained in:
2021-01-11 15:36:03 +01:00
parent e3c2adb533
commit e26c83a825
119 changed files with 6876 additions and 2002 deletions
+67 -5
View File
@@ -1,6 +1,7 @@
import pytest
from core.builtin_concepts import BuiltinConcepts
from core.concept import Concept, NotInit
from core.concept import Concept
from core.global_symbols import NotInit, NotFound
from core.sheerka.ExecutionContext import ExecutionContext
from core.sheerka.services.SheerkaDebugManager import SheerkaDebugManager, DebugItem, ConceptDebugObj
from parsers.PythonParser import PythonNode
@@ -830,7 +831,7 @@ class TestSheerkaDebugManager(TestUsingMemoryBasedSheerka):
dummy = DummyObj(foo, "value")
res = sheerka.inspect(context, dummy, "#type#", "fake", "a", "b")
assert res.body == {'#type#': 'DummyObj',
'fake': "** Not Found **",
'fake': NotFound,
'a': foo,
'b': 'value'}
@@ -850,19 +851,19 @@ class TestSheerkaDebugManager(TestUsingMemoryBasedSheerka):
res = sheerka.inspect(context, 0)
assert res.body == {'#type#': 'NotFound',
assert res.body == {'#type#': 'NotFoundConcept',
'id': sheerka.concepts_ids[BuiltinConcepts.NOT_FOUND],
'key': '__NOT_FOUND',
'name': '__NOT_FOUND',
'body': 'no digest'}
def test_i_can_inspect_values(self):
sheerka, context, table, how, little = self.init_concepts(
sheerka, context, table, how, little = self.init_test().with_concepts(
"table",
Concept("how is x").def_var("x"),
Concept("little x").def_var("x"),
create_new=True
)
).unpack()
return_values = sheerka.evaluate_user_input("how is little table")
@@ -911,3 +912,64 @@ class TestSheerkaDebugManager(TestUsingMemoryBasedSheerka):
assert str(ConceptDebugObj(foo)) == \
"(:foo|1001:meta.x='x_meta', meta.y='y_meta', compiled.x=(:bar|1002:meta.a='a_meta', value.a='a_value'), value.x='x_value', value.z='extra_value')"
def test_i_can_save_and_restore_state_to_default_state(self):
sheerka, context = self.init_concepts()
service = sheerka.services[SheerkaDebugManager.NAME]
sheerka.push_ontology(context, "new ontology")
service.set_debug(context)
service.set_explicit(context)
service.debug_var(context, "var_service.var_method.var_name", "1+", 1)
service.debug_rule(context, "rule_service.rule_method.rule_name", "2+", 2)
service.debug_concept(context, "concept_service.concept_method.concept_name", "3+", 3)
# sanity check
assert service.activated
assert service.explicit
assert service.debug_vars_settings != []
assert service.debug_rules_settings != []
assert service.debug_concepts_settings != []
sheerka.pop_ontology()
assert not service.activated
assert not service.explicit
assert service.context_cache == set()
assert service.variable_cache == set()
assert service.debug_vars_settings == []
assert service.debug_rules_settings == []
assert service.debug_concepts_settings == []
def test_i_can_save_and_restore_state_to_specific_state(self):
sheerka, context = self.init_concepts()
service = sheerka.services[SheerkaDebugManager.NAME]
service.set_debug(context)
service.set_explicit(context)
service.debug_var(context, "v_service.v_method.v_name", "1+", 1)
service.debug_rule(context, "r_service.r_method.r_name", "2+", 2)
service.debug_concept(context, "c_serv.c_method.c_name", "3+", 3)
sheerka.push_ontology(context, "new ontology")
# modify the state
service.set_debug(context, False)
service.set_explicit(context, False)
service.debug_var(context, "var_service2.var_method2.var_name2", "11+", 11)
service.debug_rule(context, "rule_service2.rule_method2.rule_name2", "22+", 22)
service.debug_concept(context, "concept_service2.concept_method2.concept_name2", "33+", 33)
# sanity
assert not service.activated
assert not service.explicit
assert len(service.debug_vars_settings) == 2
assert len(service.debug_rules_settings) == 2
assert len(service.debug_concepts_settings) == 2
sheerka.pop_ontology()
assert service.activated
assert service.explicit
assert service.debug_vars_settings == [DebugItem("v_name", "v_service", "v_method", 1, True, 1, False, True)]
assert service.debug_rules_settings == [DebugItem("r_name", "r_service", "r_method", 2, True, 2, False, True)]
assert service.debug_concepts_settings == [DebugItem("c_name", "c_serv", "c_method", 3, True, 3, False, True)]