コード例 #1
0
def test_default_construction():
    """LogicEngine is not default constructible."""
    with pytest.raises(TypeError):
        #pylint: disable=no-value-for-parameter
        engine = LogicEngine()
コード例 #2
0
def test_configuration_with_numy_facts():
    facts = {"f1": "vals.sum() > blob.available"}
    rules = {"r1": {"expression": "f1", "actions": ["launch"]}}
    le = LogicEngine({"rules": rules, "facts": facts})
    assert le.produces() == ["actions", "newfacts"]
    assert set(le.consumes()) == set(["vals", "blob"])
コード例 #3
0
def test_trivial_configuration():
    """Logic engine constructed with trivial rules and facts."""
    cfg = {"rules": {}, "facts": {}}
    le = LogicEngine(cfg)
    assert le.produces() == ["actions", "newfacts"]
    assert le.consumes() == []
コード例 #4
0
def test_configuration_with_fact_using_function():
    facts = {"f1": "len(vals) == 10"}
    rules = {"r1": {"expression": "f1", "actions": ["launch"]}}
    le = LogicEngine({"rules": rules, "facts": facts})
    assert le.produces() == ["actions", "newfacts"]
    assert le.consumes() == ["vals"]
コード例 #5
0
def test_wrong_configuration():
    """LogicEngine construction requires rules and facts;
    if we don't supply them it is an error."""
    with pytest.raises(KeyError):
        engine = LogicEngine({})