Skip to content

Commit

Permalink
Move EventCatcher to tests.utils for use in unit and functional t…
Browse files Browse the repository at this point in the history
…ests
  • Loading branch information
QMalcolm committed May 15, 2024
1 parent e08c448 commit bcb2efc
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
2 changes: 1 addition & 1 deletion tests/functional/configs/test_warn_error_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from dbt.events.types import DeprecatedModel
from dbt.tests.util import update_config_file
from dbt_common.events.base_types import EventLevel
from tests.functional.utils import EventCatcher
from tests.utils import EventCatcher

ModelsDictSpec = Dict[str, Union[str, "ModelsDictSpec"]]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
)
from dbt.tests.util import update_config_file
from dbt_common.events.base_types import EventLevel
from tests.functional.utils import EventCatcher
from tests.utils import EventCatcher


class TestSpacesInModelNamesHappyPath:
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/events/test_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from dbt_common.events.base_types import BaseEvent
from dbt_common.events.event_manager_client import get_event_manager
from dbt_common.events.logger import LoggerConfig
from tests.functional.utils import EventCatcher
from tests.utils import EventCatcher


class TestSetupEventLogger:
Expand Down
17 changes: 17 additions & 0 deletions tests/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from dataclasses import dataclass, field
from typing import List

from dbt_common.events.base_types import BaseEvent, EventMsg


@dataclass
class EventCatcher:
event_to_catch: BaseEvent
caught_events: List[EventMsg] = field(default_factory=list)

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

def flush(self) -> None:
self.caught_events = []

0 comments on commit bcb2efc

Please sign in to comment.