Skip to content

Commit

Permalink
Merge pull request #46 from mkanoor/partial_retract_fact
Browse files Browse the repository at this point in the history
Added support for complete match on retract fact
  • Loading branch information
mkanoor committed May 18, 2023
2 parents b4504cb + e9e3ef6 commit 0331ebf
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "drools_jpy"
version = "0.3.1"
version = "0.3.2"
authors = [
{ name="Madhu Kanoor", email="author@example.com" },
]
Expand Down
Binary file not shown.
27 changes: 27 additions & 0 deletions tests/test_ruleset.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,33 @@ def test_retract_matching_facts():
assert len(response) == 0


def test_retract_matching_facts_complete():
test_data = load_ast("asts/retract_matching_facts.yml")

my_callback1 = mock.Mock()
my_callback2 = mock.Mock()
result = Matches(data={"m": {"meta": {"uuid": "934"}, "i": 67, "n": 239}})

ruleset_data = test_data[0]["RuleSet"]
rs = Ruleset(
name=ruleset_data["name"], serialized_ruleset=json.dumps(ruleset_data)
)
rs.add_rule(Rule("r1", my_callback1))
rs.add_rule(Rule("r2", my_callback2))

rs.assert_fact(json.dumps(dict(i=67, n=239, meta=dict(uuid="934"))))
rs.assert_fact(json.dumps(dict(j=42)))
assert not my_callback1.called

assert (len(rs.get_facts())) == 1
rs.retract_matching_facts(json.dumps(dict(i=67, n=239)), True, ["meta"])

my_callback2.assert_called_with(result)
response = rs.get_facts()
rs.end_session()
assert len(response) == 0


def test_get_facts():
test_data = load_ast("asts/assert_fact.yml")

Expand Down

0 comments on commit 0331ebf

Please sign in to comment.