Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions tests/test_extraction_rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,29 @@ def test_file_path_extraction(self):
result = rule_based_extract("Edit the file src/main.py to fix the bug")
entity_names = [e.name for e in result.entities]
assert any("main.py" in n for n in entity_names)

def test_rule_based_extract_complete_pipeline(self):
"""Test rule_based_extract with a complete input that tests all extraction parts."""
text = "I prefer Python. Python requires Docker. I built this on 2024-01-01."
result = rule_based_extract(text)

assert isinstance(result, ExtractionResult)

# Test Entities
entity_names = [e.name for e in result.entities]
assert "Python" in entity_names
assert "Docker" in entity_names
Comment on lines +84 to +86

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The current entity assertions only verify the presence of names but do not check the entity_type or ensure that no unexpected entities were extracted. For a robust integration test, it is better to verify the exact count and the attributes of the extracted entities.

Suggested change
entity_names = [e.name for e in result.entities]
assert "Python" in entity_names
assert "Docker" in entity_names
assert len(result.entities) == 2
entities_by_name = {e.name: e for e in result.entities}
assert entities_by_name["Python"].entity_type == "tech"
assert entities_by_name["Docker"].entity_type == "tech"
References
  1. Every contribution must meet SOTA+ standards of precision, quality, and logic. All code must be production-ready and robust. (link)


# Test Relations
assert len(result.relations) == 2

pref_relation = next(r for r in result.relations if r.predicate == "prefers")
assert pref_relation.subject == "user"
assert pref_relation.object == "Python"

dep_relation = next(r for r in result.relations if r.predicate == "depends_on")
assert dep_relation.subject == "Python"
assert dep_relation.object == "Docker"
Comment on lines +89 to +97

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Using next() on a generator in a test can lead to a StopIteration error if no match is found, which provides a less helpful error message than a standard pytest assertion failure. Furthermore, the assertion len(result.relations) == 2 confirms that the "built" relation is missing; this is because CREATION_PATTERNS are defined in muninn/extraction/rules.py but are not currently utilized in the extract_relations_rule_based function. Consider using more robust assertions that verify both the count and the specific attributes of each relation.

Suggested change
assert len(result.relations) == 2
pref_relation = next(r for r in result.relations if r.predicate == "prefers")
assert pref_relation.subject == "user"
assert pref_relation.object == "Python"
dep_relation = next(r for r in result.relations if r.predicate == "depends_on")
assert dep_relation.subject == "Python"
assert dep_relation.object == "Docker"
# Note: Currently only 2 relations are extracted because CREATION_PATTERNS are ignored in rules.py
assert len(result.relations) == 2
prefers = [r for r in result.relations if r.predicate == "prefers"]
assert len(prefers) == 1
assert prefers[0].subject == "user"
assert prefers[0].object == "Python"
depends = [r for r in result.relations if r.predicate == "depends_on"]
assert len(depends) == 1
assert depends[0].subject == "Python"
assert depends[0].object == "Docker"
References
  1. Every contribution must meet SOTA+ standards of precision, quality, and logic. All code must be production-ready and robust. (link)


# Test Temporal Context
assert result.temporal_context == "2024-01-01"
Loading