Skip to content

Commit

Permalink
Add test to check exception handling of msg_to_dict
Browse files Browse the repository at this point in the history
  • Loading branch information
QMalcolm committed Apr 3, 2023
1 parent a40aba2 commit cd362c8
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions tests/unit/test_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
import pytest

import dbt.flags as flags
from dbt.events.functions import warn_or_error
from dbt.events.types import NoNodesForSelectionCriteria
from dbt.events.functions import msg_to_dict, warn_or_error
from dbt.events.types import InfoLevel, NoNodesForSelectionCriteria
from dbt.exceptions import EventCompilationError


Expand Down Expand Up @@ -43,3 +43,19 @@ def test_warn_or_error_warn_error(warn_error, expect_compilation_exception):
warn_or_error(NoNodesForSelectionCriteria())
else:
warn_or_error(NoNodesForSelectionCriteria())


def test_msg_to_dict_handles_exceptions_gracefully():
class BadEvent(InfoLevel):
"""A spoof Note event which breaks dictification"""

def __init__(self):
self.__class__.__name__ = "Note"

event = BadEvent()
try:
msg_to_dict(event)
except Exception as exc:
assert (
False
), f"We expect `msg_to_dict` to gracefully handle exceptions, but it raised {exc}"

0 comments on commit cd362c8

Please sign in to comment.