First implementation of Debugger for SyaNodeParser
This commit is contained in:
@@ -2,6 +2,7 @@ from dataclasses import dataclass
|
||||
|
||||
import core.utils
|
||||
import pytest
|
||||
from core.builtin_concepts import BuiltinConcepts
|
||||
from core.concept import Concept
|
||||
from core.tokenizer import Token, TokenKind, Tokenizer, Keywords
|
||||
|
||||
@@ -338,3 +339,81 @@ def test_i_can_get_text_from_tokens(text, expected_text):
|
||||
def test_i_can_get_text_from_tokens_with_custom_switcher(text, custom, expected_text):
|
||||
tokens = list(Tokenizer(text))
|
||||
assert core.utils.get_text_from_tokens(tokens, custom) == expected_text
|
||||
|
||||
|
||||
def test_i_can_deep_copy_a_concept():
|
||||
def check_are_the_same(actual, expected):
|
||||
assert id(actual) != id(expected)
|
||||
|
||||
for k, v in vars(expected.get_metadata()).items():
|
||||
assert getattr(actual.get_metadata(), k) == v
|
||||
|
||||
# test the values
|
||||
for k, v in expected.values().items():
|
||||
assert getattr(actual, k) == v
|
||||
|
||||
concept1 = Concept(name="concept1_name",
|
||||
is_builtin=True,
|
||||
is_unique=True,
|
||||
key="concept1_key",
|
||||
body="concept1_body",
|
||||
where='concept1_where',
|
||||
pre="concept1_pre",
|
||||
post="concept1_post",
|
||||
ret="concept1_ret",
|
||||
definition="concept1_definition",
|
||||
definition_type="concept1_definition_type",
|
||||
desc="concept1_desc",
|
||||
id="concept1_ids",
|
||||
props="concept1_props",
|
||||
variables=[],
|
||||
bound_body=None)
|
||||
|
||||
concept2 = Concept(name="concept2_name",
|
||||
is_builtin=True,
|
||||
is_unique=True,
|
||||
key="concept2_key",
|
||||
body="concept2_body",
|
||||
where='concept2_where',
|
||||
pre="concept2_pre",
|
||||
post="concept2_post",
|
||||
ret="concept2_ret",
|
||||
definition="concept2_definition",
|
||||
definition_type="concept2_definition_type",
|
||||
desc="concept2_desc",
|
||||
id="concept2_ids",
|
||||
props={"prop_name": concept1},
|
||||
variables=[("var1", "default_value1"), ("var2", "default_value2")],
|
||||
bound_body="var1")
|
||||
|
||||
concept = Concept(name="my_name",
|
||||
is_builtin=True,
|
||||
is_unique=True,
|
||||
key="my_key",
|
||||
body="my_body",
|
||||
where='my_where',
|
||||
pre="my_pre",
|
||||
post="my_post",
|
||||
ret="my_ret",
|
||||
definition="my_definition",
|
||||
definition_type="my_definition_type",
|
||||
desc="my_desc",
|
||||
id="my_ids",
|
||||
props={
|
||||
BuiltinConcepts.ISA: {concept1, concept2},
|
||||
"prop2": ["value1, value2"],
|
||||
"prop3": {"a": 1, "b": 2},
|
||||
"prop4": "a simple value"},
|
||||
variables=[("var1", "default_value1"), ("var2", "default_value2")])
|
||||
concept.set_value("var1", "string_value")
|
||||
concept.set_value("var2", 10)
|
||||
concept.set_value("var3", concept1)
|
||||
|
||||
copied = core.utils.sheerka_deepcopy(concept)
|
||||
|
||||
check_are_the_same(copied, concept)
|
||||
|
||||
copied_props = sorted(list(copied.get_prop(BuiltinConcepts.ISA)), key=lambda o: o.id)
|
||||
concept_props = sorted(list(concept.get_prop(BuiltinConcepts.ISA)), key=lambda o: o.id)
|
||||
for copied_prop, concept_prop in zip(copied_props, concept_props):
|
||||
check_are_the_same(copied_prop, concept_prop)
|
||||
|
||||
Reference in New Issue
Block a user