def test_categorize(): now = datetime.now(timezone.utc) classes = [ (["Test"], Rule({"regex": "^just"})), (["Test", "Subtest"], Rule({"regex": "subtest$"})), (["Test", "Ignorecase"], Rule({ "regex": "ignorecase", "ignore_case": True })), ] events = [ Event(timestamp=now, duration=0, data={"key": "just a test"}), Event(timestamp=now, duration=0, data={"key": "just a subtest"}), Event(timestamp=now, duration=0, data={"key": "just a IGNORECASE test"}), Event(timestamp=now, duration=0, data={}), ] events = categorize(events, classes) assert events[0].data["$category"] == ["Test"] assert events[1].data["$category"] == ["Test", "Subtest"] assert events[2].data["$category"] == ["Test", "Ignorecase"] assert events[3].data["$category"] == ["Uncategorized"]
def q2_categorize(events: list, classes: list): classes = [(_cls, Rule(rule_dict)) for _cls, rule_dict in classes] return categorize(events, classes)