Updated sheerka.value() and added unit tests
This commit is contained in:
@@ -45,7 +45,6 @@ class BuiltinConcepts(Enum):
|
||||
ENUMERATION = "enum" # represents a list or a set
|
||||
LIST = "list" # represents a list
|
||||
CANNOT_RESOLVE_VALUE_ERROR = "value cannot be resolved" # don't know how to find concept value
|
||||
CONCEPT_NOT_INITIALIZED = "concept not evaluated" # Try to work on a concept that is not evaluated
|
||||
|
||||
NODE = "node"
|
||||
GENERIC_NODE = "generic node"
|
||||
@@ -69,7 +68,6 @@ BuiltinErrors = [str(e) for e in {
|
||||
BuiltinConcepts.CONCEPT_ALREADY_DEFINED,
|
||||
BuiltinConcepts.CONCEPT_EVAL_ERROR,
|
||||
BuiltinConcepts.CANNOT_RESOLVE_VALUE_ERROR,
|
||||
BuiltinConcepts.CONCEPT_NOT_INITIALIZED
|
||||
}]
|
||||
|
||||
"""
|
||||
@@ -293,27 +291,6 @@ class ConceptEvalError(Concept):
|
||||
return self.props["property_name"].value
|
||||
|
||||
|
||||
class ConceptNotInitialized(Concept):
|
||||
def __init__(self, error=None, concept=None, property_name=None):
|
||||
super().__init__(BuiltinConcepts.CONCEPT_NOT_INITIALIZED,
|
||||
True,
|
||||
False,
|
||||
BuiltinConcepts.CONCEPT_NOT_INITIALIZED,
|
||||
error)
|
||||
self.set_prop("concept", concept)
|
||||
|
||||
def __repr__(self):
|
||||
return f"ConceptNotInitialized(error={self.error}, concept={self.concept})"
|
||||
|
||||
@property
|
||||
def error(self):
|
||||
return self.body
|
||||
|
||||
@property
|
||||
def concept(self):
|
||||
return self.props["concept"].value
|
||||
|
||||
|
||||
class EnumerationConcept(Concept):
|
||||
def __init__(self, iteration=None):
|
||||
super().__init__(BuiltinConcepts.ENUMERATION, True, False, BuiltinConcepts.ENUMERATION, iteration)
|
||||
|
||||
+6
-3
@@ -546,7 +546,7 @@ class Sheerka(Concept):
|
||||
return from_db
|
||||
|
||||
# else return new Unknown concept
|
||||
# Note that I don't call the new() method, as it use get() -> cyclic call
|
||||
# Note that I don't call the new() method to prevent cyclic call
|
||||
unknown_concept = Concept()
|
||||
template = self.concepts_cache[str(BuiltinConcepts.UNKNOWN_CONCEPT)]
|
||||
unknown_concept.update_from(template)
|
||||
@@ -623,7 +623,7 @@ class Sheerka(Concept):
|
||||
if self.isinstance(obj, BuiltinConcepts.RETURN_VALUE) and \
|
||||
obj.status and \
|
||||
self.isinstance(obj.value, BuiltinConcepts.USER_INPUT):
|
||||
return obj.value.text
|
||||
return obj.value.body
|
||||
|
||||
if not isinstance(obj, Concept):
|
||||
return obj
|
||||
@@ -632,7 +632,10 @@ class Sheerka(Concept):
|
||||
return obj.get_value()
|
||||
|
||||
if obj.body is not None:
|
||||
return obj.body
|
||||
if (isinstance(obj.body, list) or isinstance(obj.body, set)) and len(obj.body) == 1:
|
||||
return obj.body[0]
|
||||
else:
|
||||
return obj.body
|
||||
|
||||
return obj if allow_none_body else self.new(BuiltinConcepts.CANNOT_RESOLVE_VALUE_ERROR, body=obj)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user