Skip to content

Commit

Permalink
add predicate to EventCatcher test util (#10482)
Browse files Browse the repository at this point in the history
  • Loading branch information
MichelleArk authored Jul 23, 2024
1 parent 560d151 commit cd90d44
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions tests/utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from dataclasses import dataclass, field
from typing import List
from typing import Callable, List

from dbt_common.events.base_types import BaseEvent, EventMsg

Expand All @@ -8,9 +8,10 @@
class EventCatcher:
event_to_catch: BaseEvent
caught_events: List[EventMsg] = field(default_factory=list)
predicate: Callable[[EventMsg], bool] = lambda event: True

def catch(self, event: EventMsg):
if event.info.name == self.event_to_catch.__name__:
if event.info.name == self.event_to_catch.__name__ and self.predicate(event):
self.caught_events.append(event)

def flush(self) -> None:
Expand Down

0 comments on commit cd90d44

Please sign in to comment.