Implemented SheerkaOntology
This commit is contained in:
@@ -2,7 +2,8 @@ from dataclasses import dataclass
|
||||
|
||||
import pytest
|
||||
from core.builtin_concepts import BuiltinConcepts
|
||||
from core.concept import Concept, ConceptParts
|
||||
from core.concept import Concept, ConceptParts, freeze_concept_attrs
|
||||
from core.simple_debug import my_debug
|
||||
from printer.Formatter import Formatter, BraceToken
|
||||
from printer.SheerkaPrinter import FormatInstructions
|
||||
|
||||
@@ -154,10 +155,13 @@ class TestSheerkaPrinter(TestUsingMemoryBasedSheerka):
|
||||
# for all obj of a given type
|
||||
|
||||
sheerka = self.get_sheerka()
|
||||
sheerka.printer_handler.reset()
|
||||
|
||||
foo = Concept("foo a b").def_var("a").def_var("b").init_key()
|
||||
foo.set_value("a", "value a").set_value("b", "value b")
|
||||
foo.set_value(ConceptParts.BODY, "body")
|
||||
sheerka.set_id_if_needed(foo, False)
|
||||
freeze_concept_attrs(foo)
|
||||
|
||||
sheerka.printer_handler.register_format_l(foo, "DEFAULT:{id}-{name}-{key}-{body}-{a}-{b}")
|
||||
|
||||
@@ -170,10 +174,13 @@ class TestSheerkaPrinter(TestUsingMemoryBasedSheerka):
|
||||
# for all obj of a given type in the current print call
|
||||
|
||||
sheerka = self.get_sheerka()
|
||||
sheerka.printer_handler.reset()
|
||||
|
||||
foo = Concept("foo a b").def_var("a").def_var("b").init_key()
|
||||
foo.set_value("a", "value a").set_value("b", "value b")
|
||||
foo.set_value(ConceptParts.BODY, "body")
|
||||
sheerka.set_id_if_needed(foo, False)
|
||||
freeze_concept_attrs(foo)
|
||||
|
||||
sheerka.printer_handler.register_format_l(foo, "DEFAULT:{id}-{name}-{key}-{body}-{a}-{b}")
|
||||
context_instructions = FormatInstructions().set_format_l(foo, "CONTEXT:{id}-{name}-{key}-{body}-{a}-{b}")
|
||||
@@ -187,10 +194,13 @@ class TestSheerkaPrinter(TestUsingMemoryBasedSheerka):
|
||||
# for the item only
|
||||
|
||||
sheerka = self.get_sheerka()
|
||||
sheerka.printer_handler.reset()
|
||||
|
||||
foo = Concept("foo a b").def_var("a").def_var("b").init_key()
|
||||
foo.set_value("a", "value a").set_value("b", "value b")
|
||||
foo.set_value(ConceptParts.BODY, "body")
|
||||
sheerka.set_id_if_needed(foo, False)
|
||||
freeze_concept_attrs(foo)
|
||||
|
||||
sheerka.printer_handler.register_format_l(foo, "{id}-{name}-{key}-{body}-{a}-{b}")
|
||||
context_instructions = FormatInstructions().set_format_l(foo, "CONTEXT:{id}-{name}-{key}-{body}-{a}-{b}")
|
||||
@@ -242,6 +252,8 @@ class TestSheerkaPrinter(TestUsingMemoryBasedSheerka):
|
||||
|
||||
def test_i_can_format_d_concepts_using_default_definition(self, capsys):
|
||||
sheerka, context, foo = self.init_concepts(Concept("foo a b").def_var("a").def_var("b"))
|
||||
sheerka.printer_handler.reset()
|
||||
|
||||
foo_1 = sheerka.new(foo.key, a="value a", b="value b")
|
||||
foo_2 = sheerka.new(foo.key, a="value c", b="value d")
|
||||
lst = [foo_1, foo_2]
|
||||
@@ -259,6 +271,8 @@ b: DEFAULT:'value d'
|
||||
|
||||
def test_i_can_format_d_concepts_using_context_definition(self, capsys):
|
||||
sheerka, context, foo = self.init_concepts(Concept("foo a b").def_var("a").def_var("b"))
|
||||
sheerka.printer_handler.reset()
|
||||
|
||||
foo_1 = sheerka.new(foo.key, a="value a", b="value b")
|
||||
foo_2 = sheerka.new(foo.key, a="value c", b="value d")
|
||||
lst = [foo_1, foo_2]
|
||||
@@ -277,6 +291,8 @@ b: CONTEXT:'value d'
|
||||
|
||||
def test_i_can_format_d_concepts_using_item_definition(self, capsys):
|
||||
sheerka, context, foo = self.init_concepts(Concept("foo a b").def_var("a").def_var("b"))
|
||||
sheerka.printer_handler.reset()
|
||||
|
||||
item_instructions = FormatInstructions().set_format_d(foo, {"a": "ITEM:{a}", "b": "ITEM:{b}"})
|
||||
foo.set_format_instructions(item_instructions)
|
||||
foo_1 = sheerka.new(foo.key, a="value a", b="value b")
|
||||
@@ -371,6 +387,8 @@ self: (1001)foo a b
|
||||
|
||||
def test_i_can_format_d_when_dictionary(self, capsys):
|
||||
sheerka, context, foo = self.init_concepts(Concept("foo a b").def_var("a").def_var("b"))
|
||||
sheerka.printer_handler.reset()
|
||||
|
||||
dict_value = {
|
||||
"a": "value a",
|
||||
"beta": {"b1": 10, "b2": Obj("10", 15), "b3": ["items", "in", "a", "list"]},
|
||||
@@ -436,6 +454,8 @@ bar: *name 'bar' is not defined*
|
||||
])
|
||||
def test_i_can_concat_print_instruction_and_register_format(self, capsys, template, expected):
|
||||
sheerka = self.get_sheerka()
|
||||
sheerka.printer_handler.reset()
|
||||
|
||||
foo = Obj("value a", "value b")
|
||||
|
||||
sheerka.printer_handler.register_format_l("tests.core.test_sheerka_printer.Obj", "{a}")
|
||||
|
||||
Reference in New Issue
Block a user