def test_chunk_events_by_key(): now = datetime.now(timezone.utc) events = [] e1_data = {"label1": "1a", "label2": "2a"} e2_data = {"label1": "1a", "label2": "2b"} e3_data = {"label1": "1b", "label2": "2b"} e1 = Event(data=e1_data, timestamp=now, duration=timedelta(seconds=1)) e2 = Event(data=e2_data, timestamp=now, duration=timedelta(seconds=1)) e3 = Event(data=e3_data, timestamp=now, duration=timedelta(seconds=1)) events = [e1, e2, e3] result = chunk_events_by_key(events, "label1") print(len(result)) pprint(result) assert len(result) == 2 # Check root label assert result[0].data["label1"] == "1a" assert result[1].data["label1"] == "1b" # Check timestamp assert result[0].timestamp == e1.timestamp assert result[1].timestamp == e3.timestamp # Check duration assert result[0].duration == e1.duration + e2.duration assert result[1].duration == e3.duration # Check subevents assert result[0].data["subevents"][0] == e1 assert result[0].data["subevents"][1] == e2 assert result[1].data["subevents"][0] == e3
def q2_chunk_events_by_key(events: list, key: str) -> List[Event]: return chunk_events_by_key(events, key)
def q2_chunk_events_by_key(events: list, key: str) -> List[Event]: _verify_variable_is_type(events, list) _verify_variable_is_type(key, str) return chunk_events_by_key(events, key)