Enhanced PythonEvaluator to accept concepts
This commit is contained in:
+24
-79
@@ -33,6 +33,11 @@ def init_test():
|
||||
os.chdir(current_pwd)
|
||||
|
||||
|
||||
class ConceptWithGetValue(Concept):
|
||||
def get_value(self):
|
||||
return self.get_prop("my_prop")
|
||||
|
||||
|
||||
def test_root_folder_is_created_after_initialization():
|
||||
return_value = Sheerka().initialize(root_folder)
|
||||
assert return_value.status, "initialisation should be successful"
|
||||
@@ -288,93 +293,33 @@ def test_i_cannot_instantiate_when_properties_are_not_recognized():
|
||||
assert sheerka.isinstance(new.concept, concept)
|
||||
|
||||
|
||||
def test_i_can_use_expect_one_when_empty():
|
||||
@pytest.mark.parametrize("concept, allow_non_body, expected", [
|
||||
(None, False, None),
|
||||
(3.14, False, 3.14),
|
||||
(Concept("name", body="foo"), False, "foo"),
|
||||
(Concept("name"), True, Concept("name")),
|
||||
(ConceptWithGetValue("name").set_prop("my_prop", "my_value"), True, "my_value"),
|
||||
])
|
||||
def test_i_can_get_value(concept, allow_non_body, expected):
|
||||
sheerka = get_sheerka()
|
||||
|
||||
res = sheerka.expect_one(get_context(sheerka), [])
|
||||
assert not res.status
|
||||
assert sheerka.isinstance(res.value, BuiltinConcepts.IS_EMPTY)
|
||||
assert sheerka.value(concept, allow_non_body) == expected
|
||||
|
||||
|
||||
def test_i_can_use_expect_one_when_too_many_success():
|
||||
def test_i_cannot_get_value_when_no_body_and_allow_none_body_is_false():
|
||||
sheerka = get_sheerka()
|
||||
concept = Concept("name")
|
||||
allow_none_body = False
|
||||
|
||||
items = [
|
||||
ReturnValueConcept("who", True, None),
|
||||
ReturnValueConcept("who", True, None),
|
||||
]
|
||||
res = sheerka.expect_one(get_context(sheerka), items)
|
||||
assert not res.status
|
||||
assert sheerka.isinstance(res.value, BuiltinConcepts.TOO_MANY_SUCCESS)
|
||||
assert res.value.obj == items
|
||||
assert sheerka.value(concept, allow_none_body) == sheerka.new(BuiltinConcepts.CANNOT_RESOLVE_VALUE_ERROR,
|
||||
body=concept)
|
||||
|
||||
|
||||
def test_i_can_use_expect_when_only_errors_1():
|
||||
sheerka = get_sheerka()
|
||||
|
||||
items = [
|
||||
ReturnValueConcept("who", False, None),
|
||||
]
|
||||
res = sheerka.expect_one(get_context(sheerka), items)
|
||||
assert not res.status
|
||||
assert sheerka.isinstance(res.value, BuiltinConcepts.TOO_MANY_ERRORS)
|
||||
assert res.value.obj == items
|
||||
|
||||
|
||||
def test_i_can_use_expect_when_only_errors_2():
|
||||
sheerka = get_sheerka()
|
||||
|
||||
items = [
|
||||
ReturnValueConcept("who", False, None),
|
||||
ReturnValueConcept("who", False, None),
|
||||
]
|
||||
res = sheerka.expect_one(get_context(sheerka), items)
|
||||
assert not res.status
|
||||
assert sheerka.isinstance(res.value, BuiltinConcepts.TOO_MANY_ERRORS)
|
||||
assert res.value.obj == items
|
||||
|
||||
|
||||
def test_i_can_use_expect_one_when_one_success_1():
|
||||
sheerka = get_sheerka()
|
||||
|
||||
items = [
|
||||
ReturnValueConcept("who", True, None),
|
||||
]
|
||||
res = sheerka.expect_one(get_context(sheerka), items)
|
||||
assert res.status
|
||||
assert res == items[0]
|
||||
|
||||
|
||||
def test_i_can_use_expect_one_when_one_success_2():
|
||||
sheerka = get_sheerka()
|
||||
|
||||
items = [
|
||||
ReturnValueConcept("who", False, None),
|
||||
ReturnValueConcept("who", True, None),
|
||||
ReturnValueConcept("who", False, None),
|
||||
]
|
||||
res = sheerka.expect_one(get_context(sheerka), items)
|
||||
assert res.status
|
||||
assert res == items[1]
|
||||
|
||||
|
||||
def test_i_can_use_expect_one_when_not_a_list_true():
|
||||
sheerka = get_sheerka()
|
||||
|
||||
res = sheerka.expect_one(get_context(sheerka), ReturnValueConcept("who", True, None))
|
||||
assert res.status
|
||||
assert res == ReturnValueConcept("who", True, None)
|
||||
|
||||
|
||||
def test_i_can_use_expect_one_when_not_a_list_false():
|
||||
sheerka = get_sheerka()
|
||||
|
||||
res = sheerka.expect_one(get_context(sheerka), ReturnValueConcept("who", False, None))
|
||||
|
||||
assert not res.status
|
||||
assert sheerka.isinstance(res.value, BuiltinConcepts.TOO_MANY_ERRORS)
|
||||
assert res.value.obj == [ReturnValueConcept("who", False, None)]
|
||||
|
||||
# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
#
|
||||
# E V A L U A T I O N S
|
||||
#
|
||||
# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
|
||||
@pytest.mark.parametrize("text, expected", [
|
||||
("1 + 1", 2),
|
||||
|
||||
Reference in New Issue
Block a user