예제 #1
0
def test_fact_using_numpy_array():
    fact = NamedFact("f3", "vals.sum() > 40")
    assert fact.name == "f3"
    #fact = NamedFact("f3", "np.sum(vals) > 40")
    assert fact.evaluate(make_db(3)) is False
    assert fact.evaluate(make_db(10)) is True
    assert fact.required_names() == ["vals"]
예제 #2
0
def test_simple_fact():
    fact = NamedFact("f1", "z < 100")
    assert fact.name == "f1"
    assert fact.evaluate({"z": 50}) is True
    assert fact.evaluate({"z": 100}) is False
    assert fact.evaluate({"z": 200}) is False
    #assert set(fact.required_names()) is set(["z"])
    assert fact.required_names() == ["z"]
예제 #3
0
    def __init__(self, cfg):
        super().__init__(cfg)
        self.logger = logging.getLogger()
        self.facts = [NamedFact(name, expr) for name, expr in cfg["facts"].items()]

        # Only the names of facts are really needed. We pass in the
        # JSON form of the whole facts dictionary until the C++ is
        # updated to take a list of strings.
        self.re = RuleEngine(cfg["facts"], cfg["rules"])
예제 #4
0
def test_compound_fact():
    fact = NamedFact("f2", "z < 100 and a == 4")
    assert fact.name == "f2"
    assert fact.evaluate({"z": 50, "a": 4}) is True
    assert fact.evaluate({"z": 100, "a": 4}) is False
    assert fact.evaluate({"z": 200, "a": 4}) is False
    assert fact.evaluate({"z": 200, "a": 5}) is False
    assert fact.evaluate({"z": 100, "a": 5}) is False
    assert fact.evaluate({"z": 50, "a": 5}) is False
    assert set(fact.required_names()) == set(["z", "a"])
예제 #5
0
    def __init__(self, cfg):
        super(FakeCondorLE, self).__init__(cfg)
        self.facts = [
            NamedFact(name, expr) for name, expr in cfg["facts"].iteritems()
        ]

        # Only the names of facts are really needed. We pass in the
        # JSON form of the whole facts dictionary until the C++ is
        # updated to take a list of strings.

        self.re = RuleEngine(json.dumps(cfg["facts"]),
                             json.dumps(cfg["rules"]))

        self.log = de_logger.get_logger()
        self.log.debug('>>> __init__ completed with input cfg = %s' % cfg)
예제 #6
0
def test_fact_using_numpy_function():
    fact = NamedFact("f3", "np.sum(vals) > 40")
    assert fact.name == "f3"
    assert set(fact.required_names()) == set(["vals", "np"])
    with pytest.raises(BaseException):
        fact.evaluate(make_db(3))
예제 #7
0
def test_fact_with_nested_names():
    fact = NamedFact("f", "z > 100 and b.c == 10")
    assert fact.name == "f"
    assert set(fact.required_names()) == set(["z", "b"])